@Test public void test_sugar_assertThat() { assertThat(true); try { assertThat(false); fail(); } catch (AssertionError e) { assertThat(e.getMessage(), is("Expected true but is false")); } }
@Test public void testReadAggregate_WrongIdentifier() { fixture.registerAggregateFactory(mockAggregateFactory); fixture.registerAnnotatedCommandHandler( new MyCommandHandler(fixture.getRepository(), fixture.getEventBus())); TestExecutor exec = fixture.given(new MyEvent("AggregateId", 1)); try { exec.when(new TestCommand("OtherIdentifier")); fail("Expected an AssertionError"); } catch (AssertionError e) { assertTrue( "Wrong message. Was: " + e.getMessage(), e.getMessage().contains("OtherIdentifier")); assertTrue("Wrong message. Was: " + e.getMessage(), e.getMessage().contains("AggregateId")); } }
private void check(AssertionError error) throws Exception { createComparisonFailure(verify(constructorInvoker)); assertFalse(error instanceof ComparisonFailure); assertEquals( "[Jedi] \nExpecting:\n <\"Yoda\">\nto be equal to:\n <\"Luke\">\nbut was not.", error.getMessage()); }
@Test public void testMultipleErrors3() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertError(new TestException()); } catch (AssertionError ex) { if (!(ex.getCause() instanceof CompositeException)) { fail("Multiple Error present but the reported error doesn't have a composite cause!"); } // expected return; } fail("Multiple Error present but no assertion error!"); }
@Test public void testNoTerminalEventBut2Errors() { TestSubscriber<Integer> ts = TestSubscriber.create(); ts.onError(new TestException()); ts.onError(new TestException()); try { ts.assertNoTerminalEvent(); fail("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected if (!(ex.getCause() instanceof CompositeException)) { fail("Did not report a composite exception cause: " + ex.getCause()); } } }