For IntelliJ IDEA,
Android Studio or Eclipse



/** * Formats failure for file assertions */ private static void failFile(File path, String actual, String expected, String message) { String formatted = ""; if(message != null) { formatted = message + " "; } fail(formatted + "expected <" + expected +"> but was <" + toString(path) + ">" +(expected!=null?"<" + expected +">":"")); }
/** * @param tstvalue * @param string * @param string2 * @param message */ private static void failSecurity(Exception e, File path, String actual, String expected, String message) { String formatted = ""; if(message != null) { formatted = message + " "; } fail(formatted + "expected <" + expected +"> but was <" + toString(path) + ">" +"<" + (e!=null && e.getMessage()!=null && e.getMessage().length()>0 ?e.getMessage() :"not authorized by JVM") + ">"); }
private void waitForAndAssertResponse(ListenableFuture<Response> responseFuture) throws InterruptedException, java.util.concurrent.ExecutionException { Response response = responseFuture.get(); if (500 == response.getStatusCode()) { logger.debug("==============\n" + "500 response from call\n" + "Headers:" + response.getHeaders() + "\n" + "==============\n"); assertEquals(response.getStatusCode(), 500, "Should have 500 status code"); assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking"); fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception")); } else { assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES); } } }
@Test public void testSimple() throws Exception { final ModelConverter mr = modelResolver(); final Model model = mr.resolve(ModelWithJodaDateTime.class, new ModelConverterContextImpl(mr), null); assertNotNull(model); final Map<String, Property> props = model.getProperties(); assertEquals(props.size(), 2); for (Map.Entry<String, Property> entry : props.entrySet()) { final String name = entry.getKey(); final Property prop = entry.getValue(); if ("name".equals(name)) { assertEquals(prop.getType(), "string"); } else if ("createdAt".equals(name)) { assertEquals(prop.getType(), "string"); assertEquals(prop.getFormat(), "date-time"); } else { fail(String.format("Unknown property '%s'", name)); } } }
/** * Fails a test with no message. */ static public void fail() { fail(null); }
@Test public void notReflexive() { NotReflexive notReflexive = new NotReflexive(); try { equivalenceTester() .addEquivalentGroup(notReflexive) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(NOT_REFLEXIVE, 0, 0, notReflexive)); } }
@Test public void comparableNotReflexive() { ComparableNotReflexive comparableNotReflexive = new ComparableNotReflexive(); try { equivalenceTester() .addEquivalentGroup(comparableNotReflexive) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(COMPARE_NOT_REFLEXIVE, 0, 0, comparableNotReflexive)); } }
@Override public void corruption(long bytes, String reason) { fail(String.format("corruption of %s bytes: %s", bytes, reason)); }
@Test public void equalsNullThrowsException() { EqualsNullThrowsException equalsNullThrowsException = new EqualsNullThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsNullThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_NULL_EXCEPTION, 0, 0, equalsNullThrowsException)); } }
@Test public void equalsUnrelatedClassThrowsException() { EqualsOtherClassThrowsException equalsOtherClassThrowsException = new EqualsOtherClassThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsOtherClassThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_UNRELATED_CLASS_CLASS_CAST_EXCEPTION, 0, 0, equalsOtherClassThrowsException)); } }
@Test public void equalsNull() { EqualsNull equalsNull = new EqualsNull(); try { equivalenceTester() .addEquivalentGroup(equalsNull) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_NULL, 0, 0, equalsNull)); } }
@Override public void corruption(long bytes, String reason) { fail(String.format("corruption of %s bytes: %s", bytes, reason)); }
@Test public void equalsNullThrowsException() { EqualsNullThrowsException equalsNullThrowsException = new EqualsNullThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsNullThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_NULL_EXCEPTION, 0, 0, equalsNullThrowsException)); } }
@Test public void equalsNull() { EqualsNull equalsNull = new EqualsNull(); try { equivalenceTester() .addEquivalentGroup(equalsNull) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_NULL, 0, 0, equalsNull)); } }
@Test public void comparableNotReflexive() { ComparableNotReflexive comparableNotReflexive = new ComparableNotReflexive(); try { equivalenceTester() .addEquivalentGroup(comparableNotReflexive) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(COMPARE_NOT_REFLEXIVE, 0, 0, comparableNotReflexive)); } }