2323import io .spine .core .TenantId ;
2424import io .spine .net .EmailAddress ;
2525import io .spine .net .InternetDomain ;
26- import org .hamcrest .BaseMatcher ;
27- import org .hamcrest .Description ;
28- import org .hamcrest .Matcher ;
2926import org .junit .jupiter .api .DisplayName ;
3027import org .junit .jupiter .api .Test ;
3128
29+ import static com .google .common .truth .Truth .assertThat ;
3230import static io .spine .protobuf .Messages .isDefault ;
33- import static org .hamcrest .MatcherAssert .assertThat ;
34- import static org .hamcrest .Matchers .isEmptyString ;
35- import static org .hamcrest .Matchers .not ;
36- import static org .junit .jupiter .api .Assertions .assertEquals ;
3731import static org .junit .jupiter .api .Assertions .assertNotNull ;
3832
3933@ DisplayName ("`SingleTenantNamespaceSupplier` should" )
@@ -45,9 +39,9 @@ void testProduceEmpty() {
4539 NamespaceSupplier supplier = NamespaceSupplier .singleTenant ();
4640 Namespace namespace = supplier .get ();
4741 assertNotNull (namespace );
48- assertThat (namespace .value (), isEmptyString () );
49- TenantId tenantId = namespace .toTenantId ();
50- assertThat (tenantId , isEffectivelyDefault () );
42+ assertThat (namespace .value ()). isEmpty ( );
43+ TenantId tenant = namespace .toTenantId ();
44+ assertThat (isEffectivelyDefault (tenant )). isTrue ( );
5145 }
5246
5347 @ Test
@@ -56,40 +50,24 @@ void testProduceCustom() {
5650 String namespaceValue = "my-custom-namespace" ;
5751 NamespaceSupplier supplier = NamespaceSupplier .singleTenant (namespaceValue );
5852 Namespace namespace = supplier .get ();
59- assertNotNull (namespace );
60- assertEquals ( namespaceValue , namespace .value ());
53+ assertThat (namespace ). isNotNull ( );
54+ assertThat ( namespace .value ()). isEqualTo ( namespaceValue );
6155
62- TenantId tenantId = namespace .toTenantId ();
63- assertThat (tenantId , not (isEffectivelyDefault ()));
64- String actualNamespaceValue = tenantId .getValue ();
65- assertEquals (namespaceValue , actualNamespaceValue );
56+ TenantId tenant = namespace .toTenantId ();
57+ assertThat (isEffectivelyDefault (tenant )).isFalse ();
58+ assertThat (tenant .getValue ()).isEqualTo (namespaceValue );
6659 }
6760
68- @ SuppressWarnings ("OverlyComplexAnonymousInnerClass" ) // OK for the test purposes
69- private static Matcher <TenantId > isEffectivelyDefault () {
70- return new BaseMatcher <TenantId >() {
71- @ Override
72- public boolean matches (Object item ) {
73- if (!(item instanceof TenantId )) {
74- return false ;
75- }
76- TenantId tenantId = (TenantId ) item ;
77- InternetDomain domain = tenantId .getDomain ();
78- if (!isDefault (domain )) {
79- return false ;
80- }
81- EmailAddress email = tenantId .getEmail ();
82- if (!isDefault (email )) {
83- return false ;
84- }
85- String value = tenantId .getValue ();
86- return value .isEmpty ();
87- }
88-
89- @ Override
90- public void describeTo (Description description ) {
91- description .appendText ("not default, as expected" );
92- }
93- };
61+ private static boolean isEffectivelyDefault (TenantId tenant ) {
62+ InternetDomain domain = tenant .getDomain ();
63+ if (!isDefault (domain )) {
64+ return false ;
65+ }
66+ EmailAddress email = tenant .getEmail ();
67+ if (!isDefault (email )) {
68+ return false ;
69+ }
70+ String value = tenant .getValue ();
71+ return value .isEmpty ();
9472 }
9573}
0 commit comments