|
@@ -5,8 +5,6 @@ import static org.leumasjaffe.json.schema.matcher.Accepts.accepts;
|
|
|
import static org.leumasjaffe.json.schema.matcher.AcceptedTypes.acceptsTypes;
|
|
import static org.leumasjaffe.json.schema.matcher.AcceptedTypes.acceptsTypes;
|
|
|
import static org.leumasjaffe.json.schema.matcher.Not.not;
|
|
import static org.leumasjaffe.json.schema.matcher.Not.not;
|
|
|
|
|
|
|
|
-import java.util.function.IntPredicate;
|
|
|
|
|
-
|
|
|
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.ARRAY;
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.ARRAY;
|
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.OBJECT;
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.OBJECT;
|
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.STRING;
|
|
import static com.fasterxml.jackson.databind.node.JsonNodeType.STRING;
|
|
@@ -22,62 +20,57 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.fasterxml.jackson.databind.node.TextNode;
|
|
import com.fasterxml.jackson.databind.node.TextNode;
|
|
|
|
|
|
|
|
public class SizeTesterTest {
|
|
public class SizeTesterTest {
|
|
|
- static IntPredicate NON_ZERO = i -> i > 0;
|
|
|
|
|
-
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testAcceptedTypeIsArgument() {
|
|
public void testAcceptedTypeIsArgument() {
|
|
|
- assertThat(new SizeTester(ARRAY, NON_ZERO),
|
|
|
|
|
- acceptsTypes(ARRAY));
|
|
|
|
|
- assertThat(new SizeTester(OBJECT, NON_ZERO),
|
|
|
|
|
- acceptsTypes(OBJECT));
|
|
|
|
|
- assertThat(new SizeTester(STRING, NON_ZERO),
|
|
|
|
|
- acceptsTypes(STRING));
|
|
|
|
|
|
|
+ assertThat(SizeTester.minItems(0), acceptsTypes(ARRAY));
|
|
|
|
|
+ assertThat(SizeTester.minProperties(0), acceptsTypes(OBJECT));
|
|
|
|
|
+ assertThat(SizeTester.minLength(0), acceptsTypes(STRING));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void arrayMatcherRejectsObject() {
|
|
public void arrayMatcherRejectsObject() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(ARRAY, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minItems(0);
|
|
|
final JsonNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
final JsonNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void objectMatcherRejectsArray() {
|
|
public void objectMatcherRejectsArray() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(OBJECT, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minProperties(0);
|
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void textMatcherRejectsArray() {
|
|
public void textMatcherRejectsArray() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(STRING, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minLength(0);
|
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void arrayMatcherRejectsTooSmall() {
|
|
public void arrayMatcherRejectsTooSmall() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(ARRAY, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minItems(1);
|
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
final JsonNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void objectMatcherRejectsTooSmall() {
|
|
public void objectMatcherRejectsTooSmall() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(OBJECT, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minProperties(1);
|
|
|
final JsonNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
final JsonNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
assertThat(notEmptyArray, not(accepts(node)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testMatcherRejectsTooSmall() {
|
|
public void testMatcherRejectsTooSmall() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(STRING, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minLength(1);
|
|
|
assertThat(notEmptyArray, not(accepts(new TextNode(""))));
|
|
assertThat(notEmptyArray, not(accepts(new TextNode(""))));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void arrayMatcherAcceptsGoodSize() {
|
|
public void arrayMatcherAcceptsGoodSize() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(ARRAY, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minItems(1);
|
|
|
final ArrayNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
final ArrayNode node = new ArrayNode(JsonNodeFactory.instance);
|
|
|
node.add(NullNode.getInstance());
|
|
node.add(NullNode.getInstance());
|
|
|
assertThat(notEmptyArray, accepts(node));
|
|
assertThat(notEmptyArray, accepts(node));
|
|
@@ -85,7 +78,7 @@ public class SizeTesterTest {
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void objectMatcherAcceptsGoodSize() {
|
|
public void objectMatcherAcceptsGoodSize() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(OBJECT, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minProperties(1);
|
|
|
final ObjectNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
final ObjectNode node = new ObjectNode(JsonNodeFactory.instance);
|
|
|
node.set("_", NullNode.getInstance());
|
|
node.set("_", NullNode.getInstance());
|
|
|
assertThat(notEmptyArray, accepts(node));
|
|
assertThat(notEmptyArray, accepts(node));
|
|
@@ -93,7 +86,7 @@ public class SizeTesterTest {
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testMatcherAcceptsGoodSize() {
|
|
public void testMatcherAcceptsGoodSize() {
|
|
|
- final SizeTester notEmptyArray = new SizeTester(STRING, NON_ZERO);
|
|
|
|
|
|
|
+ final SizeTester notEmptyArray = SizeTester.minLength(1);
|
|
|
assertThat(notEmptyArray, accepts(new TextNode("_")));
|
|
assertThat(notEmptyArray, accepts(new TextNode("_")));
|
|
|
}
|
|
}
|
|
|
|
|
|