Skip to content

Commit 2fe98d9

Browse files
committed
SOLR-17217: Simplify verbose MatcherAssert.assertThat usage in tests
1 parent 418dc06 commit 2fe98d9

File tree

108 files changed

+737
-895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+737
-895
lines changed

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ Other Changes
181181
* SOLR-17201: Http2SolrClient and friends no longer marked as @lucene.experimental.
182182
Krb5HttpClientBuilder and PreemptiveBasicAuthClientBuilderFactory no longer deprecated (janhoy)
183183

184+
* SOLR-17217: Simplify verbose MatcherAssert.assertThat usage in tests (hossman)
185+
184186
================== 9.5.0 ==================
185187
New Features
186188
---------------------

solr/core/src/test/org/apache/solr/TestDistributedGrouping.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.solr.common.params.ModifiableSolrParams;
3131
import org.apache.solr.common.params.SolrParams;
3232
import org.apache.solr.common.util.NamedList;
33-
import org.hamcrest.MatcherAssert;
3433
import org.junit.Test;
3534

3635
/**
@@ -888,7 +887,7 @@ public void test() throws Exception {
888887
"group.offset",
889888
"-1"));
890889
assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, exception.code());
891-
MatcherAssert.assertThat(
890+
assertThat(
892891
exception.getMessage(), containsString("'group.offset' parameter cannot be negative"));
893892
resetExceptionIgnores();
894893

solr/core/src/test/org/apache/solr/cloud/CreateCollectionCleanupTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
3030
import org.apache.solr.client.solrj.response.RequestStatusState;
3131
import org.apache.solr.common.params.CoreAdminParams;
32-
import org.hamcrest.MatcherAssert;
3332
import org.junit.BeforeClass;
3433
import org.junit.Test;
3534

@@ -76,8 +75,7 @@ public static void createCluster() throws Exception {
7675
public void testCreateCollectionCleanup() throws Exception {
7776
final CloudSolrClient cloudClient = cluster.getSolrClient();
7877
String collectionName = "foo";
79-
MatcherAssert.assertThat(
80-
CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));
78+
assertThat(CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));
8179
// Create a collection that would fail
8280
CollectionAdminRequest.Create create =
8381
CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 1);
@@ -95,7 +93,7 @@ public void testCreateCollectionCleanup() throws Exception {
9593
});
9694

9795
// Confirm using LIST that the collection does not exist
98-
MatcherAssert.assertThat(
96+
assertThat(
9997
"Failed collection is still in the clusterstate: "
10098
+ cluster.getSolrClient().getClusterState().getCollectionOrNull(collectionName),
10199
CollectionAdminRequest.listCollections(cloudClient),
@@ -106,8 +104,7 @@ public void testCreateCollectionCleanup() throws Exception {
106104
public void testAsyncCreateCollectionCleanup() throws Exception {
107105
final CloudSolrClient cloudClient = cluster.getSolrClient();
108106
String collectionName = "foo2";
109-
MatcherAssert.assertThat(
110-
CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));
107+
assertThat(CollectionAdminRequest.listCollections(cloudClient), not(hasItem(collectionName)));
111108

112109
// Create a collection that would fail
113110
CollectionAdminRequest.Create create =
@@ -125,10 +122,10 @@ public void testAsyncCreateCollectionCleanup() throws Exception {
125122
RequestStatusState state =
126123
AbstractFullDistribZkTestBase.getRequestStateAfterCompletion(
127124
"testAsyncCreateCollectionCleanup", 30, cloudClient);
128-
MatcherAssert.assertThat(state.getKey(), is("failed"));
125+
assertThat(state.getKey(), is("failed"));
129126

130127
// Confirm using LIST that the collection does not exist
131-
MatcherAssert.assertThat(
128+
assertThat(
132129
"Failed collection is still in the clusterstate: "
133130
+ cluster.getSolrClient().getClusterState().getCollectionOrNull(collectionName),
134131
CollectionAdminRequest.listCollections(cloudClient),

solr/core/src/test/org/apache/solr/cloud/DistribJoinFromCollectionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.apache.solr.common.cloud.Replica;
4141
import org.apache.solr.common.cloud.Slice;
4242
import org.apache.solr.common.cloud.ZkStateReader;
43-
import org.hamcrest.MatcherAssert;
4443
import org.junit.AfterClass;
4544
import org.junit.BeforeClass;
4645
import org.junit.Test;
@@ -204,7 +203,7 @@ private void testJoins(String toColl, String fromColl, String toDocId, boolean i
204203

205204
private void assertScore(boolean isScoresTest, SolrDocument doc) {
206205
if (isScoresTest) {
207-
MatcherAssert.assertThat(
206+
assertThat(
208207
"score join doesn't return 1.0", doc.getFirstValue("score").toString(), not("1.0"));
209208
} else {
210209
assertEquals("Solr join has constant score", "1.0", doc.getFirstValue("score").toString());

solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.solr.common.cloud.ZkStateReader;
3333
import org.apache.zookeeper.KeeperException;
3434
import org.hamcrest.CoreMatchers;
35-
import org.hamcrest.MatcherAssert;
3635
import org.junit.BeforeClass;
3736
import org.junit.Test;
3837

@@ -115,11 +114,11 @@ public void test()
115114
}
116115
assertTrue(found);
117116
// There are no leader election was kicked off on testCollection2
118-
MatcherAssert.assertThat(
117+
assertThat(
119118
collection2Shard1Nodes,
120119
CoreMatchers.is(
121120
getElectionNodes(TEST_COLLECTION_2, "shard1", stateReader.getZkClient())));
122-
MatcherAssert.assertThat(
121+
assertThat(
123122
collection2Shard2Nodes,
124123
CoreMatchers.is(
125124
getElectionNodes(TEST_COLLECTION_2, "shard2", stateReader.getZkClient())));

solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.solr.common.cloud.Slice;
4040
import org.apache.solr.embedded.JettySolrRunner;
4141
import org.apache.solr.util.TestInjection;
42-
import org.hamcrest.MatcherAssert;
4342
import org.junit.After;
4443
import org.junit.Before;
4544
import org.junit.BeforeClass;
@@ -138,7 +137,7 @@ private Replica corruptLeader(String collection) throws IOException, SolrServerE
138137
} catch (RemoteSolrException e) {
139138
// solrClient.add would throw RemoteSolrException with code 500
140139
// or 404 if the bad replica has already been deleted
141-
MatcherAssert.assertThat(e.code(), anyOf(is(500), is(404)));
140+
assertThat(e.code(), anyOf(is(500), is(404)));
142141
} catch (AlreadyClosedException e) {
143142
// If giving up leadership, might be already closed/closing
144143
}

solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.solr.common.SolrException;
2424
import org.apache.solr.common.SolrInputDocument;
2525
import org.apache.solr.embedded.JettySolrRunner;
26-
import org.hamcrest.MatcherAssert;
2726
import org.junit.BeforeClass;
2827
import org.junit.Test;
2928

@@ -51,7 +50,7 @@ public void test() throws Exception {
5150
() -> {
5251
client.add("collection", new SolrInputDocument());
5352
});
54-
MatcherAssert.assertThat(
53+
assertThat(
5554
e.getMessage(), containsString("Document is missing mandatory uniqueKey field: id"));
5655
}
5756
}

solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.solr.common.cloud.Slice;
4747
import org.apache.solr.common.util.NamedList;
4848
import org.apache.solr.embedded.JettySolrRunner;
49-
import org.hamcrest.MatcherAssert;
5049
import org.junit.After;
5150
import org.junit.Before;
5251
import org.junit.BeforeClass;
@@ -138,7 +137,7 @@ public void multipleOptionsSplitTest() {
138137
.setShardName("shard1");
139138
SolrException thrown =
140139
assertThrows(SolrException.class, () -> splitShard.process(cluster.getSolrClient()));
141-
MatcherAssert.assertThat(
140+
assertThat(
142141
thrown.getMessage(),
143142
containsString("numSubShards can not be specified with split.key or ranges parameters"));
144143
}

solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.apache.solr.common.params.SolrParams;
4848
import org.apache.solr.embedded.JettySolrRunner;
4949
import org.apache.solr.search.TestPseudoReturnFields;
50-
import org.hamcrest.MatcherAssert;
5150
import org.junit.AfterClass;
5251
import org.junit.Before;
5352
import org.junit.BeforeClass;
@@ -745,16 +744,15 @@ public void testAugmenters() throws Exception {
745744
assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
746745

747746
assertTrue(msg, doc.getFieldValue("shard_id") instanceof String);
748-
MatcherAssert.assertThat(doc.getFieldValue("shard_id").toString(), startsWith("shard"));
747+
assertThat(doc.getFieldValue("shard_id").toString(), startsWith("shard"));
749748

750749
assertTrue(msg, doc.getFieldValue("replica_urls") instanceof String);
751-
MatcherAssert.assertThat(
750+
assertThat(
752751
doc.getFieldValue("replica_urls").toString(),
753752
containsString(
754753
"/solr/org.apache.solr.cloud.TestCloudPseudoReturnFields_collection_shard"));
755754
if (1 < repFactor) {
756-
MatcherAssert.assertThat(
757-
doc.getFieldValue("replica_urls").toString(), containsString("|"));
755+
assertThat(doc.getFieldValue("replica_urls").toString(), containsString("|"));
758756
}
759757

760758
assertEquals(msg, doc.getFieldValue("shard_id"), doc.getFieldValue("[shard]"));
@@ -791,16 +789,15 @@ public void testAugmenters() throws Exception {
791789
String msg = p + " => " + doc;
792790

793791
assertTrue(msg, doc.getFieldValue("shard_id") instanceof String);
794-
MatcherAssert.assertThat(doc.getFieldValue("shard_id").toString(), startsWith("shard"));
792+
assertThat(doc.getFieldValue("shard_id").toString(), startsWith("shard"));
795793

796794
assertTrue(msg, doc.getFieldValue("replica_urls") instanceof String);
797-
MatcherAssert.assertThat(
795+
assertThat(
798796
doc.getFieldValue("replica_urls").toString(),
799797
containsString(
800798
"/solr/org.apache.solr.cloud.TestCloudPseudoReturnFields_collection_shard"));
801799
if (1 < repFactor) {
802-
MatcherAssert.assertThat(
803-
doc.getFieldValue("replica_urls").toString(), containsString("|"));
800+
assertThat(doc.getFieldValue("replica_urls").toString(), containsString("|"));
804801
}
805802

806803
assertEquals(msg, doc.getFieldValue("shard_id"), doc.getFieldValue("[shard]"));

solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
import org.apache.zookeeper.CreateMode;
107107
import org.apache.zookeeper.KeeperException;
108108
import org.apache.zookeeper.data.Stat;
109-
import org.hamcrest.MatcherAssert;
110109
import org.junit.After;
111110
import org.junit.AfterClass;
112111
import org.junit.Assume;
@@ -1402,8 +1401,7 @@ public void testUploadWithScriptUpdateProcessor() throws Exception {
14021401
});
14031402
unIgnoreException("uploaded without any authentication in place");
14041403

1405-
MatcherAssert.assertThat(
1406-
thrown.getMessage(), containsString("Underlying core creation failed"));
1404+
assertThat(thrown.getMessage(), containsString("Underlying core creation failed"));
14071405

14081406
// Authorization on
14091407
final String trustedSuffix = "-trusted";
@@ -1438,8 +1436,7 @@ public void testUploadWithLibDirective() throws Exception {
14381436
});
14391437
unIgnoreException("without any authentication in place");
14401438

1441-
MatcherAssert.assertThat(
1442-
thrown.getMessage(), containsString("Underlying core creation failed"));
1439+
assertThat(thrown.getMessage(), containsString("Underlying core creation failed"));
14431440

14441441
// Authorization on
14451442
final String trustedSuffix = "-trusted";

0 commit comments

Comments
 (0)