Skip to content

Commit 2e3ee98

Browse files
committed
tests and fixes
1 parent 4d1d184 commit 2e3ee98

File tree

8 files changed

+262
-8
lines changed

8 files changed

+262
-8
lines changed

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
Maximum number of lines in any .java file is limited.
5050
-->
5151
<module name="FileLength">
52-
<property name="max" value="2000"/>
52+
<property name="max" value="4000"/>
5353
<property name="fileExtensions" value="java"/>
5454
</module>
5555

src/main/java/com/amihaiemil/eoyaml/ReadFlowMapping.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ final class ReadFlowMapping extends BaseYamlMapping {
9797
*/
9898
ReadFlowMapping(final YamlLine folded) {
9999
this.entries = new StringEntries(folded);
100-
System.out.println("FLOW LINE: " + folded.value());
101100
this.folded = folded;
102101
}
103102

src/main/java/com/amihaiemil/eoyaml/RtYamlInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public YamlMapping readYamlMapping() throws IOException {
6969
).iterator();
7070
final YamlMapping read;
7171
if(iterator.hasNext()) {
72-
if ("{".equals(iterator.next().trimmed())) {
72+
if (iterator.next().trimmed().startsWith("{")) {
7373
read = new ReadFlowMapping(all);
7474
} else {
7575
read = new ReadYamlMapping(all);
@@ -93,7 +93,7 @@ public YamlSequence readYamlSequence() throws IOException {
9393
).iterator();
9494
final YamlSequence read;
9595
if(iterator.hasNext()) {
96-
if ("[".equals(iterator.next().trimmed())) {
96+
if (iterator.next().trimmed().startsWith("[")) {
9797
read = new ReadFlowSequence(all);
9898
} else {
9999
read = new ReadYamlSequence(all);

src/test/java/com/amihaiemil/eoyaml/RtYamlInputTest.java

Lines changed: 237 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.junit.Test;
3636

3737
import java.io.File;
38-
import java.io.FileInputStream;
3938
import java.io.FileNotFoundException;
4039
import java.io.IOException;
4140
import java.nio.file.Files;
@@ -1844,6 +1843,240 @@ public void shouldReadListOfMapProperly()
18441843
);
18451844
}
18461845

1846+
/**
1847+
* We should be able to read a file containing only a flow mapping.
1848+
* @throws IOException If something is wrong.
1849+
*/
1850+
@Test
1851+
public void readsFlowMapping() throws IOException {
1852+
final String filename = "flowMapping.yml";
1853+
final YamlMapping mapping = new RtYamlInput(
1854+
Files.newBufferedReader(Paths.get("src/test/resources/" + filename))
1855+
).readYamlMapping();
1856+
System.out.println(mapping);
1857+
MatcherAssert.assertThat(
1858+
mapping.keys().size(), Matchers.equalTo(4)
1859+
);
1860+
MatcherAssert.assertThat(
1861+
mapping.values().size(), Matchers.equalTo(4)
1862+
);
1863+
MatcherAssert.assertThat(
1864+
mapping.string("name"), Matchers.equalTo("eo-yaml")
1865+
);
1866+
MatcherAssert.assertThat(
1867+
mapping.string("architect"), Matchers.equalTo("amihaiemil")
1868+
);
1869+
MatcherAssert.assertThat(
1870+
mapping.yamlSequence("developers").string(0),
1871+
Matchers.equalTo("amihaiemil")
1872+
);
1873+
MatcherAssert.assertThat(
1874+
mapping.yamlSequence("developers").string(1),
1875+
Matchers.equalTo("sherif")
1876+
);
1877+
MatcherAssert.assertThat(
1878+
mapping.yamlSequence("developers").string(2),
1879+
Matchers.equalTo("rultor")
1880+
);
1881+
MatcherAssert.assertThat(
1882+
mapping.yamlMapping("tools").string("devops"),
1883+
Matchers.equalTo("rultor")
1884+
);
1885+
MatcherAssert.assertThat(
1886+
mapping.yamlMapping("tools").string("pm"),
1887+
Matchers.equalTo("self-xdsd")
1888+
);
1889+
}
1890+
1891+
/**
1892+
* We should be able to read a file containing only a flow mapping
1893+
* on one line.
1894+
* @throws IOException If something is wrong.
1895+
*/
1896+
@Test
1897+
public void readsFlowMappingOneLine() throws IOException {
1898+
final String filename = "flowMapping_one_line.yml";
1899+
final YamlMapping mapping = new RtYamlInput(
1900+
Files.newBufferedReader(Paths.get("src/test/resources/" + filename))
1901+
).readYamlMapping();
1902+
System.out.println(mapping);
1903+
MatcherAssert.assertThat(
1904+
mapping.keys().size(), Matchers.equalTo(4)
1905+
);
1906+
MatcherAssert.assertThat(
1907+
mapping.values().size(), Matchers.equalTo(4)
1908+
);
1909+
MatcherAssert.assertThat(
1910+
mapping.string("name"), Matchers.equalTo("eo-yaml")
1911+
);
1912+
MatcherAssert.assertThat(
1913+
mapping.string("architect"), Matchers.equalTo("amihaiemil")
1914+
);
1915+
MatcherAssert.assertThat(
1916+
mapping.yamlSequence("developers").string(0),
1917+
Matchers.equalTo("amihaiemil")
1918+
);
1919+
MatcherAssert.assertThat(
1920+
mapping.yamlSequence("developers").string(1),
1921+
Matchers.equalTo("sherif")
1922+
);
1923+
MatcherAssert.assertThat(
1924+
mapping.yamlSequence("developers").string(2),
1925+
Matchers.equalTo("rultor")
1926+
);
1927+
MatcherAssert.assertThat(
1928+
mapping.yamlMapping("tools").string("devops"),
1929+
Matchers.equalTo("rultor")
1930+
);
1931+
MatcherAssert.assertThat(
1932+
mapping.yamlMapping("tools").string("pm"),
1933+
Matchers.equalTo("self-xdsd")
1934+
);
1935+
}
1936+
1937+
/**
1938+
* We should be able to read a file containing only a flow sequence.
1939+
* @throws IOException If something is wrong.
1940+
*/
1941+
@Test
1942+
public void readsFlowSequence() throws IOException {
1943+
final String filename = "flowSequence.yml";
1944+
final YamlSequence sequence = new RtYamlInput(
1945+
Files.newBufferedReader(Paths.get("src/test/resources/" + filename))
1946+
).readYamlSequence();
1947+
System.out.println(sequence);
1948+
final YamlMapping first = sequence.yamlMapping(0);
1949+
MatcherAssert.assertThat(
1950+
first.keys().size(), Matchers.equalTo(4)
1951+
);
1952+
MatcherAssert.assertThat(
1953+
first.values().size(), Matchers.equalTo(4)
1954+
);
1955+
MatcherAssert.assertThat(
1956+
first.string("name"), Matchers.equalTo("eo-yaml")
1957+
);
1958+
MatcherAssert.assertThat(
1959+
first.string("architect"), Matchers.equalTo("amihaiemil")
1960+
);
1961+
MatcherAssert.assertThat(
1962+
first.yamlSequence("developers").string(0),
1963+
Matchers.equalTo("amihaiemil")
1964+
);
1965+
MatcherAssert.assertThat(
1966+
first.yamlSequence("developers").string(1),
1967+
Matchers.equalTo("sherif")
1968+
);
1969+
MatcherAssert.assertThat(
1970+
first.yamlSequence("developers").string(2),
1971+
Matchers.equalTo("rultor")
1972+
);
1973+
MatcherAssert.assertThat(
1974+
first.yamlMapping("tools").string("devops"),
1975+
Matchers.equalTo("rultor")
1976+
);
1977+
MatcherAssert.assertThat(
1978+
first.yamlMapping("tools").string("pm"),
1979+
Matchers.equalTo("self-xdsd")
1980+
);
1981+
final YamlMapping second = sequence.yamlMapping(1);
1982+
MatcherAssert.assertThat(
1983+
second.keys().size(), Matchers.equalTo(4)
1984+
);
1985+
MatcherAssert.assertThat(
1986+
second.values().size(), Matchers.equalTo(4)
1987+
);
1988+
MatcherAssert.assertThat(
1989+
second.string("name"), Matchers.equalTo("queenlang")
1990+
);
1991+
MatcherAssert.assertThat(
1992+
second.string("architect"), Matchers.equalTo("amihaiemil")
1993+
);
1994+
MatcherAssert.assertThat(
1995+
second.yamlSequence("developers").string(0),
1996+
Matchers.equalTo("amihaiemil")
1997+
);
1998+
MatcherAssert.assertThat(
1999+
second.yamlMapping("tools").string("devops"),
2000+
Matchers.equalTo("rultor")
2001+
);
2002+
MatcherAssert.assertThat(
2003+
second.yamlMapping("tools").string("pm"),
2004+
Matchers.equalTo("self-xdsd")
2005+
);
2006+
}
2007+
2008+
/**
2009+
* We should be able to read a file containing only a flow sequence on one
2010+
* line.
2011+
* @throws IOException If something is wrong.
2012+
*/
2013+
@Test
2014+
public void readsFlowSequenceOneLine() throws IOException {
2015+
final String filename = "flowSequence_one_line.yml";
2016+
final YamlSequence sequence = new RtYamlInput(
2017+
Files.newBufferedReader(Paths.get("src/test/resources/" + filename))
2018+
).readYamlSequence();
2019+
System.out.println(sequence);
2020+
final YamlMapping first = sequence.yamlMapping(0);
2021+
MatcherAssert.assertThat(
2022+
first.keys().size(), Matchers.equalTo(4)
2023+
);
2024+
MatcherAssert.assertThat(
2025+
first.values().size(), Matchers.equalTo(4)
2026+
);
2027+
MatcherAssert.assertThat(
2028+
first.string("name"), Matchers.equalTo("eo-yaml")
2029+
);
2030+
MatcherAssert.assertThat(
2031+
first.string("architect"), Matchers.equalTo("amihaiemil")
2032+
);
2033+
MatcherAssert.assertThat(
2034+
first.yamlSequence("developers").string(0),
2035+
Matchers.equalTo("amihaiemil")
2036+
);
2037+
MatcherAssert.assertThat(
2038+
first.yamlSequence("developers").string(1),
2039+
Matchers.equalTo("sherif")
2040+
);
2041+
MatcherAssert.assertThat(
2042+
first.yamlSequence("developers").string(2),
2043+
Matchers.equalTo("rultor")
2044+
);
2045+
MatcherAssert.assertThat(
2046+
first.yamlMapping("tools").string("devops"),
2047+
Matchers.equalTo("rultor")
2048+
);
2049+
MatcherAssert.assertThat(
2050+
first.yamlMapping("tools").string("pm"),
2051+
Matchers.equalTo("self-xdsd")
2052+
);
2053+
final YamlMapping second = sequence.yamlMapping(1);
2054+
MatcherAssert.assertThat(
2055+
second.keys().size(), Matchers.equalTo(4)
2056+
);
2057+
MatcherAssert.assertThat(
2058+
second.values().size(), Matchers.equalTo(4)
2059+
);
2060+
MatcherAssert.assertThat(
2061+
second.string("name"), Matchers.equalTo("queenlang")
2062+
);
2063+
MatcherAssert.assertThat(
2064+
second.string("architect"), Matchers.equalTo("amihaiemil")
2065+
);
2066+
MatcherAssert.assertThat(
2067+
second.yamlSequence("developers").string(0),
2068+
Matchers.equalTo("amihaiemil")
2069+
);
2070+
MatcherAssert.assertThat(
2071+
second.yamlMapping("tools").string("devops"),
2072+
Matchers.equalTo("rultor")
2073+
);
2074+
MatcherAssert.assertThat(
2075+
second.yamlMapping("tools").string("pm"),
2076+
Matchers.equalTo("self-xdsd")
2077+
);
2078+
}
2079+
18472080
/**
18482081
* Read a test resource file's contents.
18492082
* @param fileName File to read.
@@ -1852,11 +2085,11 @@ public void shouldReadListOfMapProperly()
18522085
* @throws IOException If something is wrong.
18532086
*/
18542087
private String readTestResource(final String fileName)
1855-
throws FileNotFoundException, IOException {
2088+
throws IOException {
18562089
return new String(
18572090
IOUtils.toByteArray(
1858-
new FileInputStream(
1859-
new File("src/test/resources/" + fileName)
2091+
Files.newInputStream(
2092+
new File("src/test/resources/" + fileName).toPath()
18602093
)
18612094
)
18622095
);

src/test/resources/flowMapping.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
name: eo-yaml,
3+
architect: amihaiemil,
4+
developers: [amihaiemil, sherif, rultor],
5+
tools: {devops: rultor, pm: self-xdsd}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{name: eo-yaml,architect: amihaiemil,developers: [amihaiemil, sherif, rultor],tools: {devops: rultor, pm: self-xdsd}}

src/test/resources/flowSequence.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
name: eo-yaml,
4+
architect: amihaiemil,
5+
developers: [ amihaiemil, sherif, rultor ],
6+
tools: { devops: rultor, pm: self-xdsd }
7+
},
8+
{
9+
name: queenlang,
10+
architect: amihaiemil,
11+
developers: [ amihaiemil],
12+
tools: { devops: rultor, pm: self-xdsd }
13+
},
14+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{name: eo-yaml,architect: amihaiemil,developers: [ amihaiemil, sherif, rultor ],tools: { devops: rultor, pm: self-xdsd }},{name: queenlang,architect: amihaiemil,developers: [ amihaiemil], tools: { devops: rultor, pm: self-xdsd }},]

0 commit comments

Comments
 (0)