/* 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
   }
 }
  public void testTest_trasitive() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);
    Object group1Item3 = new TestObject(1, 3);

    equivalenceMock.expectEquivalent(group1Item1, group1Item2);
    equivalenceMock.expectEquivalent(group1Item1, group1Item3);
    equivalenceMock.expectEquivalent(group1Item2, group1Item1);
    equivalenceMock.expectDistinct(group1Item2, group1Item3);
    equivalenceMock.expectEquivalent(group1Item3, group1Item1);
    equivalenceMock.expectEquivalent(group1Item3, group1Item2);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group1Item2, 1);
    equivalenceMock.expectHash(group1Item3, 1);

    equivalenceMock.replay();

    try {
      tester.addEquivalenceGroup(group1Item1, group1Item2, group1Item3).test();
    } catch (AssertionFailedError expected) {
      assertThat(expected.getMessage())
          .contains(
              "TestObject{group=1, item=2} [group 1, item 2] must be equivalent to "
                  + "TestObject{group=1, item=3} [group 1, item 3]");
      return;
    }
    fail();
  }
  public void testTest_hash() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);

    equivalenceMock.expectEquivalent(group1Item1, group1Item2);
    equivalenceMock.expectEquivalent(group1Item2, group1Item1);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group1Item2, 2);

    equivalenceMock.replay();

    try {
      tester.addEquivalenceGroup(group1Item1, group1Item2).test();
    } catch (AssertionFailedError expected) {
      String expectedMessage =
          "the hash (1) of TestObject{group=1, item=1} [group 1, item 1] must be "
              + "equal to the hash (2) of TestObject{group=1, item=2} [group 1, item 2]";
      if (!expected.getMessage().contains(expectedMessage)) {
        fail("<" + expected.getMessage() + "> expected to contain <" + expectedMessage + ">");
      }
      return;
    }
    fail();
  }
  public void testFailure() {
    selenium.setContext(
        "A real negative test, using the real Selenium on the browser side served by Jetty, driven from Java",
        SeleniumLogLevels.DEBUG);
    selenium.open("/selenium-server/tests/html/test_click_page1.html");
    String badElementName = "This element doesn't exist, so Selenium should throw an exception";
    try {
      selenium.getText(badElementName);
      fail("No exception was thrown!");
    } catch (SeleniumException se) {
      assertTrue(
          "Exception message isn't as expected: " + se.getMessage(),
          se.getMessage().indexOf(badElementName + " not found") != -1);
    }

    try {
      assertTrue(
          "Negative test", selenium.isTextPresent("Negative test: verify non-existent text"));
      fail("No exception was thrown!");
    } catch (AssertionFailedError se) {
      assertTrue(
          "Exception message isn't as expected: " + se.getMessage(),
          se.getMessage().indexOf("Negative test") != -1);
    }
  }
Exemple #5
0
  public void testExceptionContainsFileNameUnmarshalResourceWithBadResource()
      throws MarshalException, ValidationException, FileNotFoundException, IOException {
    /*
     * We are going to attempt to unmarshal groups.xml with the wrong
     * class so we get a MarshalException and we can then test to see if the
     * file name is embedded in the exception.
     */
    boolean gotException = false;
    File file = ConfigurationTestUtils.getFileForConfigFile("groups.xml");
    try {
      CastorUtils.unmarshal(Userinfo.class, new FileSystemResource(file));
    } catch (MarshalException e) {
      String matchString = file.getAbsolutePath().replace('\\', '/');
      if (e.toString().contains(matchString)) {
        gotException = true;
      } else {
        AssertionFailedError ae =
            new AssertionFailedError(
                "Got an exception, but not one containing the message we were expecting ('"
                    + matchString
                    + "'): "
                    + e);
        ae.initCause(e);
        throw ae;
      }
    }

    if (!gotException) {
      fail("Did not get a MarshalException, but we were expecting one.");
    }
  }
  public void testLoadFile() {
    try {
      String datadir =
          System.getProperty("planworks.test.data.dir")
              .concat(System.getProperty("file.separator"))
              .concat("loadTest")
              .concat(System.getProperty("file.separator"));
      checkConstraintLoad(datadir);
      checkConstraintVarMapLoad(datadir);
      checkObjectLoad(datadir);
      checkPartialPlanLoad(datadir);
      checkProjectLoad(datadir);
      checkSequenceLoad(datadir);
      checkTokenLoad(datadir);
      checkVariableLoad(datadir);
      // checkTransactionLoad(datadir);
      checkPartialPlanStatsLoad(datadir);
      checkResourceInstantsLoad(datadir);
      checkRulesLoad(datadir);
      checkRuleInstanceLoad(datadir);
      checkDecisionLoad(datadir);

      // catch assert errors and Exceptions here, since JUnit seems to not do it
    } catch (AssertionFailedError err) {
      err.printStackTrace();
      System.exit(-1);
    } catch (Exception excp) {
      excp.printStackTrace();
      System.exit(-1);
    }
  }
Exemple #7
0
 static Throwable wrapWithAddendum(Throwable ex, String addendum, boolean after) {
   if (ex instanceof AssertionFailedError) {
     AssertionFailedError ne = new AssertionFailedError(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof AssertionError) { // preferred in JUnit 4
     AssertionError ne = new AssertionError(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof IOException) { // #66208
     IOException ne = new IOException(combineMessages(ex, addendum, after));
     if (ex.getCause() != null) {
       ne.initCause(ex.getCause());
     }
     ne.setStackTrace(ex.getStackTrace());
     return ne;
   }
   if (ex instanceof Exception) {
     return new InvocationTargetException(ex, combineMessages(ex, addendum, after));
   }
   return ex;
 }
  public void testThrowsAssertionFailedErrorIfTriesToThrowIncompatibleCheckedException()
      throws Throwable {
    Class[] expectedExceptionTypes = {ExpectedExceptionType1.class, ExpectedExceptionType2.class};
    Invocation incompatibleInvocation =
        new Invocation(
            "INVOKED-OBJECT",
            methodFactory.newMethod(
                "methodName", MethodFactory.NO_ARGUMENTS, void.class, expectedExceptionTypes),
            null);

    try {
      throwStub.invoke(incompatibleInvocation);
    } catch (AssertionFailedError ex) {
      String message = ex.getMessage();

      for (int i = 0; i < expectedExceptionTypes.length; i++) {
        AssertMo.assertIncludes(
            "should include name of expected exception types",
            expectedExceptionTypes[i].getName(),
            message);
      }
      AssertMo.assertIncludes(
          "should include name of thrown exception type", THROWABLE.getClass().getName(), message);
      return;
    }
    fail("should have failed");
  }
 protected final <A extends Annotation> void assertAnnotation(
     PropertyInfo<?, ?> property,
     Class<A> annotationClass,
     Map<String, Object> expectedAnnotation) {
   A ann1 = property.getAnnotation(annotationClass);
   assertNotNull(ann1);
   Map<String, Object> values = new HashMap<String, Object>();
   for (Method m : ann1.getClass().getDeclaredMethods()) {
     if (m.getName().equals("equals")
         && m.getParameterTypes().length == 1
         && m.getParameterTypes()[0] == Object.class) {
       continue;
     }
     if (m.getName().equals("hashCode") && m.getParameterTypes().length == 0) {
       continue;
     }
     if (m.getName().equals("toString") && m.getParameterTypes().length == 0) {
       continue;
     }
     if (m.getName().equals("annotationType") && m.getParameterTypes().length == 0) {
       continue;
     }
     try {
       Object value = m.invoke(ann1);
       values.put(m.getName(), value);
     } catch (Exception e) {
       AssertionFailedError afe =
           new AssertionFailedError("Could not invoke annotation value " + m);
       afe.initCause(e);
       throw afe;
     }
   }
   assertEquals(expectedAnnotation, values);
 }
  private void _transition_exprAction__grid_transitions0_actions1(final GridImpl<String> it) {
    try {

      this.gridImpl.setElement(0, 1, "0, 1");
    } catch (junit.framework.AssertionFailedError error) {
      fail("gridImpl.setElement(0, 1, \"0, 1\") failed: " + error.getMessage());
    }
  }
Exemple #11
0
 public void testPathsCanRevealNamingAmbiguitiesWhenUsingSubstrings() throws Exception {
   try {
     tree.select("child/child1_1");
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("Naming ambiguity: there are several 'child' under 'root'", e.getMessage());
   }
 }
Exemple #12
0
 public void testSelectChildrenWithNoMatch() throws Exception {
   try {
     tree.select("", "UNKNOWN");
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("No children found", e.getMessage());
   }
 }
Exemple #13
0
 public void testSelectMultiplePathsWithInvalidPath() throws Exception {
   try {
     tree.select(new String[] {"child1", "unknown"});
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals(Tree.badTreePath("unknown"), e.getMessage());
   }
 }
  private void _transition_exprAction__gridIteratorColumnMajor_transitions0_actions5(
      final GridImpl<String> it, final GridIterator<String> gridIterator) {
    try {

      this.gridImpl.setElement(1, 2, "1, 2");
    } catch (junit.framework.AssertionFailedError error) {
      fail("gridImpl.setElement(1, 2, \"1, 2\") failed: " + error.getMessage());
    }
  }
Exemple #15
0
 public void testPathsCanRevealNamingAmbiguitiesWhenUsingExactNames() throws Exception {
   rootNode.add(new DefaultMutableTreeNode(child1));
   try {
     tree.select("child1/child1_1");
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("Naming ambiguity: there are several 'child1' under 'root'", e.getMessage());
   }
 }
 public void testInsertTextAtABadPosition() throws Exception {
   textBox.setText("text");
   try {
     textBox.insertText("a", 10);
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("Position should be between 0 and 4", e.getMessage());
   }
 }
  public void verify() {
    forgetFailure();

    try {
      invocationDispatcher.verify();
    } catch (AssertionFailedError ex) {
      throw new AssertionFailedError("mock object " + name + ": " + ex.getMessage());
    }
  }
 /** Sleeps until the given time has elapsed. Throws AssertionFailedError if interrupted. */
 void sleep(long millis) {
   try {
     delay(millis);
   } catch (InterruptedException ie) {
     AssertionFailedError afe = new AssertionFailedError("Unexpected InterruptedException");
     afe.initCause(ie);
     throw afe;
   }
 }
Exemple #19
0
 public void testCheckSelectionWithBadPath() throws Exception {
   tree.select("child1/child1_1");
   String pathToCheck = "child1/toto";
   try {
     assertTrue(tree.selectionEquals(pathToCheck));
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals(Tree.badTreePath("child1/toto"), e.getMessage());
   }
 }
 protected void enableAutoCommit() {
   try {
     netConn.setAutoCommit(false);
   } catch (SQLException se) {
     junit.framework.AssertionFailedError ase =
         new junit.framework.AssertionFailedError(se.getMessage());
     ase.initCause(se);
     throw ase;
   }
 }
 public void testAssertEmptyWithPlainText() throws Exception {
   jTextComponent.setText("");
   assertTrue(textBox.textIsEmpty());
   jTextComponent.setText("a");
   try {
     assertTrue(textBox.textIsEmpty());
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("Text should be empty but contains: a", e.getMessage());
   }
 }
Exemple #22
0
 public void testSelectNonexistingPath() throws Exception {
   assertNull(jTree.getSelectionRows());
   String path = "child1/unexistingElement";
   try {
     tree.select(path);
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals(Tree.badTreePath("child1/unexistingElement"), e.getMessage());
   }
   assertNull(jTree.getSelectionRows());
 }
 public void testInsertTextChecksThatTheComponentIsEditable() throws Exception {
   textBox.setText("text");
   jTextComponent.setEditable(false);
   try {
     textBox.insertText("new text", 0);
     throw new AssertionFailureNotDetectedError();
   } catch (AssertionFailedError e) {
     assertEquals("The text box is not editable", e.getMessage());
   }
   assertEquals("text", jTextComponent.getText());
 }
Exemple #24
0
 public void testAppendsInfoToFailureMessage() throws Exception {
   try {
     conditionRunner.waitFor("this condition should always fail", new AlwaysFalseCondition());
     fail("the condition should have failed");
   } catch (AssertionFailedError expected) {
     assertEquals(
         "Condition \"Sky should be blue\" failed to become true within 100 msec; "
             + "this condition should always fail; [sky is in fact pink]",
         expected.getMessage());
   }
 }
 /**
  * Records the given exception using {@link #threadRecordFailure}, then rethrows the exception,
  * wrapping it in an AssertionFailedError if necessary.
  */
 public void threadUnexpectedException(Throwable t) {
   threadRecordFailure(t);
   t.printStackTrace();
   if (t instanceof RuntimeException) throw (RuntimeException) t;
   else if (t instanceof Error) throw (Error) t;
   else {
     AssertionFailedError afe = new AssertionFailedError("unexpected exception: " + t);
     afe.initCause(t);
     throw afe;
   }
 }
 public int await() {
   try {
     return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
   } catch (TimeoutException e) {
     throw new AssertionFailedError("timed out");
   } catch (Exception e) {
     AssertionFailedError afe = new AssertionFailedError("Unexpected exception: " + e);
     afe.initCause(e);
     throw afe;
   }
 }
  public void test_assertReceivedMessage_withMultipleSender() throws Exception {
    sendMail("darth.Vader", new String[] {"luke", "chewbacca"}, "n/a", "n/a");

    mailFixture.getReceivedMessage(0).assertThat().to("luke", "chewbacca");

    try {
      mailFixture.getReceivedMessage(0).assertThat().to("mika");
      fail("should fail");
    } catch (AssertionFailedError error) {
      assertEquals("Assert To - The value 'mika' is not in [luke, chewbacca]", error.getMessage());
    }
  }
  public void test_assertReceivedMessagesCount() throws Exception {
    sendMail("darth.Vader", "luke.Skywalker", "scoop", "Je suis ton pere");

    mailFixture.assertReceivedMessagesCount(1);

    try {
      mailFixture.assertReceivedMessagesCount(2);
      fail("should fail");
    } catch (AssertionFailedError error) {
      assertEquals("Received message count expected:<2> but was:<1>", error.getMessage());
    }
  }
 public void testReportsUsefulErrorMessageWhenTryingToMockNonStaticInnerClass() {
   try {
     mock(NonStaticInnerClass.class);
   } catch (AssertionFailedError e) {
     assertTrue("should report error", e.getMessage().indexOf("non-static inner class") >= 0);
     assertTrue(
         "should report name of inner class",
         e.getMessage().indexOf(NonStaticInnerClass.class.getName()) >= 0);
     return;
   }
   fail("should have failed");
 }
 /**
  * Test method for {@link
  * org.jboss.jsfunit.analysis.ApplicationFactoryTestCase#testClassLoadable()}.
  */
 public void testTestClassLoadable() {
   ApplicationFactoryTestCase testcase =
       new ApplicationFactoryTestCase("testTestClassLoadable", "com.nonexist.Foo");
   try {
     testcase.testClassLoadable();
     fail("should have failed");
   } catch (AssertionFailedError afe) {
     assertEquals(
         "Could not load class 'com.nonexist.Foo' for element 'Application Factory'",
         afe.getMessage());
   }
 }