Skip to content

Commit

Permalink
Refactor tests to use assertThat instead of assertEquals (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhak-zaaim authored Nov 14, 2024
1 parent db8224f commit 54fa98f
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -94,10 +93,10 @@ void testIncludeAnalysisFromNumberedInclude() {

Include ia = Include.fromNumberedInclude(content, 2,
String.format("// _include::%d-%d:%s", expectedStartWithinBlock, expectedEndWithinBlock, expectedIncludeTarget));
assertEquals(expectedStartWithinBlock, ia.startWithinBlock(), "unexpected starting line number");
assertEquals(expectedEndWithinBlock, ia.endWithinBlock(), "unexpected ending line number");
assertEquals(includedContent, ia.body(), "unexpected body");
assertEquals(expectedIncludeTarget, ia.includeTarget(), "unexpected include target");
assertThat("unexpected starting line number", ia.startWithinBlock(), is(expectedStartWithinBlock));
assertThat("unexpected ending line number", ia.endWithinBlock(), is(expectedEndWithinBlock));
assertThat("unexpected body", ia.body(), is(includedContent));
assertThat("unexpected include target", ia.includeTarget(), is(expectedIncludeTarget));
}

@Test
Expand All @@ -124,11 +123,11 @@ void testIncludeAnalysisFromBracketedInclude() {
List<String> result = new ArrayList<>();
Include ia = Include.consumeBracketedInclude(content, lineNumber, result, result.size());

assertEquals(expectedStartWithinBlock, ia.startWithinBlock(), "unexpected start within block");
assertEquals(expectedEndWithinBlock, ia.endWithinBlock(), "unexpected end within block");
assertEquals(includedContent, ia.body(), "unexpected body");
assertEquals(expectedIncludeTarget, ia.includeTarget(), "unexpected include target");
assertEquals(expectedFinalLineAfterConsuming, lineNumber.get(), "unexpected final line number");
assertThat("unexpected start within block", ia.startWithinBlock(), is(expectedStartWithinBlock));
assertThat("unexpected end within block", ia.endWithinBlock(), is(expectedEndWithinBlock));
assertThat("unexpected body", ia.body(), is(includedContent));
assertThat("unexpected include target", ia.includeTarget(), is(expectedIncludeTarget));
assertThat("unexpected final line number", lineNumber.get(), is(expectedFinalLineAfterConsuming));
}

@Test
Expand Down Expand Up @@ -242,8 +241,8 @@ void testOverallConversion() throws DiffException {

List<String> numberedContent = IncludePreprocessor.convertBracketedToNumbered(content);

assertEquals(expectedNumberedContent, numberedContent, "overall resulting content did not match; " +
DiffUtils.diff(expectedNumberedContent, numberedContent));
assertThat("overall resulting content did not match; " +
DiffUtils.diff(expectedNumberedContent, numberedContent), numberedContent, is(expectedNumberedContent));
}

@Test
Expand All @@ -260,10 +259,11 @@ void testInitialProcessing() throws IOException, DiffException, URISyntaxExcepti
List<String> actualAfterInitialPreprocessingLines =
IncludePreprocessor.convertHybridToBracketed(originalLines);

assertEquals(expectedAfterInitialPreprocessingLines,
actualAfterInitialPreprocessingLines,
assertThat("overall resulting content did not match; " +
DiffUtils.diff(expectedAfterInitialPreprocessingLines,
actualAfterInitialPreprocessingLines).toString());
actualAfterInitialPreprocessingLines),
actualAfterInitialPreprocessingLines,
is(expectedAfterInitialPreprocessingLines));
}

private List<String> loadFromPath(Path path) throws URISyntaxException, IOException {
Expand Down Expand Up @@ -320,8 +320,7 @@ void testSourceBlockIncludeBracketing() throws DiffException {
Block sba = Block.consumeBlock(orig, lineNumber);

List<String> bracketed = sba.asBracketedBlock();
assertEquals(expectedBracketed, bracketed,
DiffUtils.diff(orig, bracketed).toString());
assertThat("overall resulting content did not match; " + DiffUtils.diff(orig, bracketed).toString(), bracketed, is(expectedBracketed));
}

private static List<String> asList(String text) {
Expand Down

0 comments on commit 54fa98f

Please sign in to comment.