From c85924874162a1d246822e9e8e62d3e34faf7ac0 Mon Sep 17 00:00:00 2001 From: amihaiemil Date: Sat, 29 Oct 2022 16:48:17 +0300 Subject: [PATCH] #517 checkstyle fixes --- .rultor.yml | 2 +- .../java/com/amihaiemil/eoyaml/ReadYamlMapping.java | 7 ++++++- .../com/amihaiemil/eoyaml/ReadYamlMappingTest.java | 8 +++++++- .../com/amihaiemil/eoyaml/ReadYamlSequenceTest.java | 13 +++++++++++-- .../java/com/amihaiemil/eoyaml/RtYamlInputTest.java | 10 ++++++++-- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.rultor.yml b/.rultor.yml index 82c274a3..8fc43ac8 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -6,7 +6,7 @@ env: MAVEN_OPTS: "-XX:MaxPermSize=256m -Xmx1g" merge: script: |- - mvn clean install -Pcheckstyle + mvn clean install -Pcheckstyle,itcases #decrypt: # settings.xml: "repo/rcfg/settings.xml.asc" # pubring.gpg: "repo/rcfg/pubring.gpg.asc" diff --git a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java index a9f8f68e..7af9515a 100644 --- a/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java +++ b/src/main/java/com/amihaiemil/eoyaml/ReadYamlMapping.java @@ -48,7 +48,12 @@ */ final class ReadYamlMapping extends BaseYamlMapping { - private static final Pattern KEY_PATTERN = Pattern.compile("^-?\\s*(?.+):(|\\s.*)$"); + /** + * Regex for a key in a mapping. + */ + private static final Pattern KEY_PATTERN = Pattern.compile( + "^-?\\s*(?.+):(|\\s.*)$" + ); /** * Yaml line just previous to the one where this mapping starts. E.g. diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java index 9660d5e1..e80696af 100644 --- a/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java +++ b/src/test/java/com/amihaiemil/eoyaml/ReadYamlMappingTest.java @@ -1171,6 +1171,9 @@ public void shouldReadFromAnotherFromYamlMapping() .equalTo("Some other value.")); } + /** + * Reads mapping key properly if value has colon. + */ @Test public void shouldReadKeyProperlyIfValueContainsColon() { final List lines = new ArrayList<>(); @@ -1178,6 +1181,9 @@ public void shouldReadKeyProperlyIfValueContainsColon() { ReadYamlMapping mapping = new ReadYamlMapping(new AllYamlLines(lines)); MatcherAssert.assertThat(mapping.keys(), Matchers.hasSize(1)); - MatcherAssert.assertThat(mapping.keys().iterator().next().asScalar().value(), Matchers.equalTo("key")); + MatcherAssert.assertThat( + mapping.keys().iterator().next().asScalar().value(), + Matchers.equalTo("key") + ); } } diff --git a/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java b/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java index e5511d78..ff81f45c 100644 --- a/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java +++ b/src/test/java/com/amihaiemil/eoyaml/ReadYamlSequenceTest.java @@ -485,6 +485,9 @@ public void printsEmptyYaml() throws Exception { MatcherAssert.assertThat(sequence.toString(), Matchers.isEmptyString()); } + /** + * Reads scalar containing colon properly. + */ @Test public void dontReturnMappingForScalarWithColon() { final List lines = new ArrayList<>(); @@ -495,7 +498,13 @@ public void dontReturnMappingForScalarWithColon() { MatcherAssert.assertThat(sequence.values(), Matchers.hasSize(1)); YamlNode sequenceItem = sequence.values().iterator().next(); - MatcherAssert.assertThat(sequenceItem.type(), Matchers.equalTo(Node.SCALAR)); - MatcherAssert.assertThat(sequenceItem.asScalar().value(), Matchers.equalTo("scalar:with-colon")); + MatcherAssert.assertThat( + sequenceItem.type(), + Matchers.equalTo(Node.SCALAR) + ); + MatcherAssert.assertThat( + sequenceItem.asScalar().value(), + Matchers.equalTo("scalar:with-colon") + ); } } diff --git a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java index c026ec70..36a86bed 100644 --- a/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java +++ b/src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java @@ -981,6 +981,10 @@ public void supportsSpringPropertyRef() throws IOException { MatcherAssert.assertThat(pretty, Matchers.equalTo(fileContents)); } + /** + * Unit test for issue 517. + * @throws IOException If something goes wrong. + */ @Test public void shouldReadKeysProperly() throws IOException { final String filename = "issue_517_values_with_colons.yml"; @@ -1002,7 +1006,8 @@ public void shouldReadKeysProperly() throws IOException { topLevelMapping.asMapping().value("a_scalar").type(), Matchers.equalTo(Node.SCALAR)); MatcherAssert.assertThat( - topLevelMapping.asMapping().value("a_scalar").asScalar().value(), + topLevelMapping.asMapping().value("a_scalar") + .asScalar().value(), Matchers.equalTo("value:with-colon")); YamlNode topLevelSequence = read.asMapping().value("a_sequence"); @@ -1011,7 +1016,8 @@ public void shouldReadKeysProperly() throws IOException { Matchers.equalTo(Node.SEQUENCE)); MatcherAssert.assertThat(topLevelSequence.asSequence().values(), Matchers.hasSize(1)); - YamlNode sequenceItem = topLevelSequence.asSequence().values().iterator().next(); + YamlNode sequenceItem = topLevelSequence.asSequence().values() + .iterator().next(); MatcherAssert.assertThat(sequenceItem.type(), Matchers.equalTo(Node.SCALAR)); MatcherAssert.assertThat(sequenceItem.asScalar().value(),