@Override protected void checkContents(final Object first, final Object... others) { final List<Object> values = new ArrayList<>(); values.add(first); Collections.addAll(values, others); final int expectedSize = 1 + others.length; assertThat(stack.size()).isEqualTo(expectedSize); try ( final AutoCloseableSoftAssertions soft = new AutoCloseableSoftAssertions(); ) { for (int index = 0; index < expectedSize; index++) soft.assertThat(stack.peek(index)) .as("element at index %d", index) .isEqualTo(values.get(index)); } }
@Test public void should_print_line_numbers_of_failed_assertions() { try { AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions(); softly.assertThat(1).isLessThan(0) .isLessThan(1); softly.close(); fail("Should not reach here"); } catch (SoftAssertionError e) { assertThat(e.getMessage()).contains(format("1) %n" + "Expecting:%n" + " <1>%n" + "to be less than:%n" + " <0> %n" + "at AutoClosableSoftAssertionsLineNumberTest.should_print_line_numbers_of_failed_assertions(AutoClosableSoftAssertionsLineNumberTest.java:34)%n" + "2) %n" + "Expecting:%n" + " <1>%n" + "to be less than:%n" + " <1> %n" + "at AutoClosableSoftAssertionsLineNumberTest.should_print_line_numbers_of_failed_assertions(AutoClosableSoftAssertionsLineNumberTest.java:35)")); } }
/** * Performs test results verification * * @param testResults {@link Map} of test results * @param evalExpressions {@link List} of evaluation expressions */ public static void verifyTestResults(Map<String, String> testResults, List<String> evalExpressions) { try(AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) { evalExpressions. forEach(evalExpression -> { String updatedEvalExpression = updateEvalExpression( testResults. entrySet(). stream(). collect(Collectors.toMap( Map.Entry::getKey, entry -> StringUtils. normalizeSpace( entry.getValue()))), evalExpression); softly.assertThat( evaluateJsToBoolean(updatedEvalExpression)). as(updatedEvalExpression). isTrue(); }); } }
@Override protected void checkContents(final Object first, final Object... others) { final Object[] array = ((ArrayValueStack<Object>) stack).getArray(); final int length = array.length; final int size = 1 + others.length; assertThat(stack.size()).isEqualTo(size); final List<Object> expected = new ArrayList<>(); expected.add(first); Collections.addAll(expected, others); try ( final AutoCloseableSoftAssertions soft = new AutoCloseableSoftAssertions(); ) { for (int index = 0; index < size; index++) soft.assertThat(array[index]) .as("element at index %d", index) .isEqualTo(expected.get(index)); for (int index = size; index < length; index++) soft.assertThat(array[index]) .as("null element at index %d?", index) .isNull(); } }
void checkSheetContents(Workbook workbook, int sheetIndex, List<String>... rows) { try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) { checkSheetContents(softly, workbook, sheetIndex, rows); } catch (SoftAssertionError sae) { System.out.println("===========\nACTUAL\n==========="); printSheet(workbook.getSheetAt(sheetIndex)); System.out.println("===========\nEXPECTED\n==========="); printSheet(asList(rows)); throw sae; } }
void checkSheetContents(AutoCloseableSoftAssertions softly, Workbook workbook, int sheetIndex, List<String>... rows) { Sheet sheet = workbook.getSheetAt(sheetIndex); softly.assertThat(sheet.getPhysicalNumberOfRows()).as("Number of rows").isEqualTo(rows.length); for (int i = 0; i < rows.length; i++) { final List<String> dataFromRow = getDataFromRow(sheet, i); softly.assertThat(dataFromRow).as("Row index %d", i).containsExactlyElementsOf(rows[i]); } }