/** * This method should fail because the value at start point is a stringbuilder. */ @Test public void should_fail_because_value_at_start_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, new StringBuilder("test")), getValue(null, true), false); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at start point:%n" + " <test>%n" + "to be of type%n" + " <BOOLEAN>%n" + "but was of type%n" + " <NOT_IDENTIFIED> (java.lang.StringBuilder)")); } }
/** * This method should fail because the value is not a date. */ @Test public void should_fail_because_value_is_not_a_date() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueInequality.isNotEqualTo(tableAssert, info, getValue(null, 8), DateValue.of(2007, 12, 23)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <8>%n" + "to be of type%n" + " <[DATE, DATE_TIME]>%n" + "but was of type%n" + " <NUMBER>")); } }
/** * This method should fail because one of the values is not a date/time. */ @Test public void should_fail_because_one_value_is_not_a_date_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, "other"), getValue(null, Timestamp.valueOf("2002-07-25 03:30:05")), DateTimeValue.of(DateValue.of(2007, 12, 23), TimeValue.of(9, 1)), DateTimeValue.of(DateValue.of(2002, 7, 25), TimeValue.of(3, 30, 5))); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at start point:%n" + " <\"other\">%n" + "to be of type%n" + " <[DATE, DATE_TIME, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * Verifies that the value is before or equal to a date value. * * @param <A> The type of the assertion which call this method. * @param assertion The assertion which call this method. * @param info Writable information about an assertion. * @param value The value. * @param date The date value to compare to. * @return {@code this} assertion object. * @throws AssertionError If the value is not before or equal to the date value in parameter. */ public static <A extends AbstractAssert<?>> A isBeforeOrEqualTo(A assertion, WritableAssertionInfo info, Value value, DateValue date) { Object object = value.getValue(); AssertionsOnValueType.isOfAnyTypeIn(assertion, info, value, ValueType.DATE, ValueType.DATE_TIME); if (object instanceof Date) { if (DateValue.from((Date) object).isBefore(date) || areEqual(value, date)) { return assertion; } throw failures.failure(info, shouldBeBeforeOrEqual(DateValue.from((Date) object), date)); } else { DateTimeValue dateTimeValue = DateTimeValue.of(date); if (DateTimeValue.from((Timestamp) object).isBefore(dateTimeValue) || areEqual(value, dateTimeValue)) { return assertion; } throw failures.failure(info, shouldBeBeforeOrEqual(DateTimeValue.from((Timestamp) object), dateTimeValue)); } }
/** * This method tests the {@code containsValues} assertion method. */ @Test public void test_contains_values() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, Locale.FRENCH), getValue(null, Locale.ENGLISH), getValue( null, Locale.FRENCH), getValue(null, null))); TableAssert tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, Locale.FRENCH, Locale.ENGLISH, Locale.FRENCH, null); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, Locale.FRENCH, Locale.FRENCH, Locale.ENGLISH, null); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, Locale.ENGLISH, null, Locale.FRENCH, Locale.FRENCH); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); list = new ArrayList<>(Arrays.asList(getValue(null, Locale.FRENCH), getValue(null, Locale.ENGLISH), getValue(null, Locale.ENGLISH), getValue( null, null))); tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, null, Locale.ENGLISH, Locale.FRENCH, Locale.ENGLISH); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); }
/** * This method should fail because the value at start point is different. */ @Test public void should_fail_because_value_at_start_point_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, UUID.fromString( "0E2A1269-EFF0-4233-B87B-B53E8B6F164D")), getValue(null, UUID.fromString("30B443AE-C0C9-4790-9BEC-CE1380808435")), UUID.fromString("30B443AE-C0C9-4790-9BEC-CE1380808435")); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that start point:%n" + " <0e2a1269-eff0-4233-b87b-b53e8b6f164d>%n" + "to be equal to: %n" + " <30b443ae-c0c9-4790-9bec-ce1380808435>")); } }
/** * This method should fail because one of the values is not a number. */ @Test public void should_fail_because_one_value_is_not_a_number() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "other"), getValue(null, 8))); try { AssertionsOnColumnEquality.hasValues(tableAssert, info, list, 7, 8); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <\"other\">%n" + "to be of type%n" + " <[NUMBER, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the values are different. */ @Test public void should_fail_because_values_are_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, new byte[] {0, 1}), getValue(null, new byte[] {2, 3}), getValue( null, null))); try { AssertionsOnColumnEquality.hasValues(tableAssert, info, list, new byte[] { 0, 1 }, new byte[] { 1, 3 }, null); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 1 to be equal to the expected value but was not equal")); } }
/** * This method should fail because one of the values is not a date/time. */ @Test public void should_fail_because_one_value_is_not_a_date() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "other"), getValue(null, Date.valueOf("2002-07-25")))); try { AssertionsOnColumnContent.containsValues(tableAssert, info, list, DateValue.of(2007, 12, 23), DateValue.of(2007, 12, 23)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <\"other\">%n" + "to be of type%n" + " <[DATE, DATE_TIME, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the value is not a boolean. */ @Test public void should_fail_because_value_is_not_a_boolean() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueType.isBoolean(tableAssert, info, getValue(null, "text")); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <\"text\">%n" + "to be of type%n" + " <BOOLEAN>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the value is not a date/time. */ @Test public void should_fail_because_value_is_not_a_date_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueCloseness.isCloseTo(tableAssert, info, getValue(null, 8), DateTimeValue.of(DateValue.of(2007, 12, 23)), DateValue.of(0, 0, 1)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <8>%n" + "to be of type%n" + " <[DATE, DATE_TIME]>%n" + "but was of type%n" + " <NUMBER>")); } }
/** * This method should fail because one of the values is not a date/time. */ @Test public void should_fail_because_one_value_is_not_a_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "other"), getValue(null, Time.valueOf("03:30:05")))); try { AssertionsOnColumnContent.containsValues(tableAssert, info, list, TimeValue.of(9, 1), TimeValue.of(9, 1)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <\"other\">%n" + "to be of type%n" + " <[TIME, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * Verifies that the values of a column are equal to texts. * * @param <A> The type of the assertion which call this method. * @param assertion The assertion which call this method. * @param info Writable information about an assertion. * @param valuesList The list of values. * @param expected The expected text values. * @return {@code this} assertion object. * @throws AssertionError If the values of the column are not equal to the texts in parameter. */ public static <A extends AbstractAssert<?>> A hasValues(A assertion, WritableAssertionInfo info, List<Value> valuesList, String... expected) { AssertionsOnColumnType.isOfAnyTypeIn(assertion, info, valuesList, ValueType.TEXT, ValueType.NUMBER, ValueType.DATE, ValueType.TIME, ValueType.DATE_TIME, ValueType.UUID, ValueType.NOT_IDENTIFIED); AssertionsOnNumberOfRows.hasNumberOfRows(assertion, info, valuesList.size(), expected.length); int index = 0; for (Value value : valuesList) { if (!areEqual(value, expected[index])) { throw failures.failure(info, shouldBeEqual(index, Values.getRepresentationFromValueInFrontOfExpected(value, expected[index]), expected[index])); } index++; } return assertion; }
/** * This method should fail because one of the values is not a text. */ @Test public void should_fail_because_one_value_is_not_a_text() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "T"), getValue(null, false))); try { AssertionsOnColumnEquality.hasValues(tableAssert, info, list, 'T', 't'); fail("An exception must be raised"); } catch (AssertionError e) { assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 1:%n" + " <false>%n" + "to be of type%n" + " <[TEXT, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <BOOLEAN>")); } }
/** * This method should fail because the value at end point is different. */ @Test public void should_fail_because_value_at_end_point_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, 1), getValue(null, 2), 1); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that end point:%n" + " <2>%n" + "to be equal to: %n" + " <1>")); } }
/** * Verifies that the values of a column are equal to date values. * * @param <A> The type of the assertion which call this method. * @param assertion The assertion which call this method. * @param info Writable information about an assertion. * @param valuesList The list of values. * @param expected The expected date values. * @return {@code this} assertion object. * @throws AssertionError If the values of the column are not equal to the date values in parameter. */ public static <A extends AbstractAssert<?>> A hasValues(A assertion, WritableAssertionInfo info, List<Value> valuesList, DateValue... expected) { AssertionsOnColumnType .isOfAnyTypeIn(assertion, info, valuesList, ValueType.DATE, ValueType.DATE_TIME, ValueType.NOT_IDENTIFIED); AssertionsOnNumberOfRows.hasNumberOfRows(assertion, info, valuesList.size(), expected.length); int index = 0; for (Value value : valuesList) { if (!areEqual(value, expected[index])) { throw failures.failure(info, shouldBeEqual(index, Values.getRepresentationFromValueInFrontOfExpected(value, expected[index]), expected[index])); } index++; } return assertion; }
/** * This method should fail because the value is not a text. */ @Test public void should_fail_because_value_is_not_a_text() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueInequality.isNotEqualTo(tableAssert, info, getValue(null, 8), 'T'); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <8>%n" + "to be of type%n" + " <TEXT>%n" + "but was of type%n" + " <NUMBER>")); } }
/** * This method should fail because the value at end point is different. */ @Test public void should_fail_because_value_at_end_point_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, 1), getValue(null, 2), 1, 1); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that end point:%n" + " <2>%n" + "to be equal to: %n" + " <1>")); } }
/** * This method should fail because the value is a stringbuiler. */ @Test public void should_fail_because_value_is_a_stringbuilder() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, new StringBuilder("test")), getValue(null, true))); AssertionsOnColumnType.isBytes(tableAssert, info, list, false); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <test>%n" + "to be of type%n" + " <BYTES>%n" + "but was of type%n" + " <NOT_IDENTIFIED> (java.lang.StringBuilder)")); } }
/** * This method tests the {@code hasNumberOfChangesLessThan} assertion method. */ @Test public void test_has_number_of_changes_less_than() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); Table table = new Table(); TableAssert tableAssert = assertThat(table); Row rowAtStartPoint = getRow(Arrays.asList("ID"), 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(Arrays.asList("ID"), 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.CREATION, rowAtStartPoint, rowAtEndPoint); Changes changes = getChanges(Arrays.asList(change, change)); TableAssert tableAssert2 = AssertionsOnNumberOfChanges.hasNumberOfChangesLessThan(tableAssert, info, changes, 3); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); }
/** * This method should fail because the type of change is different. */ @Test public void should_fail_because_type_of_change_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); Row rowAtStartPoint = getRow(null, null, null); Row rowAtEndPoint = getRow(null, null, null); Change change = getChange(DataType.TABLE, "test", ChangeType.CREATION, rowAtStartPoint, rowAtEndPoint); try { AssertionsOnChangeType.isDeletion(tableAssert, info, change); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + "to be of type%n" + " <DELETION>%n" + "but was of type%n" + " <CREATION>")); } }
/** * This method tests the {@code isDate} assertion method. */ @Test public void test_is_date() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, Date.valueOf("2007-12-23")), getValue(null, Date.valueOf("2002-07-25")))); TableAssert tableAssert2 = AssertionsOnColumnType.isDate(tableAssert, info, list, false); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); list = new ArrayList<>(Arrays.asList(getValue(null, Date.valueOf("2007-12-23")), getValue(null, Date.valueOf("2002-07-25")))); tableAssert2 = AssertionsOnColumnType.isDate(tableAssert, info, list, true); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); list = new ArrayList<>(Arrays.asList(getValue(null, null), getValue(null, Date.valueOf("2002-07-25")))); tableAssert2 = AssertionsOnColumnType.isDate(tableAssert, info, list, true); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); }
/** * This method should fail because the data type is different. */ @Test public void should_fail_because_data_type_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); Row rowAtStartPoint = getRow(null, null, null); Row rowAtEndPoint = getRow(null, null, null); Change change = getChange(DataType.REQUEST, "test", ChangeType.CREATION, rowAtStartPoint, rowAtEndPoint); try { AssertionsOnDataType.isOnTable(tableAssert, info, change); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + "to be on data type%n" + " <TABLE>%n" + "but was on data type%n" + " <REQUEST>")); } }
/** * This method tests the description of value at end point of column of change of changes. */ @Test @NeedReload public void test_default_description_value_at_end_point_of_column_of_change_of_changes() throws Exception { Field field = AbstractElement.class.getDeclaredField("info"); field.setAccessible(true); Changes changesFromSource = new Changes(source).setStartPointNow(); Changes changesFromDataSource = new Changes(dataSource).setStartPointNow(); updateChangesForTests(); changesFromSource.setEndPointNow(); changesFromDataSource.setEndPointNow(); ChangeColumnValueAssert assertionFromSource = assertThat(changesFromSource).change().column().valueAtEndPoint(); ChangeColumnValueAssert assertionFromDataSource = assertThat(changesFromDataSource).change( 1).column().valueAtEndPoint(); WritableAssertionInfo infoFromSource = (WritableAssertionInfo) field.get(assertionFromSource); assertThat(infoFromSource.descriptionText()).isEqualTo("Value at end point of Column at index 0 (column name : ID) of Change at index 0 (on table : ACTOR and with primary key : [4]) of Changes on tables of 'sa/jdbc:h2:mem:test' source"); WritableAssertionInfo infoFromDataSource = (WritableAssertionInfo) field.get(assertionFromDataSource); assertThat(infoFromDataSource.descriptionText()).isEqualTo("Value at end point of Column at index 0 (column name : ID) of Change at index 1 (on table : INTERPRETATION and with primary key : [6]) of Changes on tables of a data source"); }
/** * This method should fail because the value is not a time. */ @Test public void should_fail_because_value_is_not_a_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueInequality.isNotEqualTo(tableAssert, info, getValue(null, 8), TimeValue.of(9, 1)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <8>%n" + "to be of type%n" + " <TIME>%n" + "but was of type%n" + " <NUMBER>")); } }
/** * This method should fail because one of the values is not a boolean. */ @Test public void should_fail_because_one_value_is_not_a_boolean() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "other"), getValue(null, false))); try { AssertionsOnColumnEquality.hasValues(tableAssert, info, list, Boolean.TRUE, Boolean.FALSE); fail("An exception must be raised"); } catch (AssertionError e) { assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <\"other\">%n" + "to be of type%n" + " <[BOOLEAN, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the value at end point is different. */ @Test public void should_fail_because_value_at_end_point_is_different() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, false), getValue(null, true), Boolean.FALSE); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that end point:%n" + " <true>%n" + "to be equal to: %n" + " <false>")); } }
/** * This method should fail because the value is a stringbuiler. */ @Test public void should_fail_because_value_is_a_stringbuilder() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, new StringBuilder("test")), getValue(null, true))); AssertionsOnColumnType.isDateTime(tableAssert, info, list, false); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at index 0:%n" + " <test>%n" + "to be of type%n" + " <DATE_TIME>%n" + "but was of type%n" + " <NOT_IDENTIFIED> (java.lang.StringBuilder)")); } }
/** * This method should fail because the value is not compatible. */ @Test public void should_fail_because_value_is_not_compatible() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueChronology.isBefore(tableAssert, info, getValue(null, "test"), DateValue.of(2007, 12, 23)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <\"test\">%n" + "to be of type%n" + " <[DATE, DATE_TIME]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because one of the values is not a date/time. */ @Test public void should_fail_because_one_value_is_not_a_date_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, "other"), getValue(null, Timestamp.valueOf("2007-12-23 09:01:00")), DateTimeValue.of(DateValue.of(2007, 12, 23), TimeValue.of(9, 1))); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at start point:%n" + " <\"other\">%n" + "to be of type%n" + " <[DATE, DATE_TIME, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the expected index must be not {@code null}. */ @Test public void should_fail_because_expected_index_must_be_not_null() 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.hasModifiedColumns(tableAssert, info, change, 1, null); fail("An exception must be raised"); } catch (NullPointerException e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("Column index must be not null")); } }
/** * This method should fail because the value is not compatible. */ @Test public void should_fail_because_value_is_not_compatible() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueChronology.isBefore(tableAssert, info, getValue(null, "test"), DateTimeValue.of(DateValue.of(2007, 12, 23), TimeValue.of(9, 1, 6))); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <\"test\">%n" + "to be of type%n" + " <[DATE, DATE_TIME]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method should fail because the number of rows is different. */ @Test public void should_fail_because_number_of_rows_is_less_than_or_equal() { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnNumberOfRows.hasNumberOfRowsGreaterThan(tableAssert, info, 8, 8); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting size (number of rows) to be greater than :%n" + " <8>%n" + "but was:%n" + " <8>")); } }
/** * This method should fail because the expected string is not correct to compare to a time. */ @Test public void should_fail_because_expected_string_is_not_correct_to_compare_to_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueChronology.isBeforeOrEqualTo(tableAssert, info, getValue(null, Time.valueOf("09:01:05")), "09_01:00"); fail("An exception must be raised"); } catch (AssertJDBException e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("Expected <09_01:00> is not correct to compare to <09:01:05.000000000>")); } }
/** * This method should fail because the value is not a number. */ @Test public void should_fail_because_value_is_not_a_number() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueEquality.isEqualTo(tableAssert, info, getValue(null, false), 8); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <false>%n" + "to be of type%n" + " <NUMBER>%n" + "but was of type%n" + " <BOOLEAN>")); } }
/** * This method should fail because the value at start point have different type. */ @Test public void should_fail_because_value_at_start_point_have_different_type() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeType.isText(tableAssert, info, getValue(null, true), 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 start point:%n" + " <true>%n" + "to be of type%n" + " <TEXT>%n" + "but was of type%n" + " <BOOLEAN>")); } }
/** * This method should fail because one of the values is not a time. */ @Test public void should_fail_because_one_value_is_not_a_time() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnColumnOfChangeEquality.hasValues(tableAssert, info, getValue(null, "other"), getValue(null, Time.valueOf("09:01:05")), TimeValue.of(9, 1)); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting that the value at start point:%n" + " <\"other\">%n" + "to be of type%n" + " <[TIME, NOT_IDENTIFIED]>%n" + "but was of type%n" + " <TEXT>")); } }
/** * This method tests the {@code as} method to modify the description. */ @Test public void test_as() throws Exception { Field field = AbstractElement.class.getDeclaredField("info"); field.setAccessible(true); Table table = new Table(source, "actor"); TableRowAssert assertion = assertThat(table).row(); WritableAssertionInfo info1 = (WritableAssertionInfo) field.get(assertion); assertThat(info1.descriptionText()).isEqualTo("Row at index 0 of ACTOR table"); TableRowAssert assertion2 = assertion.as("message %s with text", 1); WritableAssertionInfo info2 = (WritableAssertionInfo) field.get(assertion2); assertThat(info2.descriptionText()).isEqualTo("message 1 with text"); Description description = new TextDescription("description %s %s", "with", "information"); TableRowAssert assertion3 = assertion.as(description); WritableAssertionInfo info3 = (WritableAssertionInfo) field.get(assertion3); assertThat(info3.descriptionText()).isEqualTo("description with information"); }
/** * This method tests the {@code containsValues} assertion method. */ @Test public void test_contains_values() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); Table table = new Table(); TableAssert tableAssert = assertThat(table); List<Value> list = new ArrayList<>(Arrays.asList(getValue(null, "test1"), getValue(null, "test2"), getValue(null, "test1"), getValue( null, null))); TableAssert tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, "test1", "test2", "test1", null); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, "test2", "test1", "test1", null); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); tableAssert2 = AssertionsOnColumnContent.containsValues(tableAssert, info, list, null, "test1", "test1", "test2"); Assertions.assertThat(tableAssert2).isSameAs(tableAssert); }
/** * This method should fail because the value is a stringbuilder. */ @Test public void should_fail_because_value_is_a_stringbuilder() throws Exception { WritableAssertionInfo info = new WritableAssertionInfo(); info.description("description"); Table table = new Table(); TableAssert tableAssert = assertThat(table); try { AssertionsOnValueType.isOfType(tableAssert, info, getValue(null, new StringBuilder("text")), ValueType.TEXT); fail("An exception must be raised"); } catch (AssertionError e) { Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[description] %n" + "Expecting:%n" + " <text>%n" + "to be of type%n" + " <TEXT>%n" + "but was of type%n" + " <NOT_IDENTIFIED> (java.lang.StringBuilder)")); } }