/** This method should fail because the value at end point is a stringbuilder. */ @Test public void should_fail_because_value_at_end_point_is_a_stringbuilder() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeType.isBoolean( tableAssert, info, getValue(null, false), getValue(null, new StringBuilder("test")), false); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[description] %n" + "Expecting that the value at end point:%n" + " <test>%n" + "to be of type%n" + " <BOOLEAN>%n" + "but was of type%n" + " <NOT_IDENTIFIED> (java.lang.StringBuilder)")); } }
@Test public void should_use_AssertionErrorFactory_when_overriding_error_message_is_not_specified() { MyOwnAssertionError expectedError = new MyOwnAssertionError("[description] my message"); Description description = new TestDescription("description"); info.description(description); when(errorFactory.newAssertionError(description)).thenReturn(expectedError); AssertionError failure = failures.failure(info, errorFactory); assertSame(expectedError, failure); }
/** This method should fail because the row exists. */ @Test public void should_fail_because_row_exists() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); Row row = getRow( null, Arrays.asList("ID", "NAME", "FIRSTNAME", "BIRTH"), Arrays.asList(1, "Weaver", "Sigourney", Date.valueOf("1949-10-08"))); try { AssertionsOnRowOfChangeExistence.doesNotExist(tableAssert, info, row); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo(String.format("[description] %n" + "Expecting not exist but exists")); } }
/** This method should fail because the number of columns is equal. */ @Test public void should_fail_because_number_of_columns_is_equal() { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnNumberOfColumns.hasNumberOfColumnsLessThan(tableAssert, info, 3, 3); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[description] %n" + "Expecting size (number of columns) to be less than :%n" + " <3>%n" + "but was:%n" + " <3>")); } }
/** This method should fail because the number of modified columns is greater or equal. */ @Test public void should_fail_because_number_of_modified_columns_is_greater_or_equal() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); Row rowAtStartPoint = getRow( null, Arrays.asList("ID", "NAME", "FIRSTNAME", "BIRTH"), Arrays.asList( getValue(null, 1), getValue(null, "Weaver"), getValue(null, "Sigourney"), getValue(null, Date.valueOf("1949-10-08")))); Row rowAtEndPoint = getRow( null, Arrays.asList("ID", "NAME", "FIRSTNAME", "BIRTH"), Arrays.asList( getValue(null, 1), getValue(null, "Weaverr"), getValue(null, "Sigourneyy"), getValue(null, Date.valueOf("1949-10-08")))); Change change = getChange(DataType.TABLE, "test", ChangeType.MODIFICATION, rowAtStartPoint, rowAtEndPoint); try { AssertionsOnModifiedColumns.hasNumberOfModifiedColumnsLessThan(tableAssert, info, change, 1); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[description] %n" + "Expecting :%n" + " number of modifications is less than 1%n" + "but was:%n" + " 2")); } }
/** This method should fail because the value at end point have different type. */ @Test public void should_fail_because_value_at_end_point_have_different_type() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeType.isBoolean( tableAssert, info, getValue(null, false), getValue(null, "test"), false); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()) .isEqualTo( String.format( "[description] %n" + "Expecting that the value at end point:%n" + " <\"test\">%n" + "to be of type%n" + " <BOOLEAN>%n" + "but was of type%n" + " <TEXT>")); } }