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