// This file was generated by jmlunit on Mon Mar 16 13:16:51 EDT 2009. package org.jmlspecs.samples.jmlkluwer; import java.util.ArrayList; import java.util.Iterator; /** Automatically-generated test driver for JML and JUnit based * testing of PriorityQueue. The superclass of this class should be edited * to supply test data. However it's best not to edit this class * directly; instead use the command *
* jmlunit PriorityQueue.java ** to regenerate this class whenever PriorityQueue.java changes. */ public class PriorityQueue_JML_Test extends PriorityQueue_JML_TestData { /** Initialize this class. */ public PriorityQueue_JML_Test(java.lang.String name) { super(name); } /** Run the tests. */ public static void main(java.lang.String[] args) { org.jmlspecs.jmlunit.JMLTestRunner.run(suite()); // You can also use a JUnit test runner such as: // junit.textui.TestRunner.run(suite()); } /** Test to see if the code for class PriorityQueue * has been compiled with runtime assertion checking (i.e., by jmlc). * Code that is not compiled with jmlc would not make an effective test, * since no assertion checking would be done. */ public void test$IsRACCompiled() { junit.framework.Assert.assertTrue("code for class PriorityQueue" + " was not compiled with jmlc" + " so no assertions will be checked!", org.jmlspecs.jmlrac.runtime.JMLChecker.isRACCompiled(PriorityQueue.class) ); } /** Return the test suite for this test class. This will have * added to it at least test$IsRACCompiled(), and any test methods * written explicitly by the user in the superclass. It will also * have added test suites for each testing each method and * constructor. */ //@ ensures \result != null; public static junit.framework.Test suite() { PriorityQueue_JML_Test testobj = new PriorityQueue_JML_Test("PriorityQueue_JML_Test"); junit.framework.TestSuite testsuite = testobj.overallTestSuite(); // Add instances of Test found by the reflection mechanism. testsuite.addTestSuite(PriorityQueue_JML_Test.class); testobj.addTestSuiteForEachMethod(testsuite); return testsuite; } /** A JUnit test object that can run a single test method. This * is defined as a nested class solely for convenience; it can't * be defined once and for all because it must subclass its * enclosing class. */ protected static abstract class OneTest extends PriorityQueue_JML_Test { /** Initialize this test object. */ public OneTest(String name) { super(name); } /** The result object that holds information about testing. */ protected junit.framework.TestResult result; //@ also //@ requires result != null; public void run(junit.framework.TestResult result) { this.result = result; super.run(result); } /* Run a single test and decide whether the test was * successful, meaningless, or a failure. This is the * Template Method pattern abstraction of the inner loop in a * JML/JUnit test. */ public void runTest() throws java.lang.Throwable { try { // The call being tested! doCall(); } catch (org.jmlspecs.jmlrac.runtime.JMLEntryPreconditionError e) { // meaningless test input addMeaningless(); } catch (org.jmlspecs.jmlrac.runtime.JMLAssertionError e) { // test failure int l = org.jmlspecs.jmlrac.runtime.JMLChecker.getLevel(); org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel (org.jmlspecs.jmlrac.runtime.JMLOption.NONE); try { java.lang.String failmsg = this.failMessage(e); junit.framework.AssertionFailedError err = new junit.framework.AssertionFailedError(failmsg); err.setStackTrace(new java.lang.StackTraceElement[]{}); err.initCause(e); result.addFailure(this, err); } finally { org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(l); } } catch (java.lang.Throwable e) { // test success } } /** Call the method to be tested with the appropriate arguments. */ protected abstract void doCall() throws java.lang.Throwable; /** Format the error message for a test failure, based on the * method's arguments. */ protected abstract java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e); /** Inform listeners that a meaningless test was run. */ private void addMeaningless() { if (result instanceof org.jmlspecs.jmlunit.JMLTestResult) { ((org.jmlspecs.jmlunit.JMLTestResult)result) .addMeaningless(this); } } } /** Create the tests that are to be run for testing the class * PriorityQueue. The framework will then run them. * @param overallTestSuite$ The suite accumulating all of the tests * for this driver class. */ //@ requires overallTestSuite$ != null; public void addTestSuiteForEachMethod (junit.framework.TestSuite overallTestSuite$) { try { this.addTestSuiteFor$TestPriorityQueue(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestAddEntry(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestContains(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestNext(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestRemove(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestIsEmpty(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } try { this.addTestSuiteFor$TestToString(overallTestSuite$); } catch (java.lang.Throwable ex) { overallTestSuite$.addTest (new org.jmlspecs.jmlunit.strategies.ConstructorFailed(ex)); } } /** Add tests for the PriorityQueue contructor * to the overall test suite. */ private void addTestSuiteFor$TestPriorityQueue (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("PriorityQueue"); try { methodTests$.addTest (new TestPriorityQueue()); } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the PriorityQueue contructor. */ protected static class TestPriorityQueue extends OneTest { /** Initialize this instance. */ public TestPriorityQueue() { super("PriorityQueue"); } protected void doCall() throws java.lang.Throwable { new PriorityQueue(); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tContructor 'PriorityQueue'"; return msg; } } /** Add tests for the addEntry method * to the overall test suite. */ private void addTestSuiteFor$TestAddEntry (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("addEntry"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("addEntry", 2)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"addEntry\", 2))"); while (!receivers$iter.atEnd()) { org.jmlspecs.jmlunit.strategies.IndefiniteIterator vjava_lang_Object$1$iter = this.vjava_lang_ObjectIter("addEntry", 1); this.check_has_data (vjava_lang_Object$1$iter, "this.vjava_lang_ObjectIter(\"addEntry\", 1)"); while (!vjava_lang_Object$1$iter.atEnd()) { org.jmlspecs.jmlunit.strategies.IntIterator vint$2$iter = this.vintIter("addEntry", 0); this.check_has_data (vint$2$iter, "this.vintIter(\"addEntry\", 0)"); while (!vint$2$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); final java.lang.Object argObj = (java.lang.Object) vjava_lang_Object$1$iter.get(); final int argPriorityLevel = vint$2$iter.getInt(); methodTests$.addTest (new TestAddEntry(receiver$, argObj, argPriorityLevel)); vint$2$iter.advance(); } vjava_lang_Object$1$iter.advance(); } receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the addEntry method. */ protected static class TestAddEntry extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Argument argObj */ private java.lang.Object argObj; /** Argument argPriorityLevel */ private int argPriorityLevel; /** Initialize this instance. */ public TestAddEntry(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$, java.lang.Object argObj, int argPriorityLevel) { super("addEntry"+ ":" + (argObj==null? "null" :"{java.lang.Object}")+ "," +argPriorityLevel); this.receiver$ = receiver$; this.argObj = argObj; this.argPriorityLevel = argPriorityLevel; } protected void doCall() throws java.lang.Throwable { receiver$.addEntry(argObj, argPriorityLevel); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'addEntry' applied to"; msg += "\n\tReceiver: " + this.receiver$; msg += "\n\tArgument argObj: " + this.argObj; msg += "\n\tArgument argPriorityLevel: " + this.argPriorityLevel; return msg; } } /** Add tests for the contains method * to the overall test suite. */ private void addTestSuiteFor$TestContains (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("contains"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("contains", 1)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"contains\", 1))"); while (!receivers$iter.atEnd()) { org.jmlspecs.jmlunit.strategies.IndefiniteIterator vjava_lang_Object$1$iter = this.vjava_lang_ObjectIter("contains", 0); this.check_has_data (vjava_lang_Object$1$iter, "this.vjava_lang_ObjectIter(\"contains\", 0)"); while (!vjava_lang_Object$1$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); final java.lang.Object argObj = (java.lang.Object) vjava_lang_Object$1$iter.get(); methodTests$.addTest (new TestContains(receiver$, argObj)); vjava_lang_Object$1$iter.advance(); } receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the contains method. */ protected static class TestContains extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Argument argObj */ private java.lang.Object argObj; /** Initialize this instance. */ public TestContains(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$, java.lang.Object argObj) { super("contains"+ ":" + (argObj==null? "null" :"{java.lang.Object}")); this.receiver$ = receiver$; this.argObj = argObj; } protected void doCall() throws java.lang.Throwable { receiver$.contains(argObj); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'contains' applied to"; msg += "\n\tReceiver: " + this.receiver$; msg += "\n\tArgument argObj: " + this.argObj; return msg; } } /** Add tests for the next method * to the overall test suite. */ private void addTestSuiteFor$TestNext (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("next"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("next", 0)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"next\", 0))"); while (!receivers$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); methodTests$.addTest (new TestNext(receiver$)); receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the next method. */ protected static class TestNext extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Initialize this instance. */ public TestNext(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$) { super("next"); this.receiver$ = receiver$; } protected void doCall() throws java.lang.Throwable { receiver$.next(); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'next' applied to"; msg += "\n\tReceiver: " + this.receiver$; return msg; } } /** Add tests for the remove method * to the overall test suite. */ private void addTestSuiteFor$TestRemove (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("remove"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("remove", 1)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"remove\", 1))"); while (!receivers$iter.atEnd()) { org.jmlspecs.jmlunit.strategies.IndefiniteIterator vjava_lang_Object$1$iter = this.vjava_lang_ObjectIter("remove", 0); this.check_has_data (vjava_lang_Object$1$iter, "this.vjava_lang_ObjectIter(\"remove\", 0)"); while (!vjava_lang_Object$1$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); final java.lang.Object argObj = (java.lang.Object) vjava_lang_Object$1$iter.get(); methodTests$.addTest (new TestRemove(receiver$, argObj)); vjava_lang_Object$1$iter.advance(); } receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the remove method. */ protected static class TestRemove extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Argument argObj */ private java.lang.Object argObj; /** Initialize this instance. */ public TestRemove(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$, java.lang.Object argObj) { super("remove"+ ":" + (argObj==null? "null" :"{java.lang.Object}")); this.receiver$ = receiver$; this.argObj = argObj; } protected void doCall() throws java.lang.Throwable { receiver$.remove(argObj); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'remove' applied to"; msg += "\n\tReceiver: " + this.receiver$; msg += "\n\tArgument argObj: " + this.argObj; return msg; } } /** Add tests for the isEmpty method * to the overall test suite. */ private void addTestSuiteFor$TestIsEmpty (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("isEmpty"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("isEmpty", 0)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"isEmpty\", 0))"); while (!receivers$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); methodTests$.addTest (new TestIsEmpty(receiver$)); receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the isEmpty method. */ protected static class TestIsEmpty extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Initialize this instance. */ public TestIsEmpty(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$) { super("isEmpty"); this.receiver$ = receiver$; } protected void doCall() throws java.lang.Throwable { receiver$.isEmpty(); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'isEmpty' applied to"; msg += "\n\tReceiver: " + this.receiver$; return msg; } } /** Add tests for the toString method * to the overall test suite. */ private void addTestSuiteFor$TestToString (junit.framework.TestSuite overallTestSuite$) { junit.framework.TestSuite methodTests$ = this.emptyTestSuiteFor("toString"); try { org.jmlspecs.jmlunit.strategies.IndefiniteIterator receivers$iter = new org.jmlspecs.jmlunit.strategies.NonNullIteratorDecorator (this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter("toString", 0)); this.check_has_data (receivers$iter, "new NonNullIteratorDecorator(this.vorg_jmlspecs_samples_jmlkluwer_PriorityQueueIter(\"toString\", 0))"); while (!receivers$iter.atEnd()) { final org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$ = (org.jmlspecs.samples.jmlkluwer.PriorityQueue) receivers$iter.get(); methodTests$.addTest (new TestToString(receiver$)); receivers$iter.advance(); } } catch (org.jmlspecs.jmlunit.strategies.TestSuiteFullException e$) { // methodTests$ doesn't want more tests } overallTestSuite$.addTest(methodTests$); } /** Test for the toString method. */ protected static class TestToString extends OneTest { /** The receiver */ private org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$; /** Initialize this instance. */ public TestToString(org.jmlspecs.samples.jmlkluwer.PriorityQueue receiver$) { super("toString"); this.receiver$ = receiver$; } protected void doCall() throws java.lang.Throwable { receiver$.toString(); } protected java.lang.String failMessage (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) { java.lang.String msg = "\n\tMethod 'toString' applied to"; msg += "\n\tReceiver: " + this.receiver$; return msg; } } /** Check that the iterator is non-null and not empty. */ private void check_has_data(org.jmlspecs.jmlunit.strategies.IndefiniteIterator iter, String call) { if (iter == null) { junit.framework.Assert.fail(call + " returned null"); } if (iter.atEnd()) { junit.framework.Assert.fail(call + " returned an empty iterator"); } } /** Converts a char to a printable String for display */ public static String charToString(char c) { if (c == '\n') { return "NL"; } else if (c == '\r') { return "CR"; } else if (c == '\t') { return "TAB"; } else if (Character.isISOControl(c)) { int i = (int)c; return "\\u" + Character.forDigit((i/2048)%16,16) + Character.forDigit((i/256)%16,16) + Character.forDigit((i/16)%16,16) + Character.forDigit((i)%16,16); } return Character.toString(c); } }