List of usage examples for java.lang AssertionError getMessage
public String getMessage()
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void rowsCountIsExactlyThrowsExceptionWhenToManyRows() { // GIVEN//from w ww . ja va 2 s . c om User user1 = new User(); user1.setUsername("username 1"); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1)); // WHEN + THEN try { JixtureAssert.assertThat(User.class).rowsCountIsExactly(0); } catch (AssertionError e) { assertThat(e.getMessage()).isEqualTo("Expected at most 0 rows but got 1"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void containsAtLeastThrowsExceptionWhenAssertFails() { // GIVEN/*from w w w. j a va 2 s.co m*/ User user1 = new User(); user1.setUsername("username 1"); User user2 = new User(); user2.setUsername("username 2"); Fixture mappingFixture = new MappingFixture(user1, user2); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1)); // WHEN + THEN try { JixtureAssert.assertThat(User.class).containsAtLeast(mappingFixture); } catch (AssertionError e) { assertThat(e.getMessage()) .isEqualTo("Expected but missing elements [{username=username 2, password=null}]"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void containsAtMostThrowsExceptionWhenAssertFails() { // GIVEN/* w w w . java 2 s . co m*/ User user1 = new User(); user1.setUsername("username 1"); User user2 = new User(); user2.setUsername("username 2"); Fixture mappingFixture = new MappingFixture(user1); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1, user2)); // WHEN + THEN try { JixtureAssert.assertThat(User.class).containsAtMost(mappingFixture); } catch (AssertionError e) { assertThat(e.getMessage()) .isEqualTo("Unexpected but present elements [{username=username 2, password=null}]"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void containsExactlyThrowsExceptionWhenAssertFailsWithNotEnoughExpected() { // GIVEN/*from ww w . j a v a 2 s . co m*/ User user1 = new User(); user1.setUsername("username 1"); User user2 = new User(); user2.setUsername("username 2"); Fixture mappingFixture = new MappingFixture(user1); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1, user2)); // WHEN + THEN try { JixtureAssert.assertThat(User.class).containsExactly(mappingFixture); } catch (AssertionError e) { assertThat(e.getMessage()) .isEqualTo("Unexpected but present elements [{username=username 2, password=null}]"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void containsExactlyThrowsExceptionWhenAssertFailsWithTooManyExpected() { // GIVEN//from w w w . j ava2 s.c o m User user1 = new User(); user1.setUsername("username 1"); User user2 = new User(); user2.setUsername("username 2"); Fixture mappingFixture = new MappingFixture(user1, user2); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1)); // WHEN + THEN try { JixtureAssert.assertThat(User.class).containsExactly(mappingFixture); } catch (AssertionError e) { assertThat(e.getMessage()) .isEqualTo("Expected but missing elements [{username=username 2, password=null}]"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:net.cpollet.jixture.asserts.TestJixtureAssert.java
@Test public void containsExactlyFailsWhenNonIgnoredColumnsAreDifferent() { // GIVEN/*from ww w . j a va 2s . c o m*/ User user1 = new User(); user1.setUsername("username"); user1.setPassword("password 1"); User user2 = new User(); user2.setUsername("username"); user2.setPassword("password 2"); Mockito.when(unitDao.getAll(User.class)).thenReturn(Arrays.asList(user1)); Fixture mappingFixture = new MappingFixture(user2); // WHEN + THEN try { JixtureAssert.assertThat(User.class).containsExactly(mappingFixture); } catch (AssertionError e) { assertThat(e.getMessage()) .isEqualTo("Expected but missing elements [{username=username, password=password 2}]," + // "Unexpected but present elements [{username=username, password=password 1}]"); return; } Assert.fail("AssertionError expected but not thrown"); }
From source file:org.apache.solr.handler.component.DistributedDebugComponentTest.java
@Test public void testRandom() throws Exception { final int NUM_ITERS = atLeast(50); for (int i = 0; i < NUM_ITERS; i++) { SolrClient client = random().nextBoolean() ? collection1 : collection2; SolrQuery q = new SolrQuery(); q.set("distrib", "true"); q.setFields("id", "text"); boolean shard1Results = random().nextBoolean(); boolean shard2Results = random().nextBoolean(); String qs = "_query_with_no_results_"; if (shard1Results) { qs += " OR batman"; }/* w w w . j a v a 2 s . c o m*/ if (shard2Results) { qs += " OR superman"; } q.setQuery(qs); Set<String> shards = new HashSet<String>(Arrays.asList(shard1, shard2)); if (random().nextBoolean()) { shards.remove(shard1); shard1Results = false; } else if (random().nextBoolean()) { shards.remove(shard2); shard2Results = false; } q.set("shards", StringUtils.join(shards, ",")); List<String> debug = new ArrayList<String>(10); boolean all = false; final boolean timing = random().nextBoolean(); final boolean query = random().nextBoolean(); final boolean results = random().nextBoolean(); final boolean track = random().nextBoolean(); if (timing) { debug.add("timing"); } if (query) { debug.add("query"); } if (results) { debug.add("results"); } if (track) { debug.add("track"); } if (debug.isEmpty()) { debug.add("true"); all = true; } q.set("debug", (String[]) debug.toArray(new String[debug.size()])); QueryResponse r = client.query(q); try { assertDebug(r, all || track, "track"); assertDebug(r, all || query, "rawquerystring"); assertDebug(r, all || query, "querystring"); assertDebug(r, all || query, "parsedquery"); assertDebug(r, all || query, "parsedquery_toString"); assertDebug(r, all || query, "QParser"); assertDebug(r, all || results, "explain"); assertDebug(r, all || timing, "timing"); } catch (AssertionError e) { throw new AssertionError(q.toString() + ": " + e.getMessage(), e); } } }
From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java
@DomainStep("the stop device test response should return result (.*)") public boolean thenTheResponseShouldReturn(final String result) { LOGGER.info("THEN: the stop device test response should return {}.", result); if (result.toUpperCase().equals("OK")) { try {// w ww . ja v a2s. c om Assert.assertNotNull("Response should not be null", this.response); Assert.assertNull("Throwable should be null", this.throwable); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } else { try { Assert.assertNotNull("Throwable should not be null", this.throwable); Assert.assertEquals(result.toUpperCase(), this.throwable.getClass().getSimpleName().toUpperCase()); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } return true; }
From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StartDeviceTestSteps.java
@DomainStep("the start device test response should return result (.*)") public boolean thenTheResponseShouldReturn(final String result) { LOGGER.info("THEN: the start device test response should return {}.", result); if (result.toUpperCase().equals("OK")) { try {/*from w ww . j a v a 2 s . c o m*/ Assert.assertNotNull("Response should not be null", this.response); Assert.assertNull("Throwable should be null", this.throwable); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } else { try { Assert.assertNotNull("Throwable should not be null", this.throwable); Assert.assertEquals(result.toUpperCase(), this.throwable.getClass().getSimpleName().toUpperCase()); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } return true; }
From source file:com.alliander.osgp.acceptancetests.firmwaremanagement.GetFirmwareVersionSteps.java
@DomainStep("the get firmware version response should return result (.*)") public boolean thenTheResponseShouldReturn(final String result) { LOGGER.info("THEN: the get firmware version response should return {}.", result); if (result.toUpperCase().equals("OK")) { try {//from w w w .j a va 2 s. c om Assert.assertNotNull("Response should not be null", this.response); Assert.assertNull("Throwable should be null", this.throwable); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } else { try { Assert.assertNotNull("Throwable should not be null", this.throwable); Assert.assertEquals(result.toUpperCase(), this.throwable.getClass().getSimpleName().toUpperCase()); } catch (final AssertionError e) { LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage()); return false; } } return true; }