Skip to content

Commit

Permalink
Add tests for JsonParsingException for JsonSource
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed Aug 27, 2018
1 parent 72fa3f6 commit 205b9a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class JsonArgumentsProvider implements AnnotationConsumer<JsonSource>, Ar
private String value;

@Override
public void accept(JsonSource jsonFileSource) {
value = jsonFileSource.value();
public void accept(JsonSource jsonSource) {
value = jsonSource.value();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.json.stream.JsonParsingException;
import java.lang.annotation.Annotation;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.*;

class JsonArgumentsProviderTest {

Expand Down Expand Up @@ -72,4 +73,25 @@ void arrayOfStrings(JsonString string) {
void simplifiedJson(JsonObject object) {
assertThat(object.getString("key")).isEqualTo("value");
}

@DisplayName("handles invalid json")
@Test
void invalidJson() {
JsonSource invalidJsonSource = new JsonSource() {
@Override
public Class<? extends Annotation> annotationType() {
return JsonSource.class;
}

@Override
public String value() {
return "notJson";
}
};
JsonArgumentsProvider args = new JsonArgumentsProvider();
args.accept(invalidJsonSource);

assertThatExceptionOfType(JsonParsingException.class)
.isThrownBy(() -> args.provideArguments(null));
}
}

0 comments on commit 205b9a8

Please sign in to comment.