diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java')
-rw-r--r-- | config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java | 143 |
1 files changed, 67 insertions, 76 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java b/config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java index dbea8fb8aeb..f59938e9a41 100644 --- a/config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/PredicateDataTypeTestCase.java @@ -2,17 +2,12 @@ package com.yahoo.schema; import com.yahoo.schema.document.ImmutableSDField; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import com.yahoo.document.DataType; import com.yahoo.schema.parser.ParseException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author Lester Solbakken @@ -52,25 +47,21 @@ public class PredicateDataTypeTestCase { return "upper-bound: " + bound + "\n"; } - @SuppressWarnings("deprecation") - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test - public void requireThatBuilderSetsIndexParametersCorrectly() throws ParseException { + void requireThatBuilderSetsIndexParametersCorrectly() throws ParseException { int arity = 2; long lowerBound = -100; long upperBound = 100; String sd = searchSd( - predicateFieldSd( - attributeFieldSd( - arityParameter(arity) + - lowerBoundParameter(lowerBound) + - upperBoundParameter(upperBound)))); + predicateFieldSd( + attributeFieldSd( + arityParameter(arity) + + lowerBoundParameter(lowerBound) + + upperBoundParameter(upperBound)))); ApplicationBuilder sb = ApplicationBuilder.createFromString(sd); for (ImmutableSDField field : sb.getSchema().allConcreteFields()) { - if (field.getDataType() == DataType.PREDICATE) { + if (field.getDataType() == DataType.PREDICATE) { for (Index index : field.getIndices().values()) { assertTrue(index.getBooleanIndexDefiniton().hasArity()); assertEquals(arity, index.getBooleanIndexDefiniton().getArity()); @@ -84,20 +75,20 @@ public class PredicateDataTypeTestCase { } @Test - public void requireThatBuilderHandlesLongValues() throws ParseException { + void requireThatBuilderHandlesLongValues() throws ParseException { int arity = 2; long lowerBound = -100000000000000000L; long upperBound = 1000000000000000000L; String sd = searchSd( - predicateFieldSd( - attributeFieldSd( - arityParameter(arity) + - "lower-bound: -100000000000000000L\n" + // +'L' - upperBoundParameter(upperBound)))); + predicateFieldSd( + attributeFieldSd( + arityParameter(arity) + + "lower-bound: -100000000000000000L\n" + // +'L' + upperBoundParameter(upperBound)))); ApplicationBuilder sb = ApplicationBuilder.createFromString(sd); for (ImmutableSDField field : sb.getSchema().allConcreteFields()) { - if (field.getDataType() == DataType.PREDICATE) { + if (field.getDataType() == DataType.PREDICATE) { for (Index index : field.getIndices().values()) { assertEquals(arity, index.getBooleanIndexDefiniton().getArity()); assertEquals(lowerBound, index.getBooleanIndexDefiniton().getLowerBound()); @@ -108,11 +99,11 @@ public class PredicateDataTypeTestCase { } @Test - public void requireThatBuilderHandlesMissingParameters() throws ParseException { + void requireThatBuilderHandlesMissingParameters() throws ParseException { String sd = searchSd( - predicateFieldSd( - attributeFieldSd( - arityParameter(2)))); + predicateFieldSd( + attributeFieldSd( + arityParameter(2)))); ApplicationBuilder sb = ApplicationBuilder.createFromString(sd); for (ImmutableSDField field : sb.getSchema().allConcreteFields()) { if (field.getDataType() == DataType.PREDICATE) { @@ -126,74 +117,74 @@ public class PredicateDataTypeTestCase { } @Test - public void requireThatBuilderFailsIfNoArityValue() throws ParseException { - String sd = searchSd(predicateFieldSd(attributeFieldSd(""))); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Missing arity value in predicate field."); - ApplicationBuilder.createFromString(sd); - fail(); + void requireThatBuilderFailsIfNoArityValue() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd(predicateFieldSd(attributeFieldSd(""))); + ApplicationBuilder.createFromString(sd); + fail(); + }); + assertTrue(exception.getMessage().contains("Missing arity value in predicate field.")); } @Test - public void requireThatBuilderFailsIfBothIndexAndAttribute() throws ParseException { - String sd = searchSd(predicateFieldSd("indexing: summary | index | attribute\nindex { arity: 2 }")); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'p', field 'pf': Use 'attribute' instead of 'index'. This will require a refeed if you have upgraded."); - ApplicationBuilder.createFromString(sd); + void requireThatBuilderFailsIfBothIndexAndAttribute() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd(predicateFieldSd("indexing: summary | index | attribute\nindex { arity: 2 }")); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("For schema 'p', field 'pf': Use 'attribute' instead of 'index'. This will require a refeed if you have upgraded.")); } @Test - public void requireThatBuilderFailsIfIndex() throws ParseException { - String sd = searchSd(predicateFieldSd("indexing: summary | index \nindex { arity: 2 }")); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'p', field 'pf': Use 'attribute' instead of 'index'. This will require a refeed if you have upgraded."); - ApplicationBuilder.createFromString(sd); + void requireThatBuilderFailsIfIndex() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd(predicateFieldSd("indexing: summary | index \nindex { arity: 2 }")); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("For schema 'p', field 'pf': Use 'attribute' instead of 'index'. This will require a refeed if you have upgraded.")); } @Test - public void requireThatBuilderFailsIfIllegalArityValue() throws ParseException { - String sd = searchSd(predicateFieldSd(attributeFieldSd(arityParameter(0)))); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Invalid arity value in predicate field, must be greater than 1."); - ApplicationBuilder.createFromString(sd); + void requireThatBuilderFailsIfIllegalArityValue() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd(predicateFieldSd(attributeFieldSd(arityParameter(0)))); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("Invalid arity value in predicate field, must be greater than 1.")); } @Test - public void requireThatBuilderFailsIfArityParameterExistButNotPredicateField() throws ParseException { - String sd = searchSd(stringFieldSd(attributeFieldSd(arityParameter(2)))); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Arity parameter is used only for predicate type fields."); - ApplicationBuilder.createFromString(sd); + void requireThatBuilderFailsIfArityParameterExistButNotPredicateField() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd(stringFieldSd(attributeFieldSd(arityParameter(2)))); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("Arity parameter is used only for predicate type fields.")); } @Test - public void requireThatBuilderFailsIfBoundParametersExistButNotPredicateField() throws ParseException { - String sd = searchSd( - stringFieldSd( + void requireThatBuilderFailsIfBoundParametersExistButNotPredicateField() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd( + stringFieldSd( attributeFieldSd( lowerBoundParameter(100) + upperBoundParameter(1000)))); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Parameters lower-bound and upper-bound are used only for predicate type fields."); - ApplicationBuilder.createFromString(sd); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("Parameters lower-bound and upper-bound are used only for predicate type fields.")); } @Test - public void requireThatArrayOfPredicateFails() throws ParseException { - String sd = searchSd( - arrayPredicateFieldSd( - attributeFieldSd( - arityParameter(1)))); - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Collections of predicates are not allowed."); - ApplicationBuilder.createFromString(sd); + void requireThatArrayOfPredicateFails() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + String sd = searchSd( + arrayPredicateFieldSd( + attributeFieldSd( + arityParameter(1)))); + ApplicationBuilder.createFromString(sd); + }); + assertTrue(exception.getMessage().contains("Collections of predicates are not allowed.")); } } |