diff --git a/pom.xml b/pom.xml index 3f218bb..eb7fd39 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.editorconfig editorconfig-maven-plugin 1.0.0-alpha1 - + maven-plugin 5.9.1 3.26.0 @@ -101,6 +101,11 @@ + + org.apache.maven.plugins + maven-plugin-plugin + 3.15.1 + org.apache.maven.plugins maven-source-plugin diff --git a/src/main/java/org/editorconfig/plugin/maven/verifiers/SpecOptionVerifier.java b/src/main/java/org/editorconfig/plugin/maven/verifiers/SpecOptionVerifier.java index 9f810c0..63aa095 100644 --- a/src/main/java/org/editorconfig/plugin/maven/verifiers/SpecOptionVerifier.java +++ b/src/main/java/org/editorconfig/plugin/maven/verifiers/SpecOptionVerifier.java @@ -48,8 +48,8 @@ protected void onInit( * Checks, whether the content of the file is compliant with the current setting of the {@link #targetOption} * * @param content content of the file - * @param section section that is assigned to the current file. The section is expected to be already merged with all others that present - * in .editorconfig files in the tree. + * @param section section that is assigned to the current file. The section is expected to be already merged with + * all others that present in .editorconfig files in the tree. * * @return OptionViolations wrapped */ @@ -60,7 +60,7 @@ protected OptionValidationResult checkInternal( OptionValue optionValue = getValueFromSection(section); - if (optionValue.isUnset() || optionValue.getValue() == null) { + if (optionValue == null || optionValue.isUnset() || optionValue.getValue() == null) { return OptionValidationResult.skippedValidation(targetOption); } diff --git a/src/main/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifier.java b/src/main/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifier.java index 9731f76..a5796cb 100644 --- a/src/main/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifier.java +++ b/src/main/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifier.java @@ -41,7 +41,9 @@ protected OptionValidationResult checkInternal( VerifiersExecutionContext executionContext) { OptionValue expectedCharset = getValueFromSection(section); - if (expectedCharset.isUnset() || expectedCharset.getValue() == null) { + if (expectedCharset == null + || expectedCharset.isUnset() + || expectedCharset.getValue() == null) { return OptionValidationResult.skippedValidation(targetOption); } diff --git a/src/test/java/org/editorconfig/plugin/maven/common/BufferedInputStreamTest.java b/src/test/java/org/editorconfig/plugin/maven/common/BufferedInputStreamTest.java index 9c8231b..5e705b0 100644 --- a/src/test/java/org/editorconfig/plugin/maven/common/BufferedInputStreamTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/common/BufferedInputStreamTest.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.assertj.core.api.Assertions; +import org.assertj.core.api.SoftAssertions; import org.editorconfig.plugin.maven.model.EndOfLine; import org.junit.jupiter.api.Test; @@ -18,7 +18,7 @@ class BufferedInputStreamTest { @Test - void test_readLine_LF() throws IOException { + void getEndOfLine_3LinesLfLfLf_Lf() throws IOException { // given String firstRow = "first row\n"; String secondRow = "second row\n"; @@ -30,17 +30,20 @@ void test_readLine_LF() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + softAssertions.assertThat(secondEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + }); } @Test - void test_readLine_LF_lastLineIsEOFEnded() throws IOException { + void getEndOfLine_3LinesLfLfEof_Eof() throws IOException { // given String firstRow = "first row\n"; String secondRow = "second row\n"; @@ -52,17 +55,20 @@ void test_readLine_LF_lastLineIsEOFEnded() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.EOF); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + softAssertions.assertThat(secondEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.EOF); + }); } @Test - void test_readLine_CRLF() throws IOException { + void getEndOfLine_3LinesCrlfCrlfCrlf_Crlf() throws IOException { // given String firstRow = "first row\r\n"; String secondRow = "second row\r\n"; @@ -74,17 +80,22 @@ void test_readLine_CRLF() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + softAssertions + .assertThat(secondEndOfLine) + .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + }); } @Test - void test_readLine_CRLF_lastRowEndWithEOF() throws IOException { + void getEndOfLine_3LinesCrlfCrlfEof_Eof() throws IOException { // given String firstRow = "first row\r\n"; String secondRow = "second row\r\n"; @@ -96,17 +107,22 @@ void test_readLine_CRLF_lastRowEndWithEOF() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.EOF); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + softAssertions + .assertThat(secondEndOfLine) + .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.EOF); + }); } @Test - void test_readLine_CR() throws IOException { + void getEndOfLine_3LinesCrCrCr_Cr() throws IOException { // given String firstRow = "first row\r"; String secondRow = "second row\r"; @@ -118,17 +134,20 @@ void test_readLine_CR() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN); + softAssertions.assertThat(secondEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN); + }); } @Test - void test_readLine_CR_lastRowEndWithEOF() throws IOException { + void getEndOfLine_3LinesCrCrEof_Eof() throws IOException { // given String firstRow = "first row\r"; String secondRow = "second row\r"; @@ -140,13 +159,16 @@ void test_readLine_CR_lastRowEndWithEOF() throws IOException { new BufferedInputStream(testFromAsciiString(source)); // when - ByteArrayLine first = bufferedInputStream.readLine(); - ByteArrayLine second = bufferedInputStream.readLine(); - ByteArrayLine third = bufferedInputStream.readLine(); - - Assertions.assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN); - Assertions.assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.CARRIAGE_RERUN); - Assertions.assertThat(third.getEndOfLine()).isEqualTo(EndOfLine.EOF); + EndOfLine firstEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine secondEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + EndOfLine thirdEndOfLine = bufferedInputStream.readLine().getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN); + softAssertions.assertThat(secondEndOfLine).isEqualTo(EndOfLine.CARRIAGE_RERUN); + softAssertions.assertThat(thirdEndOfLine).isEqualTo(EndOfLine.EOF); + }); } private static ByteArrayInputStream testFromAsciiString(String asciiString) { diff --git a/src/test/java/org/editorconfig/plugin/maven/common/ByteArrayLineTest.java b/src/test/java/org/editorconfig/plugin/maven/common/ByteArrayLineTest.java index c08c3be..352b3c1 100644 --- a/src/test/java/org/editorconfig/plugin/maven/common/ByteArrayLineTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/common/ByteArrayLineTest.java @@ -7,6 +7,7 @@ import java.nio.charset.Charset; import java.util.stream.Stream; +import org.assertj.core.api.SoftAssertions; import org.editorconfig.plugin.maven.model.EndOfLine; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -26,25 +27,29 @@ class ByteArrayLineTest { @Test - void test_endOfLine() { - - // when. + void isTheLastLine_2LinesLfEof_FalseTrue() { + // given ByteArrayLine first = new ByteArrayLine( new byte[] {'H', 'e', 'l', 'l', 'o', '\n'}, 5, EndOfLine.LINE_FEED); ByteArrayLine second = new ByteArrayLine(new byte[] {'H', 'e', 'l', 'l', 'o'}, 5, EndOfLine.EOF); - // then. - assertThat(first.getEndOfLine()).isEqualTo(EndOfLine.LINE_FEED); - assertThat(first.isTheLastLine()).isFalse(); - assertThat(second.getEndOfLine()).isEqualTo(EndOfLine.EOF); - assertThat(second.isTheLastLine()).isTrue(); + // when + EndOfLine firstEndOfLine = first.getEndOfLine(); + EndOfLine secondEndOfLine = second.getEndOfLine(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(firstEndOfLine).isEqualTo(EndOfLine.LINE_FEED); + softAssertions.assertThat(secondEndOfLine).isEqualTo(EndOfLine.EOF); + softAssertions.assertThat(first.isTheLastLine()).isFalse(); + softAssertions.assertThat(second.isTheLastLine()).isTrue(); + }); } @Test - void test_getContent() { - - // when. + void getContentWithEol_3LinesLfCrlfEof_Ok() { + // given ByteArrayLine first = new ByteArrayLine( new byte[] {'H', 'e', 'l', 'l', 'o', '\n'}, 5, EndOfLine.LINE_FEED); ByteArrayLine second = new ByteArrayLine( @@ -54,20 +59,28 @@ void test_getContent() { ByteArrayLine third = new ByteArrayLine( new byte[] {'B', 'B', 'B', '\0', '\0', '\0', '\0'}, 3, EndOfLine.EOF); - // then. - assertThat(first.getContentWithEol()) - .hasSize(6) - .containsExactly('H', 'e', 'l', 'l', 'o', '\n'); - assertThat(second.getContentWithEol()) - .hasSize(6) - .containsExactly('A', 'l', 'e', 'x', '\r', '\n'); - assertThat(third.getContentWithEol()).hasSize(4).containsExactly('B', 'B', 'B', '\0'); + // when + byte[] firstContent = first.getContentWithEol(); + byte[] secondContent = second.getContentWithEol(); + byte[] thirdContent = third.getContentWithEol(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions + .assertThat(firstContent) + .hasSize(6) + .containsExactly('H', 'e', 'l', 'l', 'o', '\n'); + softAssertions + .assertThat(secondContent) + .hasSize(6) + .containsExactly('A', 'l', 'e', 'x', '\r', '\n'); + softAssertions.assertThat(thirdContent).hasSize(4).containsExactly('B', 'B', 'B', '\0'); + }); } @Test - void test_lengthWithEol() { - - // when. + void lengthWithEol_3LinesLfCrlfEof_Ok() { + // given ByteArrayLine first = new ByteArrayLine( new byte[] {'H', 'e', 'l', 'l', 'o', '\n'}, 5, EndOfLine.LINE_FEED); ByteArrayLine second = new ByteArrayLine( @@ -77,33 +90,38 @@ void test_lengthWithEol() { ByteArrayLine third = new ByteArrayLine( new byte[] {'B', 'B', 'B', '\0', '\0', '\0', '\0'}, 3, EndOfLine.EOF); - // then. - assertThat(first.lengthWithEoL()).isEqualTo(6); - assertThat(second.lengthWithEoL()).isEqualTo(6); - assertThat(third.lengthWithEoL()).isEqualTo(4); + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(first.lengthWithEoL()).isEqualTo(6); + softAssertions.assertThat(second.lengthWithEoL()).isEqualTo(6); + softAssertions.assertThat(third.lengthWithEoL()).isEqualTo(4); + }); } @ParameterizedTest @MethodSource("test_isEmpty") - void test_isEmpty(String string, EndOfLine endOfLine, boolean expectedIsEmpty) { - - // when. - boolean actualIsEmpty = new ByteArrayLine( - string.getBytes(US_ASCII), - string.length() - endOfLine.getLengthInBytes(), - endOfLine) - .isEmpty(); - - // then. - assertThat(actualIsEmpty).isEqualTo(expectedIsEmpty); + void isEmpty_ListOfStrings_Ok(String string, EndOfLine endOfLine, boolean expected) { + // given + ByteArrayLine line = new ByteArrayLine( + string.getBytes(US_ASCII), + string.length() - endOfLine.getLengthInBytes(), + endOfLine); + + // when + boolean actual = line.isEmpty(); + + // then + assertThat(actual).isEqualTo(expected); } @ParameterizedTest @MethodSource("test_getIndent") - void test_getIndent(ByteArrayLine line, Charset charset, int expectedIndent) { - int indent = line.getIndent(2, charset); + void getIndent_ListOfStrings_Ok(ByteArrayLine line, Charset charset, int expected) { + // when + int actual = line.getIndent(2, charset); - assertThat(indent).isEqualTo(expectedIndent); + // then + assertThat(actual).isEqualTo(expected); } static Stream test_getIndent() { diff --git a/src/test/java/org/editorconfig/plugin/maven/common/CachingInputStreamTest.java b/src/test/java/org/editorconfig/plugin/maven/common/CachingInputStreamTest.java index 65baf40..ff01375 100644 --- a/src/test/java/org/editorconfig/plugin/maven/common/CachingInputStreamTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/common/CachingInputStreamTest.java @@ -10,24 +10,25 @@ import java.io.IOException; import java.net.URISyntaxException; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + class CachingInputStreamTest { @Test - void test_readAllBytes_twice() throws IOException { + void reset_readAllBytesTwice_areEqual() throws IOException { CachingInputStream cachingInputStream = fromFile("caching_input_stream/SomeClass.java"); byte[] first = cachingInputStream.readAllBytes(); cachingInputStream.reset(); byte[] second = cachingInputStream.readAllBytes(); - Assertions.assertThat(first).isEqualTo(second); + assertThat(first).isEqualTo(second); } @Test - void test_BufferedInputStream() throws IOException { + void reset_writeBytes_areEqual() throws IOException { CachingInputStream cachingInputStream = fromFile("caching_input_stream/SimpleRecord.java"); BufferedInputStream bufferedInputStream = new BufferedInputStream(cachingInputStream); @@ -46,8 +47,7 @@ void test_BufferedInputStream() throws IOException { secondIteration.writeBytes(line.getContentWithEol()); } - Assertions.assertThat(firstIteration.toByteArray()) - .isEqualTo(secondIteration.toByteArray()); + assertThat(firstIteration.toByteArray()).isEqualTo(secondIteration.toByteArray()); } private static CachingInputStream fromFile(String file) { diff --git a/src/test/java/org/editorconfig/plugin/maven/config/TreeBuilderTest.java b/src/test/java/org/editorconfig/plugin/maven/config/TreeBuilderTest.java index 81a0673..14f4e5b 100644 --- a/src/test/java/org/editorconfig/plugin/maven/config/TreeBuilderTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/config/TreeBuilderTest.java @@ -19,7 +19,7 @@ class TreeBuilderTest { @Test - void testTreeBuilding() throws URISyntaxException { + void buildTree_ValidPath_ValidTreeNode() throws URISyntaxException { // given. File start = new File(ClassLoader.getSystemClassLoader() .getResource("tree-builder/first") diff --git a/src/test/java/org/editorconfig/plugin/maven/config/TreeNodeTest.java b/src/test/java/org/editorconfig/plugin/maven/config/TreeNodeTest.java index 68ed712..bdab449 100644 --- a/src/test/java/org/editorconfig/plugin/maven/config/TreeNodeTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/config/TreeNodeTest.java @@ -7,10 +7,10 @@ import java.nio.file.Paths; import org.assertj.core.api.InstanceOfAssertFactories; +import org.assertj.core.api.SoftAssertions; import org.editorconfig.plugin.maven.model.Editorconfig; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; /** @@ -21,7 +21,7 @@ class TreeNodeTest { @Test - void testSimpleChildInsertion() { + void insertNode_InsertIntoTheRoot_ValidTreeNode() { // given. TreeNode root = buildTestNodeTree(); @@ -29,18 +29,21 @@ void testSimpleChildInsertion() { root.insertNode(new Editorconfig(Paths.get("/root/third/.editorconfig"))); // then. - assertThat(root.getChildren()).hasSize(3); - assertThat(root.getChildren()) - .extracting(treeNode -> - treeNode.getValue().getLocation().toAbsolutePath().toString()) - .containsOnly( - "/root/first/.editorconfig", - "/root/second/.editorconfig", - "/root/third/.editorconfig"); + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(root.getChildren()).hasSize(3); + softAssertions + .assertThat(root.getChildren()) + .extracting(treeNode -> + treeNode.getValue().getLocation().toAbsolutePath().toString()) + .containsOnly( + "/root/first/.editorconfig", + "/root/second/.editorconfig", + "/root/third/.editorconfig"); + }); } @Test - void testInsertionSingleLevelNesting() { + void insertNode_InsertIntoTheLeaf_ValidTreeNode() { // given. TreeNode root = buildTestNodeTree(); @@ -48,33 +51,38 @@ void testInsertionSingleLevelNesting() { root.insertNode(new Editorconfig(Paths.get("/root/second/inner/.editorconfig"))); // then. - assertThat(root.getChildren()).hasSize(2); - assertThat(root.getChildren()) - .filteredOn(treeNode -> treeNode.getValue() - .getLocation() - .toString() - .equals("/root/first/.editorconfig")) - .hasSize(1) - .element(0) - .extracting(TreeNode::getChildren, InstanceOfAssertFactories.list(TreeNode.class)) - .isEmpty(); - - assertThat(root.getChildren()) - .filteredOn(treeNode -> treeNode.getValue() - .getLocation() - .toString() - .equals("/root/second/.editorconfig")) - .hasSize(1) - .element(0) - .extracting(TreeNode::getChildren, InstanceOfAssertFactories.list(TreeNode.class)) - .hasSize(1) - .element(0) - .extracting(treeNode -> treeNode.getValue().getLocation().toString()) - .isEqualTo("/root/second/inner/.editorconfig"); + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(root.getChildren()).hasSize(2); + softAssertions + .assertThat(root.getChildren()) + .filteredOn(treeNode -> treeNode.getValue() + .getLocation() + .toString() + .equals("/root/first/.editorconfig")) + .hasSize(1) + .element(0) + .extracting( + TreeNode::getChildren, InstanceOfAssertFactories.list(TreeNode.class)) + .isEmpty(); + softAssertions + .assertThat(root.getChildren()) + .filteredOn(treeNode -> treeNode.getValue() + .getLocation() + .toString() + .equals("/root/second/.editorconfig")) + .hasSize(1) + .element(0) + .extracting( + TreeNode::getChildren, InstanceOfAssertFactories.list(TreeNode.class)) + .hasSize(1) + .element(0) + .extracting(treeNode -> treeNode.getValue().getLocation().toString()) + .isEqualTo("/root/second/inner/.editorconfig"); + }); } @Test - void testInsertionIntoWrongNodeParent() { + void insertNode_InsertIntoTheInvalidRoot_NodeInsertionException() { // given. TreeNode root = buildTestNodeTree(); diff --git a/src/test/java/org/editorconfig/plugin/maven/glob/GlobExpressionParserTest.java b/src/test/java/org/editorconfig/plugin/maven/glob/GlobExpressionParserTest.java index 31e5dc9..6f9e2ab 100644 --- a/src/test/java/org/editorconfig/plugin/maven/glob/GlobExpressionParserTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/glob/GlobExpressionParserTest.java @@ -8,11 +8,12 @@ import java.util.function.Function; import java.util.stream.Stream; -import org.assertj.core.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Unit tests for {@link GlobExpressionParser} * @@ -22,11 +23,17 @@ class GlobExpressionParserTest { @ParameterizedTest @MethodSource("testAcceptsSource") - void testAccepts(Path target, Path editorconfig, String globPattern, boolean expectedAccepts) { - boolean actualAccepts = new GlobExpressionParser(editorconfig.toFile().getAbsolutePath()) - .accepts(target, globPattern); + void accepts_ListOfCheckedPaths_Ok( + Path target, Path editorconfig, String globPattern, boolean expectedAccepts) { + // given. + GlobExpressionParser globExpressionParser = + new GlobExpressionParser(editorconfig.toFile().getAbsolutePath()); + + // when. + boolean actualAccepts = globExpressionParser.accepts(target, globPattern); - Assertions.assertThat(actualAccepts).isEqualTo(expectedAccepts); + // than. + assertThat(actualAccepts).isEqualTo(expectedAccepts); } static Stream testAcceptsSource() { diff --git a/src/test/java/org/editorconfig/plugin/maven/model/EndOfLineTest.java b/src/test/java/org/editorconfig/plugin/maven/model/EndOfLineTest.java index ed4d4aa..f87179f 100644 --- a/src/test/java/org/editorconfig/plugin/maven/model/EndOfLineTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/model/EndOfLineTest.java @@ -13,13 +13,17 @@ class EndOfLineTest { @ParameterizedTest @EnumSource(value = EndOfLine.class, names = "CARRIAGE_RERUN_LINE_FEED", mode = Mode.EXCLUDE) - void isSingleCharacter_true(EndOfLine source) { + void isSingleCharacter_СrLfEof_True(EndOfLine source) { + + // when/then Assertions.assertThat(source.isSingleCharacter()).isTrue(); } @ParameterizedTest @EnumSource(value = EndOfLine.class, names = "CARRIAGE_RERUN_LINE_FEED", mode = Mode.INCLUDE) - void isSingleCharacter_false(EndOfLine source) { + void isSingleCharacter_Сrlf_False(EndOfLine source) { + + // when/then Assertions.assertThat(source.isSingleCharacter()).isFalse(); } } diff --git a/src/test/java/org/editorconfig/plugin/maven/model/GlobExpressionTest.java b/src/test/java/org/editorconfig/plugin/maven/model/GlobExpressionTest.java index aff5b11..37c1d9d 100644 --- a/src/test/java/org/editorconfig/plugin/maven/model/GlobExpressionTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/model/GlobExpressionTest.java @@ -21,7 +21,9 @@ class GlobExpressionTest { @ParameterizedTest @MethodSource(value = "argumentsStream") - void testFromRawString(String expected, String actual) { + void fromAndGetRaw_ListOfRawStrings_StringValues(String expected, String actual) { + + // when/then assertThat(GlobExpression.from(expected).getRaw()).isEqualTo(actual); } diff --git a/src/test/java/org/editorconfig/plugin/maven/model/OptionTest.java b/src/test/java/org/editorconfig/plugin/maven/model/OptionTest.java index 83e7d4c..11c775d 100644 --- a/src/test/java/org/editorconfig/plugin/maven/model/OptionTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/model/OptionTest.java @@ -4,18 +4,25 @@ */ package org.editorconfig.plugin.maven.model; -import org.assertj.core.api.Assertions; +import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test; class OptionTest { @Test - void testCaseInsensitiveMatch() { - Assertions.assertThat(Option.from(Option.END_OF_LINE.name())) - .isPresent() - .hasValue(Option.END_OF_LINE); - Assertions.assertThat(Option.from(Option.END_OF_LINE.getKey())) - .isPresent() - .hasValue(Option.END_OF_LINE); + void OptionFrom_EndOfLine_ValidNameAndKey() { + + // when/then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions + .assertThat(Option.from(Option.END_OF_LINE.name())) + .isPresent() + .hasValue(Option.END_OF_LINE); + + softAssertions + .assertThat(Option.from(Option.END_OF_LINE.getKey())) + .isPresent() + .hasValue(Option.END_OF_LINE); + }); } } diff --git a/src/test/java/org/editorconfig/plugin/maven/model/OptionValueTest.java b/src/test/java/org/editorconfig/plugin/maven/model/OptionValueTest.java index b1c6e67..5e567e5 100644 --- a/src/test/java/org/editorconfig/plugin/maven/model/OptionValueTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/model/OptionValueTest.java @@ -5,7 +5,7 @@ package org.editorconfig.plugin.maven.model; import org.apache.maven.plugin.MojoExecutionException; -import org.assertj.core.api.Assertions; +import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Test; /** @@ -16,42 +16,55 @@ class OptionValueTest { @Test - void testUnset() { - // given. + void isUnset_OptionValueUnset_True() { + // given OptionValue unset = OptionValue.unset(); - // when/then. - Assertions.assertThat(unset.isUnset()).isTrue(); - Assertions.assertThatThrownBy(unset::getValue).isInstanceOf(MojoExecutionException.class); + // when/then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(unset.isUnset()).isTrue(); + softAssertions + .assertThatThrownBy(unset::getValue) + .isInstanceOf(MojoExecutionException.class); + }); } @Test - void testResolve_null() { - // given. + void resolve_NullSource_NullValue() { + // given OptionValue nullable = OptionValue.resolve(null, IndentationStyle::from); - // when/then. - Assertions.assertThat(nullable.isUnset()).isFalse(); - Assertions.assertThat(nullable.getValue()).isEqualTo(null); + // when/then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(nullable.isUnset()).isFalse(); + + softAssertions.assertThat(nullable.getValue()).isEqualTo(null); + }); } @Test - void testResolve_unparsable() { - // given. + void resolve_UnparsableSource_NullValue() { + // given OptionValue nullable = OptionValue.resolve("hey", IndentationStyle::from); - // when/then. - Assertions.assertThat(nullable.isUnset()).isFalse(); - Assertions.assertThat(nullable.getValue()).isEqualTo(null); + // when/then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(nullable.isUnset()).isFalse(); + + softAssertions.assertThat(nullable.getValue()).isEqualTo(null); + }); } @Test - void testResolve_validValue() { - // given. + void resolve_TabSource_IndentationStyleTAB() { + // given OptionValue nullable = OptionValue.resolve("tab", IndentationStyle::from); - // when/then. - Assertions.assertThat(nullable.isUnset()).isFalse(); - Assertions.assertThat(nullable.getValue()).isEqualTo(IndentationStyle.TAB); + // when/then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(nullable.isUnset()).isFalse(); + + softAssertions.assertThat(nullable.getValue()).isEqualTo(IndentationStyle.TAB); + }); } } diff --git a/src/test/java/org/editorconfig/plugin/maven/parser/EditorconfigParserTest.java b/src/test/java/org/editorconfig/plugin/maven/parser/EditorconfigParserTest.java index d906402..92d1a59 100644 --- a/src/test/java/org/editorconfig/plugin/maven/parser/EditorconfigParserTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/parser/EditorconfigParserTest.java @@ -8,6 +8,7 @@ import java.util.Map; import org.apache.maven.monitor.logging.DefaultLog; +import org.assertj.core.api.SoftAssertions; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.editorconfig.plugin.maven.config.PluginConfiguration; @@ -17,7 +18,6 @@ import org.editorconfig.plugin.maven.model.EndOfLine; import org.editorconfig.plugin.maven.model.IndentationStyle; import org.editorconfig.plugin.maven.model.TrueFalse; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,85 +30,94 @@ */ class EditorconfigParserTest { - @AfterEach @BeforeEach void tearDown() { PluginConfiguration.destroyInstance(); } @Test - void testFileParsing_inStrictMode_happyPath() { - // Given. + void parse_inStrictMode_NoErrorsDuringParsing() { + // Given PluginConfiguration.buildInstance(Map.of(Param.STRICT_MODE, true)); EditorconfigParser editorconfigParser = new EditorconfigParser(); - // When. + // When String path = testClassPathResource("test-files/.root-editorconfig"); - Editorconfig result = editorconfigParser.parse(Paths.get(path)); - - // Then. - assertThat(result.isRoot()).isTrue(); - assertThat(result.getSections()).hasSize(2); - - assertThat(result.getSections().get(0)).satisfies(section -> { - assertThat(section.getGlobExpression().getRaw()).isEqualTo("{file.py,another-file.py}"); - assertThat(section.getIndentationStyle().getValue()).isEqualTo(IndentationStyle.TAB); - assertThat(section.getEndOfLine().getValue()).isEqualTo(EndOfLine.LINE_FEED); - assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); - assertThat(section.getTrimTrailingWhitespace().getValue()).isEqualTo(TrueFalse.TRUE); - assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.FALSE); - assertThat(section.getIndentationSizeAsDigit()).isEqualTo(2); - }); - - assertThat(result.getSections().get(1)).satisfies(section -> { - assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); - assertThat(section.getIndentationStyle().getValue()).isEqualTo(IndentationStyle.SPACE); - assertThat(section.getEndOfLine().getValue()) - .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); - assertThat(section.getTrimTrailingWhitespace().getValue()).isEqualTo(TrueFalse.FALSE); - assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.TRUE); - assertThat(section.getIndentationSizeAsDigit()).isNull(); + Editorconfig actual = editorconfigParser.parse(Paths.get(path)); + + // Then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actual.isRoot()).isTrue(); + softAssertions.assertThat(actual.getSections()).hasSize(2); + softAssertions.assertThat(actual.getSections().get(0)).satisfies(section -> { + assertThat(section.getGlobExpression().getRaw()) + .isEqualTo("{file.py,another-file.py}"); + assertThat(section.getIndentationStyle().getValue()) + .isEqualTo(IndentationStyle.TAB); + assertThat(section.getEndOfLine().getValue()).isEqualTo(EndOfLine.LINE_FEED); + assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + assertThat(section.getTrimTrailingWhitespace().getValue()) + .isEqualTo(TrueFalse.TRUE); + assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.FALSE); + assertThat(section.getIndentationSizeAsDigit()).isEqualTo(2); + }); + softAssertions.assertThat(actual.getSections().get(1)).satisfies(section -> { + assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); + assertThat(section.getIndentationStyle().getValue()) + .isEqualTo(IndentationStyle.SPACE); + assertThat(section.getEndOfLine().getValue()) + .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + assertThat(section.getTrimTrailingWhitespace().getValue()) + .isEqualTo(TrueFalse.FALSE); + assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.TRUE); + assertThat(section.getIndentationSizeAsDigit()).isNull(); + }); }); } @Test - void testFileParsing_inNonStrictMode_happyPath() { - // Given. + void parse_inNonStrictMode_NoErrorsDuringParsing() { + // Given PluginConfiguration.buildInstance(Map.of(Param.STRICT_MODE, false)); EditorconfigParser editorconfigParser = new EditorconfigParser(); - // When. + // When String path = testClassPathResource("test-files/.root-editorconfig"); Editorconfig result = editorconfigParser.parse(Paths.get(path)); - // Then. - assertThat(result.isRoot()).isTrue(); - assertThat(result.getSections()).hasSize(2); - - assertThat(result.getSections().get(0)).satisfies(section -> { - assertThat(section.getGlobExpression().getRaw()).isEqualTo("{file.py,another-file.py}"); - assertThat(section.getIndentationStyle().getValue()).isEqualTo(IndentationStyle.TAB); - assertThat(section.getEndOfLine().getValue()).isEqualTo(EndOfLine.LINE_FEED); - assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); - assertThat(section.getTrimTrailingWhitespace().getValue()).isEqualTo(TrueFalse.TRUE); - assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.FALSE); - }); - - assertThat(result.getSections().get(1)).satisfies(section -> { - assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); - assertThat(section.getIndentationStyle().getValue()).isEqualTo(IndentationStyle.SPACE); - assertThat(section.getEndOfLine().getValue()) - .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); - assertThat(section.getTrimTrailingWhitespace().getValue()).isEqualTo(TrueFalse.FALSE); - assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.TRUE); + // Then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(result.isRoot()).isTrue(); + softAssertions.assertThat(result.getSections()).hasSize(2); + softAssertions.assertThat(result.getSections().get(0)).satisfies(section -> { + assertThat(section.getGlobExpression().getRaw()) + .isEqualTo("{file.py,another-file.py}"); + assertThat(section.getIndentationStyle().getValue()) + .isEqualTo(IndentationStyle.TAB); + assertThat(section.getEndOfLine().getValue()).isEqualTo(EndOfLine.LINE_FEED); + assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + assertThat(section.getTrimTrailingWhitespace().getValue()) + .isEqualTo(TrueFalse.TRUE); + assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.FALSE); + }); + softAssertions.assertThat(result.getSections().get(1)).satisfies(section -> { + assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); + assertThat(section.getIndentationStyle().getValue()) + .isEqualTo(IndentationStyle.SPACE); + assertThat(section.getEndOfLine().getValue()) + .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + assertThat(section.getTrimTrailingWhitespace().getValue()) + .isEqualTo(TrueFalse.FALSE); + assertThat(section.getInsertFinalNewLine().getValue()).isEqualTo(TrueFalse.TRUE); + }); }); } @Test - void testFileParsing_inNonStrictMode_ErrorsDuringParsing() { - // Given. + void parse_inNonStrictMode_ErrorsDuringParsing() { + // Given PluginConfiguration.buildInstance(Map.of( Param.STRICT_MODE, false, @@ -116,24 +125,27 @@ void testFileParsing_inNonStrictMode_ErrorsDuringParsing() { new DefaultLog(new ConsoleLogger(Logger.LEVEL_INFO, "TestLogger")))); EditorconfigParser editorconfigParser = new EditorconfigParser(); - // When. + // When String path = testClassPathResource("test-files/.invalid-editorconfig"); Editorconfig result = editorconfigParser.parse(Paths.get(path)); - // Then. - assertThat(result.isRoot()).isTrue(); - assertThat(result.getSections()).hasSize(2); - assertThat(result.getSections().get(1)).satisfies(section -> { - assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); - assertThat(section.getIndentationStyle().getValue()).isEqualTo(IndentationStyle.SPACE); - assertThat(section.getEndOfLine().getValue()) - .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); - assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + // Then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(result.isRoot()).isTrue(); + softAssertions.assertThat(result.getSections()).hasSize(2); + softAssertions.assertThat(result.getSections().get(1)).satisfies(section -> { + assertThat(section.getGlobExpression().getRaw()).isEqualTo("*.{.kt,.java}"); + assertThat(section.getIndentationStyle().getValue()) + .isEqualTo(IndentationStyle.SPACE); + assertThat(section.getEndOfLine().getValue()) + .isEqualTo(EndOfLine.CARRIAGE_RERUN_LINE_FEED); + assertThat(section.getCharset().getValue()).isEqualTo(Charset.UTF_8); + }); }); } @Test - void testFileParsing_shouldTestJustRootEditorConfig() { + void parse_inNonStrictModeAndEmptySections_NoErrorsDuringParsing() { PluginConfiguration.buildInstance(Map.of(Param.STRICT_MODE, false)); EditorconfigParser editorconfigParser = new EditorconfigParser(); @@ -141,8 +153,10 @@ void testFileParsing_shouldTestJustRootEditorConfig() { Editorconfig parsed = editorconfigParser.parse(Paths.get(path)); - assertThat(parsed.isRoot()).isTrue(); - assertThat(parsed.getSections()).isEmpty(); + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(parsed.isRoot()).isTrue(); + softAssertions.assertThat(parsed.getSections()).isEmpty(); + }); } private static String testClassPathResource(String name) { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionValidationResultTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionValidationResultTest.java index 30b1ea3..e8bbe7b 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionValidationResultTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionValidationResultTest.java @@ -4,7 +4,7 @@ */ package org.editorconfig.plugin.maven.verifiers; -import org.assertj.core.api.Assertions; +import org.assertj.core.api.SoftAssertions; import org.editorconfig.plugin.maven.model.Option; import org.junit.jupiter.api.Test; @@ -16,7 +16,7 @@ class OptionValidationResultTest { @Test - void testViolationCount() { + void addErrorMessage_Violations_ExactViolationsCount() { // given var first = new OptionValidationResult(Option.CHARSET, "utf-8"); var second = new OptionValidationResult(Option.CHARSET, "utf-8"); @@ -25,26 +25,16 @@ void testViolationCount() { second.addErrorMessage("Some error message!"); // then - Assertions.assertThat(first.violationsCount()).isEqualTo(0); - Assertions.assertThat(second.violationsCount()).isEqualTo(1); + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(first.violationsCount()).isEqualTo(0); + softAssertions.assertThat(second.violationsCount()).isEqualTo(1); + softAssertions.assertThat(first.noErrors()).isEqualTo(true); + softAssertions.assertThat(second.noErrors()).isEqualTo(false); + }); } @Test - void testNoErrors() { - // given - var first = new OptionValidationResult(Option.CHARSET, "utf-8"); - var second = new OptionValidationResult(Option.CHARSET, "utf-8"); - - // when - second.addErrorMessage("Some error message!"); - - // then - Assertions.assertThat(first.noErrors()).isEqualTo(true); - Assertions.assertThat(second.noErrors()).isEqualTo(false); - } - - @Test - void testProfileRendering() { + void renderErrorMessage_Violations_ValidErrorMessage() { // given var first = new OptionValidationResult(Option.CHARSET, "utf-8"); first.addErrorMessage("First Error!"); @@ -54,11 +44,14 @@ void testProfileRendering() { String errorMessage = first.renderErrorMessage(); // then - Assertions.assertThat(first.noErrors()).isEqualTo(false); - Assertions.assertThat(first.violationsCount()).isEqualTo(2); - Assertions.assertThat(errorMessage) - .isEqualTo("For option charset=utf-8 found 2 violation(-s):\n" - + "\t- First Error!\n" - + "\t- Second Error!\n"); + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(first.noErrors()).isEqualTo(false); + softAssertions.assertThat(first.violationsCount()).isEqualTo(2); + softAssertions + .assertThat(errorMessage) + .isEqualTo("For option charset=utf-8 found 2 violation(-s):\n" + + "\t- First Error!\n" + + "\t- Second Error!\n"); + }); } } diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionsManagerTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionsManagerTest.java index 7a351e4..3089d71 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionsManagerTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/OptionsManagerTest.java @@ -34,7 +34,7 @@ class OptionsManagerTest { @Test - void testOrderOfVerifiersIsTakenIntoAccount() throws IOException { + void check_InvocationQueue_ExactInvocationOrder() throws IOException { // given. Queue> invocationQueue = new LinkedList<>(); diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifierTest.java index 66d674d..be1e949 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/CharsetOptionVerifierTest.java @@ -13,6 +13,7 @@ import org.editorconfig.plugin.maven.model.OptionValue; import org.editorconfig.plugin.maven.verifiers.OptionValidationResult; import org.editorconfig.plugin.maven.verifiers.VerifiersExecutionContext; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -24,14 +25,19 @@ */ class CharsetOptionVerifierTest { - private final CharsetOptionVerifier subject = new CharsetOptionVerifier(); + private CharsetOptionVerifier subject; + + @BeforeEach + void setUp() { + subject = new CharsetOptionVerifier(); + } @ParameterizedTest @MethodSource(value = {"arguments"}) - void testCharsetOptionVerifier(String sourceCodeFile, String charset, boolean noErrors) - throws Exception { + void check_CharsetOptionVerifier_OptionalValidationResult( + String sourceCodeFile, String charset, boolean expected) throws Exception { - OptionValidationResult check = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(Paths.get(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI()) @@ -40,7 +46,7 @@ void testCharsetOptionVerifier(String sourceCodeFile, String charset, boolean no sectionBuilder.charset(OptionValue.resolve(charset, Charset::from))), new VerifiersExecutionContext()); - Assertions.assertThat(check.noErrors()).isEqualTo(noErrors); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream arguments() { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/EndOfLineOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/EndOfLineOptionVerifierTest.java index bd28c32..27e79fb 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/EndOfLineOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/EndOfLineOptionVerifierTest.java @@ -31,11 +31,12 @@ void setUp() { @ParameterizedTest @MethodSource(value = "arguments") - void testEndOfLineOptionVerifier(String sourceCodeFile, EndOfLine endOfLine, boolean noErrors) + void check_EndOfLineOptionVerifier_OptionalValidationResult( + String sourceCodeFile, EndOfLine endOfLine, boolean expected) throws URISyntaxException, FileNotFoundException { // when. - OptionValidationResult check = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(new File(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI())), @@ -44,7 +45,7 @@ void testEndOfLineOptionVerifier(String sourceCodeFile, EndOfLine endOfLine, boo new VerifiersExecutionContext()); // then. - Assertions.assertThat(check.noErrors()).isEqualTo(noErrors); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream arguments() { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationSizeOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationSizeOptionVerifierTest.java index 5cd501d..7039f31 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationSizeOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationSizeOptionVerifierTest.java @@ -15,20 +15,26 @@ import org.editorconfig.plugin.maven.utils.IntegerUtils; import org.editorconfig.plugin.maven.verifiers.OptionValidationResult; import org.editorconfig.plugin.maven.verifiers.VerifiersExecutionContext; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; class IndentationSizeOptionVerifierTest { - private final IndentationSizeOptionVerifier subject = new IndentationSizeOptionVerifier(); + private IndentationSizeOptionVerifier subject; + + @BeforeEach + void setUp() { + subject = new IndentationSizeOptionVerifier(); + } @ParameterizedTest @MethodSource(value = "source") - void testIndentationSizeOptionVerifier( - String sourceCodeFile, Integer tabWidth, Integer indentSize, boolean checkShouldPass) + void check_IndentationSizeOptionVerifier_OptionalValidationResult( + String sourceCodeFile, Integer tabWidth, Integer indentSize, boolean expected) throws URISyntaxException, FileNotFoundException { - OptionValidationResult result = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(new File(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI())), @@ -37,7 +43,7 @@ void testIndentationSizeOptionVerifier( .indentationSize(OptionValue.resolve( indentSize.toString(), IntegerUtils::parseIntSafe))), new VerifiersExecutionContext()); - Assertions.assertThat(result.noErrors()).isEqualTo(checkShouldPass); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream source() { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationStyleOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationStyleOptionVerifierTest.java index 93deaf0..fe2dd40 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationStyleOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/IndentationStyleOptionVerifierTest.java @@ -14,6 +14,7 @@ import org.editorconfig.plugin.maven.utils.IntegerUtils; import org.editorconfig.plugin.maven.verifiers.OptionValidationResult; import org.editorconfig.plugin.maven.verifiers.VerifiersExecutionContext; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -25,17 +26,22 @@ */ class IndentationStyleOptionVerifierTest { - private final IndentationStyleOptionVerifier subject = new IndentationStyleOptionVerifier(); + private IndentationStyleOptionVerifier subject; + + @BeforeEach + void setUp() { + subject = new IndentationStyleOptionVerifier(); + } @ParameterizedTest @MethodSource(value = {"arguments"}) - void testIndentationStyleOptionVerifier( + void check_IndentationStyleOptionVerifier_OptionalValidationResult( String sourceCodeFile, IndentationStyle indentationStyle, Integer tabWidth, - boolean noErrors) + boolean expected) throws Exception { - OptionValidationResult check = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(Paths.get(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI()) @@ -47,7 +53,7 @@ void testIndentationStyleOptionVerifier( indentationStyle.name(), IndentationStyle::from))), new VerifiersExecutionContext()); - Assertions.assertThat(check.noErrors()).isEqualTo(noErrors); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream arguments() { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/InsertFinalNewLineOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/InsertFinalNewLineOptionVerifierTest.java index b419749..dbec22b 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/InsertFinalNewLineOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/InsertFinalNewLineOptionVerifierTest.java @@ -36,10 +36,11 @@ void setUp() { @ParameterizedTest @MethodSource(value = "arguments") - void testInsertFinalNewLineOptionVerifier(String sourceCodeFile, boolean shouldPass) + void check_InsertFinalNewLineOptionVerifier_OptionalValidationResult( + String sourceCodeFile, boolean expected) throws URISyntaxException, FileNotFoundException { // given. - OptionValidationResult sut = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(new File(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI())), @@ -48,7 +49,7 @@ void testInsertFinalNewLineOptionVerifier(String sourceCodeFile, boolean shouldP new VerifiersExecutionContext()); // when - Assertions.assertThat(sut.noErrors()).isEqualTo(shouldPass); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream arguments() { diff --git a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/TrimTrailingWhitespaceOptionVerifierTest.java b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/TrimTrailingWhitespaceOptionVerifierTest.java index 6b548d6..0e7ab05 100644 --- a/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/TrimTrailingWhitespaceOptionVerifierTest.java +++ b/src/test/java/org/editorconfig/plugin/maven/verifiers/impl/TrimTrailingWhitespaceOptionVerifierTest.java @@ -39,10 +39,11 @@ void setUp() { @ParameterizedTest @MethodSource(value = "arguments") - void testInsertFinalNewLineOptionVerifier(String sourceCodeFile, boolean shouldPass) + void check_TrimTrailingWhitespaceOptionVerifier_OptionalValidationResult( + String sourceCodeFile, boolean expected) throws URISyntaxException, FileNotFoundException { // given. - OptionValidationResult sut = subject.check( + OptionValidationResult actual = subject.check( new CachingInputStream(new File(ClassLoader.getSystemClassLoader() .getResource(sourceCodeFile) .toURI())), @@ -53,7 +54,7 @@ void testInsertFinalNewLineOptionVerifier(String sourceCodeFile, boolean shouldP .putGlobal(ContextKeys.POSSIBLE_CHARSETS, List.of(Charset.UTF_8))); // when - Assertions.assertThat(sut.noErrors()).isEqualTo(shouldPass); + Assertions.assertThat(actual.noErrors()).isEqualTo(expected); } static Stream arguments() {