diff --git a/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java b/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java index 02f6ebdb295..ec978c83e26 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java @@ -17,6 +17,8 @@ package org.apache.solr.update.processor; import java.io.IOException; +import java.math.RoundingMode; +import java.text.NumberFormat; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; @@ -34,6 +36,12 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import org.hamcrest.core.IsInstanceOf; +import org.hamcrest.core.IsEqual; +import org.hamcrest.core.IsNot; + +import static org.junit.Assume.assumeThat; + import org.apache.solr.common.SolrInputDocument; import org.apache.solr.schema.IndexSchema; import org.junit.BeforeClass; @@ -46,6 +54,14 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { private static final DateTimeFormatter isoDateOptionalTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd['T'HH:mm[:ss[.SSS]]][z", Locale.ROOT).withZone(ZoneOffset.UTC); + private static final IsInstanceOf IS_BOOLEAN = new IsInstanceOf(Boolean.class); + private static final IsInstanceOf IS_STRING = new IsInstanceOf(String.class); + private static final IsInstanceOf IS_DATE = new IsInstanceOf(Date.class); + private static final IsInstanceOf IS_FLOAT = new IsInstanceOf(Float.class); + private static final IsInstanceOf IS_DOUBLE = new IsInstanceOf(Double.class); + private static final IsInstanceOf IS_INTEGER = new IsInstanceOf(Integer.class); + private static final IsInstanceOf IS_LONG = new IsInstanceOf(Long.class); + @BeforeClass public static void beforeClass() throws Exception { initCore("solrconfig-parsing-update-processor-chains.xml", "schema12.xml"); @@ -57,7 +73,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { String dateString = "2010-11-12T13:14:15.168Z"; SolrInputDocument d = processAdd("parse-date", doc(f("id", "9"), f("date_dt", dateString))); assertNotNull(d); - assertTrue(d.getFieldValue("date_dt") instanceof Date); + assertThat(d.getFieldValue("date_dt"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date) d.getFieldValue("date_dt")).toInstant()); assertU(commit()); assertQ(req("id:9"), "//date[@name='date_dt'][.='" + dateString + "']"); @@ -69,7 +85,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { String dateString = "2010-11-12T13:14:15.168Z"; SolrInputDocument d = processAdd("parse-date", doc(f("id", "39"), f("date_tdt", dateString))); assertNotNull(d); - assertTrue(d.getFieldValue("date_tdt") instanceof Date); + assertThat(d.getFieldValue("date_tdt"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date) d.getFieldValue("date_tdt")).toInstant()); assertU(commit()); assertQ(req("id:39"), "//date[@name='date_tdt'][.='" + dateString + "']"); @@ -84,7 +100,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-date-no-run-processor", doc(f("id", "18"), f("not_in_schema", dateString))); assertNotNull(d); - assertTrue(d.getFieldValue("not_in_schema") instanceof Date); + assertThat(d.getFieldValue("not_in_schema"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date)d.getFieldValue("not_in_schema")).toInstant()); d = processAdd("parse-date-no-run-processor", @@ -92,7 +108,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(d); for (Object val : d.getFieldValues("not_in_schema")) { // check that nothing was mutated, since not all field values are parseable as dates - assertTrue(val instanceof String); + assertThat(val, IS_STRING); } d = processAdd("parse-date-no-run-processor", @@ -100,7 +116,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(d); for (Object val : d.getFieldValues("not_in_schema")) { // check again that nothing was mutated, but with a valid date first this time - assertTrue(val instanceof String); + assertThat(val, IS_STRING); } } @@ -117,8 +133,8 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { ("parse-date-non-UTC-defaultTimeZone", doc(f("id", "99"), f("dateUTC_dt", dateStringUTC), f("dateNoTimeZone_dt", dateStringNoTimeZone))); assertNotNull(d); - assertTrue(d.getFieldValue("dateUTC_dt") instanceof Date); - assertTrue(d.getFieldValue("dateNoTimeZone_dt") instanceof Date); + assertThat(d.getFieldValue("dateUTC_dt"), IS_DATE); + assertThat(d.getFieldValue("dateNoTimeZone_dt"), IS_DATE); assertU(commit()); assertQ(req("id:99") ,"//date[@name='dateUTC_dt'][.='" + dateStringUTC + "']" @@ -133,7 +149,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-date-explicit-not-in-schema-selector-no-run-processor", doc(f("id", "88"), f("not_in_schema", dateString))); assertNotNull(d); - assertTrue(d.getFieldValue("not_in_schema") instanceof Date); + assertThat(d.getFieldValue("not_in_schema"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date)d.getFieldValue("not_in_schema")).toInstant()); } @@ -151,7 +167,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { } assertNotNull(d); - assertTrue(d.getFieldValue("date_dt") instanceof Date); + assertThat(d.getFieldValue("date_dt"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date)d.getFieldValue("date_dt")).toInstant()); } @@ -162,7 +178,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("US-Pacific-parse-date-no-run-processor", doc(f("id", "288"), f("not_in_schema", dateString))); assertNotNull(d); - assertTrue(d.getFieldValue("not_in_schema") instanceof Date); + assertThat(d.getFieldValue("not_in_schema"), IS_DATE); assertEquals(Instant.parse("2010-08-09T07:00:00.000Z"), ((Date)d.getFieldValue("not_in_schema")).toInstant()); } @@ -208,8 +224,8 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-date-many-formats-no-run-processor", doc(f("id", id), f("dateUTC_dt", dateString))); assertNotNull(d); - assertTrue("index: " + i + " date '" + dateString + "' is not mutated to a Date", - d.getFieldValue("dateUTC_dt") instanceof Date); + assertThat("index: " + i + " date '" + dateString + "' is not mutated to a Date", + d.getFieldValue("dateUTC_dt"), IS_DATE); assertEquals("date '" + dateString + "' mismatched milliseconds", expectedInstant, ((Date)d.getFieldValue("dateUTC_dt")).toInstant()); } @@ -223,7 +239,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-french-date-UTC-defaultTimeZone-no-run-processor", doc(f("id", "88"), f("not_in_schema", frenchDateString))); assertNotNull(d); - assertTrue(d.getFieldValue("not_in_schema") instanceof Date); + assertThat(d.getFieldValue("not_in_schema"), IS_DATE); assertEquals(Instant.parse(dateString), ((Date)d.getFieldValue("not_in_schema")).toInstant()); } @@ -245,7 +261,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (extraDouble == o) { foundDouble = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -263,9 +279,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-int", doc(f("id", "113"), f("int1_i", intString1), f("int2_i", intString2))); assertNotNull(d); - assertTrue(d.getFieldValue("int1_i") instanceof Integer); + assertThat(d.getFieldValue("int1_i"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int1_i")).intValue()); - assertTrue(d.getFieldValue("int2_i") instanceof Integer); + assertThat(d.getFieldValue("int2_i"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int2_i")).intValue()); assertU(commit()); @@ -284,9 +300,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-int-russian-no-run-processor", doc(f("id", "113"), f("int_i", intString1), f("not_in_schema", intString2))); assertNotNull(d); - assertTrue(d.getFieldValue("int_i") instanceof Integer); + assertThat(d.getFieldValue("int_i"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int_i")).intValue()); - assertTrue(d.getFieldValue("not_in_schema") instanceof Integer); + assertThat(d.getFieldValue("not_in_schema"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("not_in_schema")).intValue()); } @@ -300,9 +316,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-int", doc(f("id", "113"), f("int1_ti", intString1), f("int2_ti", intString2))); assertNotNull(d); - assertTrue(d.getFieldValue("int1_ti") instanceof Integer); + assertThat(d.getFieldValue("int1_ti"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int1_ti")).intValue()); - assertTrue(d.getFieldValue("int2_ti") instanceof Integer); + assertThat(d.getFieldValue("int2_ti"), IS_INTEGER); assertEquals(value, ((Integer)d.getFieldValue("int2_ti")).intValue()); assertU(commit()); @@ -322,8 +338,8 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-int-no-run-processor", doc(f("id", "282"), f("not_in_schema1", longString1), f("not_in_schema2", longString2))); assertNotNull(d); - assertTrue(d.getFieldValue("not_in_schema1") instanceof String); - assertTrue(d.getFieldValue("not_in_schema2") instanceof String); + assertThat(d.getFieldValue("not_in_schema1"), IS_STRING); + assertThat(d.getFieldValue("not_in_schema2"), IS_STRING); } public void testFailedParseMixedInt() throws Exception { @@ -343,7 +359,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (floatVal == o) { foundFloat = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -361,9 +377,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-long", doc(f("id", "113"), f("long1_l", longString1), f("long2_l", longString2))); assertNotNull(d); - assertTrue(d.getFieldValue("long1_l") instanceof Long); + assertThat(d.getFieldValue("long1_l"), IS_LONG); assertEquals(value, ((Long) d.getFieldValue("long1_l")).longValue()); - assertTrue(d.getFieldValue("long2_l") instanceof Long); + assertThat(d.getFieldValue("long2_l"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("long2_l")).longValue()); assertU(commit()); @@ -373,6 +389,14 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { } public void testParseLongNonRootLocale() throws Exception { + { + final NumberFormat sanityCheck = NumberFormat.getInstance(new Locale("fr","FR")); + sanityCheck.setParseIntegerOnly(false); + sanityCheck.setRoundingMode(RoundingMode.CEILING); + assumeThat("Your JVM appears to have NumberFormat parse bugs using U+00A0 in the fr_FR Locale", + sanityCheck.parse("10 898"), new IsNot(new IsEqual(10L))); + } + IndexSchema schema = h.getCore().getLatestSchema(); assertNotNull(schema.getFieldOrNull("long_l")); // should match dynamic field "*_l" assertNull(schema.getFieldOrNull("not_in_schema")); @@ -382,9 +406,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-long-russian-no-run-processor", doc(f("id", "113"), f("long_l", longString1), f("not_in_schema", longString2))); assertNotNull(d); - assertTrue(d.getFieldValue("long_l") instanceof Long); + assertThat(d.getFieldValue("long_l"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("long_l")).longValue()); - assertTrue(d.getFieldValue("not_in_schema") instanceof Long); + assertThat(d.getFieldValue("not_in_schema"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("not_in_schema")).longValue()); } @@ -398,9 +422,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-long", doc(f("id", "113"), f("long1_tl", longString1), f("long2_tl", longString2))); assertNotNull(d); - assertTrue(d.getFieldValue("long1_tl") instanceof Long); + assertThat(d.getFieldValue("long1_tl"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("long1_tl")).longValue()); - assertTrue(d.getFieldValue("long2_tl") instanceof Long); + assertThat(d.getFieldValue("long2_tl"), IS_LONG); assertEquals(value, ((Long)d.getFieldValue("long2_tl")).longValue()); assertU(commit()); @@ -426,7 +450,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (floatVal == o) { foundFloat = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -444,9 +468,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-float", doc(f("id", "128"), f("float1_f", floatString1), f("float2_f", floatString2))); assertNotNull(d); - assertTrue(d.getFieldValue("float1_f") instanceof Float); + assertThat(d.getFieldValue("float1_f"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("float1_f"), EPSILON); - assertTrue(d.getFieldValue("float2_f") instanceof Float); + assertThat(d.getFieldValue("float2_f"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("float2_f"), EPSILON); assertU(commit()); @@ -456,19 +480,27 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { } public void testParseFloatNonRootLocale() throws Exception { - IndexSchema schema = h.getCore().getLatestSchema(); - assertNotNull(schema.getFieldOrNull("float_f")); // should match dynamic field "*_f" - assertNull(schema.getFieldOrNull("not_in_schema")); + { + final NumberFormat sanityCheck = NumberFormat.getInstance(new Locale("fr","FR")); + sanityCheck.setParseIntegerOnly(false); + sanityCheck.setRoundingMode(RoundingMode.CEILING); + assumeThat("Your JVM appears to have NumberFormat parse bugs using U+00A0 in the fr_FR Locale", + sanityCheck.parse("10 898"), new IsNot(new IsEqual(10L))); + } + float value = 10898.83491f; String floatString1 = "10898,83491"; String floatString2 = "10 898,83491"; // no-break space: U+00A0 + IndexSchema schema = h.getCore().getLatestSchema(); + assertNotNull(schema.getFieldOrNull("float_f")); // should match dynamic field "*_f" + assertNull(schema.getFieldOrNull("not_in_schema")); SolrInputDocument d = processAdd("parse-float-french-no-run-processor", doc(f("id", "140"), f("float_f", floatString1), f("not_in_schema", floatString2))); assertNotNull(d); - assertTrue(d.getFieldValue("float_f") instanceof Float); + assertThat(d.getFieldValue("float_f"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("float_f"), EPSILON); - assertTrue(d.getFieldValue("not_in_schema") instanceof Float); + assertThat(d.getFieldValue("not_in_schema"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("not_in_schema"), EPSILON); } @@ -482,9 +514,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-float", doc(f("id", "728"), f("float1_tf", floatString1), f("float2_tf", floatString2))); assertNotNull(d); - assertTrue(d.getFieldValue("float1_tf") instanceof Float); + assertThat(d.getFieldValue("float1_tf"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("float1_tf"), EPSILON); - assertTrue(d.getFieldValue("float2_tf") instanceof Float); + assertThat(d.getFieldValue("float2_tf"), IS_FLOAT); assertEquals(value, (Float)d.getFieldValue("float2_tf"), EPSILON); assertU(commit()); @@ -505,7 +537,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { doc(f("id", "342"), f("float_tf", mixedFloats.values()))); assertNotNull(d); for (Object o : d.getFieldValues("float_tf")) { - assertTrue(o instanceof Float); + assertThat(o, IS_FLOAT); mixedFloats.remove(o); } assertTrue(mixedFloats.isEmpty()); @@ -528,7 +560,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (longVal == o) { foundLong = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -546,9 +578,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-double", doc(f("id", "128"), f("double1_d", doubleString1), f("double2_d", doubleString2))); assertNotNull(d); - assertTrue(d.getFieldValue("double1_d") instanceof Double); + assertThat(d.getFieldValue("double1_d"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("double1_d"), EPSILON); - assertTrue(d.getFieldValue("double2_d") instanceof Double); + assertThat(d.getFieldValue("double2_d"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("double2_d"), EPSILON); assertU(commit()); @@ -558,6 +590,13 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { } public void testParseDoubleNonRootLocale() throws Exception { + { + final NumberFormat sanityCheck = NumberFormat.getInstance(new Locale("fr","FR")); + sanityCheck.setParseIntegerOnly(false); + sanityCheck.setRoundingMode(RoundingMode.CEILING); + assumeThat("Your JVM appears to have NumberFormat parse bugs using U+00A0 in the fr_FR Locale", + sanityCheck.parse("10 898"), new IsNot(new IsEqual(10L))); + } IndexSchema schema = h.getCore().getLatestSchema(); assertNotNull(schema.getFieldOrNull("double_d")); // should match dynamic field "*_d" assertNull(schema.getFieldOrNull("not_in_schema")); @@ -568,9 +607,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { doc(f("id", "140"), f("double_d", doubleString1), f("not_in_schema", doubleString2))); assertNotNull(d); - assertTrue(d.getFieldValue("double_d") instanceof Double); + assertThat(d.getFieldValue("double_d"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("double_d"), EPSILON); - assertTrue(d.getFieldValue("not_in_schema") instanceof Double); + assertThat(d.getFieldValue("not_in_schema"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("not_in_schema"), EPSILON); } @@ -584,9 +623,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-double", doc(f("id", "728"), f("double1_td", doubleString1), f("double2_td", doubleString2))); assertNotNull(d); - assertTrue(d.getFieldValue("double1_td") instanceof Double); + assertThat(d.getFieldValue("double1_td"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("double1_td"), EPSILON); - assertTrue(d.getFieldValue("double2_td") instanceof Double); + assertThat(d.getFieldValue("double2_td"), IS_DOUBLE); assertEquals(value, (Double)d.getFieldValue("double2_td"), EPSILON); assertU(commit()); @@ -612,7 +651,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (longVal == o) { foundLong = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -629,9 +668,9 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { SolrInputDocument d = processAdd("parse-boolean", doc(f("id", "141"), f("boolean1_b", value1), f("boolean2_b", value2))); assertNotNull(d); - assertTrue(d.getFieldValue("boolean1_b") instanceof Boolean); + assertThat(d.getFieldValue("boolean1_b"), IS_BOOLEAN); assertEquals(value1, d.getFieldValue("boolean1_b")); - assertTrue(d.getFieldValue("boolean2_b") instanceof Boolean); + assertThat(d.getFieldValue("boolean2_b"), IS_BOOLEAN); assertEquals(value2, d.getFieldValue("boolean2_b")); assertU(commit()); @@ -659,7 +698,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(d); for (int i = 0 ; i < values.length ; ++i) { - assertTrue(d.getFieldValue(fieldNames[i]) instanceof Boolean); + assertThat(d.getFieldValue(fieldNames[i]), IS_BOOLEAN); assertEquals(values[i], d.getFieldValue(fieldNames[i])); } } @@ -679,7 +718,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(d); for (int i = 0 ; i < values.length ; ++i) { - assertTrue(d.getFieldValue(fieldNames[i]) instanceof Boolean); + assertThat(d.getFieldValue(fieldNames[i]), IS_BOOLEAN); assertEquals(values[i], d.getFieldValue(fieldNames[i])); } @@ -693,7 +732,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(d); for (int i = 0 ; i < values.length ; ++i) { - assertTrue(d.getFieldValue(fieldNames[i]) instanceof String); + assertThat(d.getFieldValue(fieldNames[i]), IS_STRING); } } @@ -714,7 +753,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { if (longVal == o) { foundLong = true; } else { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } mixed.values().remove(o); } @@ -735,7 +774,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "341"), f(fieldName, booleans.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Boolean); + assertThat(o, IS_BOOLEAN); booleans.remove(o); } assertTrue(booleans.isEmpty()); @@ -747,7 +786,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "333"), f(fieldName, ints.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Integer); + assertThat(o, IS_INTEGER); ints.remove(o); } assertTrue(ints.isEmpty()); @@ -759,7 +798,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "342"), f(fieldName, longs.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Long); + assertThat(o, IS_LONG); longs.remove(o); } assertTrue(longs.isEmpty()); @@ -786,7 +825,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "342"), f(fieldName, doubles.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Double); + assertThat(o, IS_DOUBLE); longs.remove(o); } @@ -798,7 +837,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "343"), f(fieldName, dates.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Date); + assertThat(o, IS_DATE); dates.remove(o); } assertTrue(dates.isEmpty()); @@ -811,7 +850,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "344"), f(fieldName, mixedLongsAndDoubles.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Double); + assertThat(o, IS_DOUBLE); mixedLongsAndDoubles.remove(o); } assertTrue(mixedLongsAndDoubles.isEmpty()); @@ -825,7 +864,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "345"), f(fieldName, mixed))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof String); + assertThat(o, IS_STRING); } Map mixedDoubles = new LinkedHashMap<>(); // preserve order @@ -836,7 +875,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "3391"), f(fieldName, mixedDoubles.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Double); + assertThat(o, IS_DOUBLE); mixedDoubles.remove(o); } assertTrue(mixedDoubles.isEmpty()); @@ -849,7 +888,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "3392"), f(fieldName, mixedInts.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Integer); + assertThat(o, IS_INTEGER); mixedInts.remove(o); } assertTrue(mixedInts.isEmpty()); @@ -862,7 +901,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "3393"), f(fieldName, mixedLongs.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Long); + assertThat(o, IS_LONG); mixedLongs.remove(o); } assertTrue(mixedLongs.isEmpty()); @@ -875,7 +914,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "3394"), f(fieldName, mixedBooleans.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Boolean); + assertThat(o, IS_BOOLEAN); mixedBooleans.remove(o); } assertTrue(mixedBooleans.isEmpty()); @@ -890,7 +929,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { d = processAdd(chain, doc(f("id", "3395"), f(fieldName, mixedDates.values()))); assertNotNull(d); for (Object o : d.getFieldValues(fieldName)) { - assertTrue(o instanceof Date); + assertThat(o, IS_DATE); mixedDates.remove(o); } assertTrue(mixedDates.isEmpty()); @@ -915,7 +954,7 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(schema.getFieldOrNull("date_dt")); // should match "*_dt" dynamic field SolrInputDocument d = processAdd("parse-date-patterns-default-config", doc(f("id", id), f("date_dt", notInFormatDateString))); assertNotNull(d); - assertTrue("Date string: " + notInFormatDateString + " was not parsed as a date", d.getFieldValue("date_dt") instanceof Date); + assertThat("Date string: " + notInFormatDateString + " was not parsed as a date", d.getFieldValue("date_dt"), IS_DATE); assertEquals(notInFormatDateString, ((Date) d.getField("date_dt").getFirstValue()).toInstant().toString()); assertU(commit()); assertQ(req("id:" + id), "//date[@name='date_dt'][.='" + notInFormatDateString + "']"); @@ -938,8 +977,8 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(schema.getFieldOrNull("date_dt")); // should match "*_dt" dynamic field SolrInputDocument d = processAdd("parse-date-patterns-default-config", doc(f("id", id), f("date_dt", lenientDateString))); assertNotNull(d); - assertTrue("Date string: " + lenientDateString + " was not parsed as a date", - d.getFieldValue("date_dt") instanceof Date); + assertThat("Date string: " + lenientDateString + " was not parsed as a date", + d.getFieldValue("date_dt"), IS_DATE); assertEquals(expectedString, ((Date) d.getField("date_dt").getFirstValue()).toInstant().toString()); ++id; } @@ -1026,8 +1065,8 @@ public class ParsingFieldUpdateProcessorsTest extends UpdateProcessorTestBase { assertNotNull(schema.getFieldOrNull("date_dt")); // should match "*_dt" dynamic field SolrInputDocument d = processAdd(chain, doc(f("id", "1"), f("date_dt", inputDateString))); assertNotNull(d); - assertTrue("Date string: " + inputDateString + " was not parsed as a date", - d.getFieldValue("date_dt") instanceof Date); + assertThat("Date string: " + inputDateString + " was not parsed as a date", + d.getFieldValue("date_dt"), IS_DATE); assertEquals(expectedDate, d.getField("date_dt").getFirstValue()); }