Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ComdorYamlInput, Mention.comdorYaml() and unit tests
- Loading branch information
1 parent
584fcbf
commit ee8187c
Showing
6 changed files
with
289 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package co.comdor.github; | ||
|
||
import com.amihaiemil.camel.Yaml; | ||
import com.amihaiemil.camel.YamlMapping; | ||
import com.amihaiemil.camel.YamlSequence; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* CcmdorYaml from InputStream. | ||
* @author Mihai Andronache (amihaiemil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.2 | ||
*/ | ||
public final class ComdorYamlInput implements ComdorYaml { | ||
|
||
/** | ||
* Contents of .comdor.yml. | ||
*/ | ||
private final YamlMapping yaml; | ||
|
||
/** | ||
* Ctor. | ||
* @param yaml .charles.yml. | ||
* @throws IOException If the input stream cannot be read. | ||
*/ | ||
public ComdorYamlInput(final InputStream yaml) throws IOException { | ||
this.yaml = Yaml.createYamlInput(yaml).readYamlMapping(); | ||
} | ||
|
||
@Override | ||
public String docker() { | ||
return this.yaml.string("docker"); | ||
} | ||
|
||
@Override | ||
public List<String> architects() { | ||
final List<String> architects = new ArrayList<>(); | ||
final YamlSequence sequence = this.yaml.yamlSequence("architects"); | ||
if(sequence != null) { | ||
for(int idx=0; idx<sequence.size(); idx = idx + 1) { | ||
architects.add(sequence.string(idx)); | ||
} | ||
} | ||
return architects; | ||
} | ||
|
||
@Override | ||
public List<String> commanders() { | ||
final List<String> commanders = new ArrayList<>(); | ||
final YamlSequence sequence = this.yaml.yamlSequence("commanders"); | ||
if(sequence != null) { | ||
for(int idx=0; idx<sequence.size(); idx = idx + 1) { | ||
commanders.add(sequence.string(idx)); | ||
} | ||
} | ||
return commanders; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/test/java/co/comdor/github/ComdorYamlInputTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package co.comdor.github; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link ComdorYamlInput}. | ||
* @author Mihai Andronache (amihaiemil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.2 | ||
*/ | ||
public final class ComdorYamlInputTestCase { | ||
|
||
/** | ||
* ComdorYamlInput can read the commanders list. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void readsCommanders() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"docker: a/b\ncommanders:\n - john\n - amihaiemil".getBytes() | ||
) | ||
); | ||
final List<String> commanders = comdor.commanders(); | ||
MatcherAssert.assertThat(commanders, Matchers.hasSize(2)); | ||
MatcherAssert.assertThat( | ||
commanders.get(0), Matchers.equalTo("amihaiemil") | ||
); | ||
MatcherAssert.assertThat( | ||
commanders.get(1), Matchers.equalTo("john") | ||
); | ||
} | ||
|
||
/** | ||
* ComdorYamlInput can read the architects list. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void readsArchitects() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"docker: c/d\narchitects:\n - john\n - amihaiemil".getBytes() | ||
) | ||
); | ||
final List<String> architects = comdor.architects(); | ||
MatcherAssert.assertThat(architects, Matchers.hasSize(2)); | ||
MatcherAssert.assertThat( | ||
architects.get(0), Matchers.equalTo("amihaiemil") | ||
); | ||
MatcherAssert.assertThat( | ||
architects.get(1), Matchers.equalTo("john") | ||
); | ||
} | ||
|
||
/** | ||
* Reads the docker attribute. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void readsDocker() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"docker: amihaiemil/java9".getBytes() | ||
) | ||
); | ||
MatcherAssert.assertThat( | ||
comdor.docker(), Matchers.equalTo("amihaiemil/java9") | ||
); | ||
} | ||
|
||
/** | ||
* Docker attribute is missing, so ComdorYamlInput returns null. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void missingDocker() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"commanders:\n - somone".getBytes() | ||
) | ||
); | ||
MatcherAssert.assertThat( | ||
comdor.docker(), Matchers.equalTo(null) | ||
); | ||
} | ||
|
||
/** | ||
* The commanders' list is missing, so ComdorYamlInput returns an | ||
* empty list. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void missingCommanders() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"architects:\n - somone".getBytes() | ||
) | ||
); | ||
MatcherAssert.assertThat( | ||
comdor.commanders(), Matchers.iterableWithSize(0) | ||
); | ||
} | ||
|
||
/** | ||
* The architects' list is missing, so ComdorYamlInput returns an | ||
* empty list. | ||
* @throws IOException If something goes wrong. | ||
*/ | ||
@Test | ||
public void missingArchitects() throws IOException { | ||
final ComdorYaml comdor = new ComdorYamlInput( | ||
new ByteArrayInputStream( | ||
"docker: a/b".getBytes() | ||
) | ||
); | ||
MatcherAssert.assertThat( | ||
comdor.architects(), Matchers.iterableWithSize(0) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ee8187c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
27-316a9c24
disappeared fromsrc/main/java/co/comdor/github/ComdorYaml.java
, that's why I closed #32.