Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Dec 1, 2018
1 parent 92b5d9e commit 5958e13
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/co/comdor/github/ComdorYamlInputTestCase.java
Expand Up @@ -62,6 +62,27 @@ public void readsArchitects() throws IOException {
);
}

/**
* ComdorYamlInput can read the labels list.
* @throws IOException If something goes wrong.
*/
@Test
public void readsLabels() throws IOException {
final ComdorYaml comdor = new ComdorYamlInput(
new ByteArrayInputStream(
"docker: c/d\nlabels:\n - 0.0.1\n - 0.0.2".getBytes()
)
);
final List<String> labels = comdor.labels();
MatcherAssert.assertThat(labels, Matchers.hasSize(2));
MatcherAssert.assertThat(
labels.get(0), Matchers.equalTo("0.0.1")
);
MatcherAssert.assertThat(
labels.get(1), Matchers.equalTo("0.0.2")
);
}

/**
* ComdorYamlInput can tag the architects.
* @throws IOException If something goes wrong.
Expand Down Expand Up @@ -142,4 +163,21 @@ public void missingArchitects() throws IOException {
comdor.architects(), Matchers.iterableWithSize(0)
);
}

/**
* The labels' list is missing, so ComdorYamlInput returns an
* empty list.
* @throws IOException If something goes wrong.
*/
@Test
public void missingLabels() throws IOException {
final ComdorYaml comdor = new ComdorYamlInput(
new ByteArrayInputStream(
"docker: a/b".getBytes()
)
);
MatcherAssert.assertThat(
comdor.labels(), Matchers.iterableWithSize(0)
);
}
}
25 changes: 25 additions & 0 deletions src/test/java/co/comdor/github/ComdorYamlRulesTestCase.java
Expand Up @@ -142,4 +142,29 @@ public void returnsReadCommanders() {
MatcherAssert.assertThat(cmd2, Matchers.iterableWithSize(2));
MatcherAssert.assertThat(cmd2, Matchers.contains("amihaiemil", "joe"));
}

/**
* Doesn't touch the labels' list. It returns it "as is".
*/
@Test
public void returnsReadLabels() {
final ComdorYaml read = Mockito.mock(ComdorYaml.class);
Mockito.when(read.labels())
.thenReturn(new ArrayList<>())
.thenReturn(Arrays.asList(new String[]{"0.0.1"}))
.thenReturn(Arrays.asList(new String[]{"0.0.1", "0.0.2"}));

MatcherAssert.assertThat(
new ComdorYamlRules(read).labels(),
Matchers.iterableWithSize(0)
);

final List<String> arch1 = new ComdorYamlRules(read).labels();
MatcherAssert.assertThat(arch1, Matchers.iterableWithSize(1));
MatcherAssert.assertThat(arch1, Matchers.contains("0.0.1"));

final List<String> arch2 = new ComdorYamlRules(read).labels();
MatcherAssert.assertThat(arch2, Matchers.iterableWithSize(2));
MatcherAssert.assertThat(arch2, Matchers.contains("0.0.1", "0.0.2"));
}
}

1 comment on commit 5958e13

@0pdd
Copy link

@0pdd 0pdd commented on 5958e13 Dec 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 105g-990a03f3 discovered in src/main/java/co/comdor/github/CreateLabels.java and submitted as #107. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.