Skip to content

Commit

Permalink
add tests for optional single value json
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidd committed Jun 23, 2015
1 parent 0ff0b7d commit 60561c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Json parser unit tests.
Expand Down Expand Up @@ -216,7 +217,7 @@ public void testOptionalParser() {
assertFalse(result.nullString.isPresent());
assertFalse(result.absentString.isPresent());
result.valueString.ifPresent((value) ->
assertEquals("string with value", value)
assertEquals("string with value", value)
);
List<Optional<Integer>> expected = new LinkedList<>();
expected.add(Optional.of(1));
Expand All @@ -227,6 +228,19 @@ public void testOptionalParser() {
assertEquals(expected, result.maybeInts);
}


@Test
public void testOptionalSingleValue() {
JsonParser<Optional<Integer>> parser = new JsonParser<>(new TypeToken<Optional<Integer>>(){});
InputStream nullValue = this.getClass()
.getResourceAsStream("/single_null_value.json");
assertFalse(parser.parse(nullValue).isPresent());

InputStream intValue = this.getClass()
.getResourceAsStream("/single_int_value.json");
assertEquals(new Integer(123), parser.parse(intValue).get());
}

@Test
public void testSaltStackJobsWithArgsAsKwargsParser() throws Exception {
InputStream is = this.getClass()
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/single_int_value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
1 change: 1 addition & 0 deletions src/test/resources/single_null_value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null

0 comments on commit 60561c8

Please sign in to comment.