Java Code Examples for junit.framework.AssertionFailedError

The following examples show how to use junit.framework.AssertionFailedError. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: tomee   Source File: EncStatefulBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupBooleanEntry() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            final Boolean expected = Boolean.TRUE;
            final Boolean actual = (Boolean) ctx.lookup("java:comp/env/stateful/references/Boolean");

            Assert.assertNotNull("The Boolean looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 2
Source Project: ghidra   Source File: AbstractDockingTest.java    License: Apache License 2.0 6 votes vote down vote up
public static Window waitForWindow(Class<?> windowClass) {

		if ((!Dialog.class.isAssignableFrom(windowClass)) &&
			(!Frame.class.isAssignableFrom(windowClass))) {
			throw new IllegalArgumentException(
				windowClass.getName() + " does not extend Dialog or Frame.");
		}

		int timeout = DEFAULT_WAIT_TIMEOUT;
		int totalTime = 0;
		while (totalTime <= timeout) {

			Set<Window> winList = getAllWindows();
			Iterator<Window> it = winList.iterator();
			while (it.hasNext()) {
				Window w = it.next();
				if (windowClass.isAssignableFrom(w.getClass()) && w.isVisible()) {
					return w;
				}
			}

			totalTime += sleep(DEFAULT_WAIT_DELAY);
		}

		throw new AssertionFailedError("Timed-out waiting for window of class: " + windowClass);
	}
 
Example 3
Source Project: tomee   Source File: EncBmpBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 4
Source Project: tomee   Source File: ContextLookupMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupBooleanEntry() throws TestFailureException {
    try {
        try {
            final Boolean expected = true;
            final Boolean actual = (Boolean) mdbContext.lookup("stateless/references/Boolean");

            Assert.assertNotNull("The Boolean looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 5
Source Project: tomee   Source File: ContextLookupMdbPojoBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupBooleanEntry() throws TestFailureException {
    try {
        try {
            final Boolean expected = true;
            final Boolean actual = (Boolean) getMessageDrivenContext().lookup("stateless/references/Boolean");

            Assert.assertNotNull("The Boolean looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 6
Source Project: ghidra   Source File: AbstractGTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void waitForCondition(BooleanSupplier condition, boolean failOnTimeout,
		Supplier<String> failureMessageSupplier) throws AssertionFailedError {

	int totalTime = 0;
	while (totalTime <= DEFAULT_WAIT_TIMEOUT) {

		if (condition.getAsBoolean()) {
			return; // success
		}

		totalTime += sleep(DEFAULT_WAIT_DELAY);
	}

	if (!failOnTimeout) {
		return;
	}

	String failureMessage = "Timed-out waiting for condition";
	if (failureMessageSupplier != null) {
		failureMessage = failureMessageSupplier.get();
	}

	throw new AssertionFailedError(failureMessage);
}
 
Example 7
Source Project: astor   Source File: TestUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fails iff values does not contain a number within epsilon of z.
 *
 * @param msg  message to return with failure
 * @param values complex array to search
 * @param z  value sought
 * @param epsilon  tolerance
 */
public static void assertContains(String msg, Complex[] values,
        Complex z, double epsilon) {
    int i = 0;
    boolean found = false;
    while (!found && i < values.length) {
        try {
            assertEquals(values[i], z, epsilon);
            found = true;
        } catch (AssertionFailedError er) {
            // no match
        }
        i++;
    }
    if (!found) {
        Assert.fail(msg +
            " Unable to find " + ComplexFormat.formatComplex(z));
    }
}
 
Example 8
Source Project: ghidra   Source File: AbstractToolSavingTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void closeAndReopenProject() {
	executeOnSwingWithoutBlocking(() -> {
		try {
			// we want to trigger the saving of tools to the toolchest for our tests
			// just closing the project doesn't save anything.
			testEnv.getProject().saveSessionTools();
			testEnv.getProject().save();
			testEnv.closeAndReopenProject();
		}
		catch (IOException e) {
			AssertionFailedError afe = new AssertionFailedError();
			afe.initCause(e);
			throw afe;
		}
	});
	waitForPostedSwingRunnables();
}
 
Example 9
Source Project: openjdk-jdk9   Source File: JSR166TestCase.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
                         Runnable... throwingActions) {
    for (Runnable throwingAction : throwingActions) {
        boolean threw = false;
        try { throwingAction.run(); }
        catch (Throwable t) {
            threw = true;
            if (!expectedExceptionClass.isInstance(t)) {
                AssertionFailedError afe =
                    new AssertionFailedError
                    ("Expected " + expectedExceptionClass.getName() +
                     ", got " + t.getClass().getName());
                afe.initCause(t);
                threadUnexpectedException(afe);
            }
        }
        if (!threw)
            shouldThrow(expectedExceptionClass.getName());
    }
}
 
Example 10
Source Project: tomee   Source File: EncMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupShortEntry() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            final Short expected = (short) 1;
            final Short actual = (Short) ctx.lookup("java:comp/env/stateless/references/Short");

            Assert.assertNotNull("The Short looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 11
Source Project: tomee   Source File: ContextLookupSingletonBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupStringEntry() throws TestFailureException {
    try {
        try {
            final String expected = new String("1");
            final String actual = (String) ejbContext.lookup("singleton/references/String");

            Assert.assertNotNull("The String looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 12
Source Project: tomee   Source File: ContextLookupMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupDoubleEntry() throws TestFailureException {
    try {
        try {
            final Double expected = 1.0D;
            final Double actual = (Double) mdbContext.lookup("stateless/references/Double");

            Assert.assertNotNull("The Double looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 13
Source Project: tomee   Source File: EncMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupPersistenceContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
            Assert.assertNotNull("The EntityManager is null", em);

            // call a do nothing method to assure entity manager actually exists
            em.getFlushMode();
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 14
Source Project: j2objc   Source File: JSR166TestCase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extra checks that get done for all test cases.
 *
 * Triggers test case failure if any thread assertions have failed,
 * by rethrowing, in the test harness thread, any exception recorded
 * earlier by threadRecordFailure.
 *
 * Triggers test case failure if interrupt status is set in the main thread.
 */
public void tearDown() throws Exception {
    Throwable t = threadFailure.getAndSet(null);
    if (t != null) {
        if (t instanceof Error)
            throw (Error) t;
        else if (t instanceof RuntimeException)
            throw (RuntimeException) t;
        else if (t instanceof Exception)
            throw (Exception) t;
        else {
            AssertionFailedError afe =
                new AssertionFailedError(t.toString());
            afe.initCause(t);
            throw afe;
        }
    }

    if (Thread.interrupted())
        tearDownFail("interrupt status set in main thread");

    checkForkJoinPoolThreadLeaks();
}
 
Example 15
Source Project: tomee   Source File: ContextLookupSingletonPojoBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupBooleanEntry() throws TestFailureException {
    try {
        try {
            final Boolean expected = Boolean.TRUE;
            final Boolean actual = (Boolean) getSessionContext().lookup("singleton/references/Boolean");

            Assert.assertNotNull("The Boolean looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 16
Source Project: tomee   Source File: EncMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupMessageDrivenContext() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            // lookup in enc
            final MessageDrivenContext messageDrivenContext = (MessageDrivenContext) ctx.lookup("java:comp/env/mdbcontext");
            Assert.assertNotNull("The SessionContext got from java:comp/env/mdbcontext is null", messageDrivenContext);

            // lookup using global name
            final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
            Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);

            // verify context was set via legacy set method
            Assert.assertNotNull("The MdbContext is null from setter method", mdbContext);
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }

}
 
Example 17
Source Project: tomee   Source File: ContextLookupSingletonPojoBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupFloatEntry() throws TestFailureException {
    try {
        try {
            final Float expected = new Float(1.0F);
            final Float actual = (Float) getSessionContext().lookup("singleton/references/Float");

            Assert.assertNotNull("The Float looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 18
Source Project: tomee   Source File: ContextLookupStatefulPojoBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupLongEntry() throws TestFailureException {
    try {
        try {
            final Long expected = new Long(1L);
            final Long actual = (Long) ejbContext.lookup("stateful/references/Long");

            Assert.assertNotNull("The Long looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 19
@Override
public void testDatesAndTimes() throws IOException, SQLException {
  final int TOTAL_RECORDS = 10;

  ColumnGenerator genDate = getDateColumnGenerator();
  ColumnGenerator genTime = getTimeColumnGenerator();

  try {
    createTextFile(0, TOTAL_RECORDS, false, genDate, genTime);
    createTable(genDate, genTime);
    runExport(getArgv(true, 10, 10));
    verifyExport(TOTAL_RECORDS);
    assertColMinAndMax(forIdx(0), genDate);
    assertColMinAndMax(forIdx(1), genTime);
  } catch (AssertionFailedError afe) {
    genDate = getNewDateColGenerator();
    genTime = getNewTimeColGenerator();

    createTextFile(0, TOTAL_RECORDS, false, genDate, genTime);
    createTable(genDate, genTime);
    runExport(getArgv(true, 10, 10));
    verifyExport(TOTAL_RECORDS);
    assertColMinAndMax(forIdx(0), genDate);
    assertColMinAndMax(forIdx(1), genTime);
  }
}
 
Example 20
Source Project: pipeline-maven-plugin   Source File: XmlUtilsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void test_listGeneratedArtifacts_including_generated_artifacts() throws Exception {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
    in.getClass(); // check non null
    Element mavenSpyLogs = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in).getDocumentElement();
    List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, true);
    System.out.println(generatedArtifacts);
    Assert.assertThat(generatedArtifacts.size(), Matchers.is(3)); // a jar file and a pom file are generated

    for (MavenArtifact mavenArtifact:generatedArtifacts) {
        Assert.assertThat(mavenArtifact.getGroupId(), Matchers.is("com.example"));
        Assert.assertThat(mavenArtifact.getArtifactId(), Matchers.is("my-jar"));
        if("pom".equals(mavenArtifact.getType())) {
            Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("pom"));
            Assert.assertThat(mavenArtifact.getClassifier(), Matchers.isEmptyOrNullString());
        } else if ("jar".equals(mavenArtifact.getType())) {
            Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("jar"));
            Assert.assertThat(mavenArtifact.getClassifier(), Matchers.isEmptyOrNullString());
        } else if ("java-source".equals(mavenArtifact.getType())) {
            Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("jar"));
            Assert.assertThat(mavenArtifact.getClassifier(), Matchers.is("sources"));
        } else {
            throw new AssertionFailedError("Unsupported type for " + mavenArtifact);
        }
    }
}
 
Example 21
Source Project: tomee   Source File: EncMdbBean.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void lookupCharacterEntry() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            final Character expected = 'D';
            final Character actual = (Character) ctx.lookup("java:comp/env/stateless/references/Character");

            Assert.assertNotNull("The Character looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 22
Source Project: tomee   Source File: EncCmpBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupFloatEntry() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            final Float expected = new Float(1.0F);
            final Float actual = (Float) ctx.lookup("java:comp/env/entity/cmp/references/Float");

            Assert.assertNotNull("The Float looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 23
Source Project: tomee   Source File: EncCmpBean.java    License: Apache License 2.0 6 votes vote down vote up
public void lookupByteEntry() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);

            final Byte expected = new Byte((byte) 1);
            final Byte actual = (Byte) ctx.lookup("java:comp/env/entity/cmp/references/Byte");

            Assert.assertNotNull("The Byte looked up is null", actual);
            Assert.assertEquals(expected, actual);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 24
Source Project: swellrt   Source File: DocOpValidatorTest.java    License: Apache License 2.0 5 votes vote down vote up
void doTest(TestData t) throws OperationException {
  DocOpBuffer d = new DocOpBuffer();
  DocOpBuffer m = new DocOpBuffer();
  boolean expected = t.build(d, m);

  BootstrapDocument doc = new BootstrapDocument();

  // initialize document
  doc.consume(d.finishUnchecked());

  // check whether m would apply
  ViolationCollector v = new ViolationCollector();
  ValidationResult result =
      DocOpValidator.validate(v, t.getSchemaConstraints(), doc, m.finishUnchecked());

  try {
    assertEquals(expected, v.isValid());
    assertEquals(result, v.getValidationResult());
  } catch (AssertionFailedError e) {
    System.err.println("test data:");
    System.err.println(DocOpUtil.toConciseString(d.finish()));
    System.err.println(DocOpUtil.toConciseString(m.finish()));
    System.err.println("violations:");
    v.printDescriptions(System.err);
    throw e;
  }
}
 
Example 25
public void testAssertNull() {
	assertNull(null);
	try {
		assertNull(new Object());
	} catch (AssertionFailedError e) {
		return;
	}
	fail();
}
 
Example 26
Source Project: tomee   Source File: EncCmp2Bean.java    License: Apache License 2.0 5 votes vote down vote up
public void lookupPersistenceUnit() throws TestFailureException {
    try {
        try {
            final InitialContext ctx = new InitialContext();
            Assert.assertNotNull("The InitialContext is null", ctx);
            final EntityManagerFactory emf = (EntityManagerFactory) ctx.lookup("java:comp/env/persistence/TestUnit");
            Assert.assertNotNull("The EntityManagerFactory is null", emf);

        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 27
Source Project: tomee   Source File: InterceptorMdbBean.java    License: Apache License 2.0 5 votes vote down vote up
public void checkMethodLevelBusinessMethodInterception() throws TestFailureException {
    try {
        Assert.assertTrue("Method Level Business Method Interception failed for Mdb", methodLevelBusinessMethodInterception);
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 28
Source Project: kubernetes-client   Source File: WatchOverHTTP.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleted() throws InterruptedException {
  logger.info("testDeleted");
  KubernetesClient client = server.getClient().inNamespace("test");

  server.expect()
    .withPath(path)
    .andReturn(200, "Failed WebSocket Connection").once();
  server.expect().withPath(path).andReturnChunked(200,
    new WatchEvent(pod1, "DELETED"), "\n",
    new WatchEvent(pod1, "ADDED"), "\n").once();

  final CountDownLatch addLatch = new CountDownLatch(1);
  final CountDownLatch deleteLatch = new CountDownLatch(1);
  try (Watch watch = client.pods().withName("pod1").withResourceVersion("1").watch(new Watcher<Pod>() {
    @Override
    public void eventReceived(Action action, Pod resource) {
      switch (action) {
        case DELETED:
          deleteLatch.countDown();
          break;
        case ADDED:
          addLatch.countDown();
          break;
        default:
          throw new AssertionFailedError();
      }
    }

    @Override
    public void onClose(KubernetesClientException cause) {}
  })) /* autoclose */ {
    assertTrue(addLatch.await(10, TimeUnit.SECONDS));
    assertTrue(deleteLatch.await(10, TimeUnit.SECONDS));
  }
}
 
Example 29
Source Project: tomee   Source File: FieldInjectionStatefulBean.java    License: Apache License 2.0 5 votes vote down vote up
public void lookupStatelessBusinessLocal() throws TestFailureException {
    try {
        Assert.assertNotNull("The EJB BusinessLocal is null", statelessBusinessLocal);
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
 
Example 30
Source Project: tomee   Source File: SetterInjectionStatefulBean.java    License: Apache License 2.0 5 votes vote down vote up
public void lookupIntegerEntry() throws TestFailureException {
    try {
        final Integer expected = new Integer(1);

        Assert.assertNotNull("The Integer looked up is null", inteegerField);
        Assert.assertEquals(expected, inteegerField);

    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}