diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-11 09:14:24 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-11 09:14:24 +0200 |
commit | 2014e93de206861200950343c5330ed5997d8770 (patch) | |
tree | d3c05754412c7449da7f0ffcb7763526e7573925 /config-model | |
parent | c93826132f9256ce5597659a521494e6a3370a6c (diff) |
Don't check error messages from another module
Diffstat (limited to 'config-model')
2 files changed, 61 insertions, 34 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java index 80440ac8eb4..1b03825eef1 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java @@ -2,9 +2,10 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.searchdefinition.parser.ParseException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author geirst @@ -138,23 +139,29 @@ public class RankingExpressionWithTensorTestCase { f.assertRankProperty("tensor(x{})", "constant(my_tensor).type", "my_profile"); } - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void requireThatInvalidTensorTypeSpecThrowsException() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For constant tensor 'my_tensor' in rank profile 'my_profile': Illegal tensor type spec: A tensor type spec must be on the form tensor[<valuetype>]?(dimensionidentifier[{}|[length?]*), but was 'tensor(x)'. Dimension 'x' is on the wrong format. Examples: tensor(x[]), tensor<float>(name{}, x[10])"); - RankProfileSearchFixture f = new RankProfileSearchFixture( - " rank-profile my_profile {\n" + - " constants {\n" + - " my_tensor {\n" + - " value: { {x:1}:1 }\n" + - " type: tensor(x)\n" + - " }\n" + - " }\n" + - " }"); - f.compileRankProfile("my_profile"); + try { + RankProfileSearchFixture f = new RankProfileSearchFixture( + " rank-profile my_profile {\n" + + " constants {\n" + + " my_tensor {\n" + + " value: { {x:1}:1 }\n" + + " type: tensor(x)\n" + + " }\n" + + " }\n" + + " }"); + f.compileRankProfile("my_profile"); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertStartsWith("For constant tensor 'my_tensor' in rank profile 'my_profile': Illegal tensor type spec", + e.getMessage()); + } + } + + private void assertStartsWith(String prefix, String string) { + assertEquals(prefix, string.substring(0, Math.min(prefix.length(), string.length()))); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java index f53ca15635f..b6569357495 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java @@ -3,48 +3,68 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.parser.ParseException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author geirst */ public class TensorFieldTestCase { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead."); - SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}")); + try { + SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.", + e.getMessage()); + } } @Test public void requireThatTensorFieldCannotBeIndexField() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field."); - SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field.", + e.getMessage()); + } } @Test public void requireThatTensorAttributeCannotBeFastSearch() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'."); - SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'.", e.getMessage()); + } } @Test public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Field type: Illegal tensor type spec: A tensor type spec must be on the form tensor[<valuetype>]?(dimensionidentifier[{}|[length?]*), but was 'tensor(invalid)'. Dimension 'invalid' is on the wrong format. Examples: tensor(x[]), tensor<float>(name{}, x[10])"); - SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertStartsWith("Field type: Illegal tensor type spec:", e.getMessage()); + } } private static String getSd(String field) { return "search test {\n document test {\n" + field + "}\n}\n"; } + private void assertStartsWith(String prefix, String string) { + assertEquals(prefix, string.substring(0, Math.min(prefix.length(), string.length()))); + } + } |