2424import org .apache .zookeeper .ZooDefs ;
2525import org .apache .zookeeper .client .ZKClientConfig ;
2626import org .apache .zookeeper .common .ClientX509Util ;
27- import org .hamcrest .Matcher ;
28- import org .hamcrest .core .IsNull ;
2927import org .junit .jupiter .api .BeforeEach ;
3028import org .junit .jupiter .api .Test ;
3129import org .mockito .ArgumentCaptor ;
3533
3634import java .util .Arrays ;
3735
38- import static org .hamcrest .CoreMatchers .anyOf ;
39- import static org .hamcrest .CoreMatchers .containsString ;
40- import static org .hamcrest .CoreMatchers .is ;
41- import static org .hamcrest .MatcherAssert .assertThat ;
36+ import static org .assertj .core .api .Assertions .assertThat ;
4237import static org .junit .jupiter .api .Assertions .assertThrows ;
4338import static org .mockito .ArgumentCaptor .forClass ;
4439import static org .mockito .ArgumentMatchers .isA ;
@@ -219,14 +214,18 @@ public void testSSLConfiguration() {
219214 verify (cfBuilder ).zkClientConfig (clientConfCaptor .capture ());
220215 ZKClientConfig conf = clientConfCaptor .getValue ();
221216
222- assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ), is ("true" ) );
223- assertThat (conf .getProperty (ZKClientConfig .ZOOKEEPER_CLIENT_CNXN_SOCKET ),
224- is ("org.apache.zookeeper.ClientCnxnSocketNetty" ) );
217+ assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT )). isEqualTo ("true" );
218+ assertThat (conf .getProperty (ZKClientConfig .ZOOKEEPER_CLIENT_CNXN_SOCKET ))
219+ . isEqualTo ("org.apache.zookeeper.ClientCnxnSocketNetty" );
225220 try (ClientX509Util sslOpts = new ClientX509Util ()) {
226- assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()), is ("keystoreLoc" ));
227- assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()), is ("ksPass" ));
228- assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()), is ("truststoreLoc" ));
229- assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()), is ("tsPass" ));
221+ assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()))
222+ .isEqualTo ("keystoreLoc" );
223+ assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()))
224+ .isEqualTo ("ksPass" );
225+ assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()))
226+ .isEqualTo ("truststoreLoc" );
227+ assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()))
228+ .isEqualTo ("tsPass" );
230229 }
231230
232231 verifyDummyConnectionString ();
@@ -244,39 +243,39 @@ public void testNoConnectionString(){
244243 clientConfigurer .withConnectionString (null );
245244
246245 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
247- assertThat (t .getMessage (), containsString ("Zookeeper connection string cannot be null!" ) );
246+ assertThat (t .getMessage ()). contains ("Zookeeper connection string cannot be null!" );
248247 }
249248
250249 @ Test
251250 public void testNoRetryPolicy () {
252251 clientConfigurer .withRetryPolicy (null );
253252
254253 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
255- assertThat (t .getMessage (), containsString ("Zookeeper connection retry policy cannot be null!" ) );
254+ assertThat (t .getMessage ()). contains ("Zookeeper connection retry policy cannot be null!" );
256255 }
257256
258257 @ Test
259258 public void testNoAuthType () {
260259 clientConfigurer .withAuthType (null );
261260
262261 Throwable t = assertThrows (NullPointerException .class , () -> clientConfigurer .create ());
263- assertThat (t .getMessage (), containsString ("Zookeeper authType cannot be null!" ) );
262+ assertThat (t .getMessage ()). contains ("Zookeeper authType cannot be null!" );
264263 }
265264
266265 @ Test
267266 public void testUnrecognizedAuthType () {
268267 clientConfigurer .withAuthType ("something" );
269268
270269 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
271- assertThat (t .getMessage (), is ("Zookeeper authType must be one of [none, sasl]!" ) );
270+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper authType must be one of [none, sasl]!" );
272271 }
273272
274273 @ Test
275274 public void testSaslAuthTypeWithoutKeytab () {
276275 clientConfigurer .withAuthType ("sasl" );
277276
278277 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
279- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Keytab must be specified!" ) );
278+ assertThat (t .getMessage ()). isEqualTo ("Zookeeper client's Kerberos Keytab must be specified!" );
280279 }
281280
282281 @ Test
@@ -286,7 +285,8 @@ public void testSaslAuthTypeWithEmptyKeytab() {
286285 .withKeytab ("" );
287286
288287 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
289- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Keytab must be specified!" ));
288+
289+ assertThat (t .getMessage ()).isEqualTo ("Zookeeper client's Kerberos Keytab must be specified!" );
290290 }
291291
292292 @ Test
@@ -296,7 +296,8 @@ public void testSaslAuthTypeWithoutPrincipal() {
296296 .withKeytab ("keytabLoc" );
297297
298298 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
299- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Principal must be specified!" ));
299+ assertThat (t .getMessage ()).isEqualTo (
300+ "Zookeeper client's Kerberos Principal must be specified!" );
300301 }
301302
302303 @ Test
@@ -307,7 +308,8 @@ public void testSaslAuthTypeWithEmptyPrincipal() {
307308 .withPrincipal ("" );
308309
309310 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
310- assertThat (t .getMessage (), is ("Zookeeper client's Kerberos Principal must be specified!" ));
311+ assertThat (t .getMessage ()).isEqualTo (
312+ "Zookeeper client's Kerberos Principal must be specified!" );
311313 }
312314
313315 @ Test
@@ -319,7 +321,7 @@ public void testSaslAuthTypeWithoutJaasLoginEntryName() {
319321 .withJaasLoginEntryName (null );
320322
321323 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
322- assertThat (t .getMessage (), is ("JAAS Login Entry name must be specified!" ) );
324+ assertThat (t .getMessage ()). isEqualTo ("JAAS Login Entry name must be specified!" );
323325 }
324326
325327 @ Test
@@ -331,7 +333,7 @@ public void testSaslAuthTypeWithEmptyJaasLoginEntryName() {
331333 .withJaasLoginEntryName ("" );
332334
333335 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
334- assertThat (t .getMessage (), is ("JAAS Login Entry name must be specified!" ) );
336+ assertThat (t .getMessage ()). isEqualTo ("JAAS Login Entry name must be specified!" );
335337 }
336338
337339 @ Test
@@ -340,8 +342,8 @@ public void testSSLWithoutKeystore() {
340342 .enableSSL (true );
341343
342344 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
343- assertThat (t .getMessage (),
344- is ( "The keystore location parameter is empty for the ZooKeeper client connection." ) );
345+ assertThat (t .getMessage ()). isEqualTo (
346+ "The keystore location parameter is empty for the ZooKeeper client connection." );
345347 }
346348
347349 @ Test
@@ -351,8 +353,8 @@ public void testSSLWithEmptyKeystore() {
351353 .withKeystore ("" );
352354
353355 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
354- assertThat (t .getMessage (),
355- is ( "The keystore location parameter is empty for the ZooKeeper client connection." ) );
356+ assertThat (t .getMessage ()). isEqualTo (
357+ "The keystore location parameter is empty for the ZooKeeper client connection." );
356358 }
357359
358360 @ Test
@@ -362,8 +364,8 @@ public void testSSLWithoutTruststore() {
362364 .withKeystore ("keyStoreLoc" );
363365
364366 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
365- assertThat (t .getMessage (),
366- is ( "The truststore location parameter is empty for the ZooKeeper client connection." ) );
367+ assertThat (t .getMessage ()). isEqualTo (
368+ "The truststore location parameter is empty for the ZooKeeper client connection." );
367369 }
368370
369371 @ Test
@@ -374,8 +376,8 @@ public void testSSLWithEmptyTruststore() {
374376 .withTruststore ("" );
375377
376378 Throwable t = assertThrows (IllegalArgumentException .class , () -> clientConfigurer .create ());
377- assertThat (t .getMessage (),
378- is ( "The truststore location parameter is empty for the ZooKeeper client connection." ) );
379+ assertThat (t .getMessage ()). isEqualTo (
380+ "The truststore location parameter is empty for the ZooKeeper client connection." );
379381 }
380382
381383 private void testSaslAuthType (String vendor ) {
@@ -395,36 +397,39 @@ private void testSaslAuthType(String vendor) {
395397 verify (cfBuilder ).aclProvider (aclProviderCaptor .capture ());
396398 SASLOwnerACLProvider aclProvider = aclProviderCaptor .getValue ();
397399
398- assertThat (aclProvider .getDefaultAcl ().size (), is ( 1 ) );
399- assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getScheme (), is ("sasl" ) );
400- assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getId (), is ("principal" ) );
401- assertThat (aclProvider .getDefaultAcl ().get (0 ).getPerms (), is (ZooDefs .Perms .ALL ) );
400+ assertThat (aclProvider .getDefaultAcl ().size ()). isEqualTo ( 1 );
401+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getScheme ()). isEqualTo ("sasl" );
402+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getId ().getId ()). isEqualTo ("principal" );
403+ assertThat (aclProvider .getDefaultAcl ().get (0 ).getPerms ()). isEqualTo (ZooDefs .Perms .ALL );
402404
403405 Arrays .stream (new String [] {"/" , "/foo" , "/foo/bar/baz" , "/random/path" })
404406 .forEach (s -> {
405- assertThat (aclProvider .getAclForPath (s ).size (), is ( 1 ) );
406- assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getScheme (), is ("sasl" ) );
407- assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getId (), is ("principal" ) );
408- assertThat (aclProvider .getAclForPath (s ).get (0 ).getPerms (), is (ZooDefs .Perms .ALL ) );
407+ assertThat (aclProvider .getAclForPath (s ).size ()). isEqualTo ( 1 );
408+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getScheme ()). isEqualTo ("sasl" );
409+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getId ().getId ()). isEqualTo ("principal" );
410+ assertThat (aclProvider .getAclForPath (s ).get (0 ).getPerms ()). isEqualTo (ZooDefs .Perms .ALL );
409411 });
410412
411- assertThat (System .getProperty (ZKClientConfig .LOGIN_CONTEXT_NAME_KEY ), is ("TestEntry" ) );
412- assertThat (System .getProperty ("zookeeper.authProvider.1" ),
413- is ( "org.apache.zookeeper.server.auth.SASLAuthenticationProvider" ) );
413+ assertThat (System .getProperty (ZKClientConfig .LOGIN_CONTEXT_NAME_KEY )). isEqualTo ("TestEntry" );
414+ assertThat (System .getProperty ("zookeeper.authProvider.1" )). isEqualTo (
415+ "org.apache.zookeeper.server.auth.SASLAuthenticationProvider" );
414416
415417 Configuration config = Configuration .getConfiguration ();
416- assertThat (config .getAppConfigurationEntry ("TestEntry" ).length , is ( 1 ) );
418+ assertThat (config .getAppConfigurationEntry ("TestEntry" ).length ). isEqualTo ( 1 );
417419 AppConfigurationEntry entry = config .getAppConfigurationEntry ("TestEntry" )[0 ];
418- assertThat (entry .getOptions ().get ("keyTab" ), is ("keytabLoc" ));
419- assertThat (entry .getOptions ().get ("principal" ), is ("principal@some.host/SOME.REALM" ));
420- assertThat (entry .getOptions ().get ("useKeyTab" ), is ("true" ));
421- assertThat (entry .getOptions ().get ("storeKey" ), is ("true" ));
422- assertThat (entry .getOptions ().get ("useTicketCache" ), is ("false" ));
423- assertThat (entry .getOptions ().get ("refreshKrb5Config" ), is ("true" ));
420+ assertThat (entry .getOptions ().get ("keyTab" )).isEqualTo ("keytabLoc" );
421+ assertThat (entry .getOptions ().get ("principal" )).isEqualTo ("principal@some.host/SOME.REALM" );
422+ assertThat (entry .getOptions ().get ("useKeyTab" )).isEqualTo ("true" );
423+ assertThat (entry .getOptions ().get ("storeKey" )).isEqualTo ("true" );
424+ assertThat (entry .getOptions ().get ("useTicketCache" )).isEqualTo ("false" );
425+ assertThat (entry .getOptions ().get ("refreshKrb5Config" )).isEqualTo ("true" );
426+
424427 if (System .getProperty ("java.vendor" ).contains ("IBM" )){
425- assertThat (entry .getLoginModuleName (), is ("com.ibm.security.auth.module.Krb5LoginModule" ));
428+ assertThat (entry .getLoginModuleName ()).isEqualTo (
429+ "com.ibm.security.auth.module.Krb5LoginModule" );
426430 } else {
427- assertThat (entry .getLoginModuleName (), is ("com.sun.security.auth.module.Krb5LoginModule" ));
431+ assertThat (entry .getLoginModuleName ()).isEqualTo (
432+ "com.sun.security.auth.module.Krb5LoginModule" );
428433 }
429434 } finally {
430435 Configuration .setConfiguration (origConf );
@@ -465,8 +470,8 @@ private void verifyDefaultRetryPolicy() {
465470 verify (cfBuilder ).retryPolicy (retry .capture ());
466471 ExponentialBackoffRetry policy = retry .getValue ();
467472
468- assertThat (policy .getBaseSleepTimeMs (), is (1000 ) );
469- assertThat (policy .getN (), is ( 3 ) );
473+ assertThat (policy .getBaseSleepTimeMs ()). isEqualTo (1000 );
474+ assertThat (policy .getN ()). isEqualTo ( 3 );
470475 }
471476
472477 private void verifyDefaultAclProvider () {
@@ -478,21 +483,16 @@ private void verifyDefaultZKClientConfig() {
478483 verify (cfBuilder ).zkClientConfig (clientConfCaptor .capture ());
479484 ZKClientConfig conf = clientConfCaptor .getValue ();
480485
481- assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ), isEmptyOrFalse ());
486+ assertThat (conf .getProperty (ZKClientConfig .SECURE_CLIENT ))
487+ .satisfiesAnyOf (value -> assertThat (value ).isNullOrEmpty (),
488+ value -> assertThat (value ).isEqualTo ("false" ));
489+
482490 try (ClientX509Util sslOpts = new ClientX509Util ()) {
483- assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ()), isEmpty () );
484- assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ()), isEmpty () );
485- assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ()), isEmpty () );
486- assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ()), isEmpty () );
491+ assertThat (conf .getProperty (sslOpts .getSslKeystoreLocationProperty ())). isNullOrEmpty ( );
492+ assertThat (conf .getProperty (sslOpts .getSslKeystorePasswdProperty ())). isNullOrEmpty ( );
493+ assertThat (conf .getProperty (sslOpts .getSslTruststoreLocationProperty ())). isNullOrEmpty ( );
494+ assertThat (conf .getProperty (sslOpts .getSslTruststorePasswdProperty ())). isNullOrEmpty ( );
487495 }
488496 }
489497
490- private Matcher <String > isEmptyOrFalse () {
491- return anyOf (isEmpty (), is ("false" ));
492- }
493-
494- private Matcher <String > isEmpty () {
495- return anyOf (new IsNull <>(), is ("" ));
496- }
497-
498498}
0 commit comments