1414import  java .util .Map ;
1515import  java .util .Set ;
1616
17- import  org .hamcrest .MatcherAssert ;
1817import  org .junit .Test ;
1918
2019import  org .opensearch .common .xcontent .XContentFactory ;
3130
3231import  org .mockito .Mockito ;
3332
33+ import  static  org .hamcrest .MatcherAssert .assertThat ;
3434import  static  org .hamcrest .Matchers .contains ;
3535import  static  org .hamcrest .Matchers .equalTo ;
3636import  static  org .hamcrest .Matchers .is ;
3737import  static  org .hamcrest .Matchers .notNullValue ;
3838import  static  org .hamcrest .Matchers .nullValue ;
39+ import  static  org .hamcrest .Matchers .sameInstance ;
3940import  static  org .junit .Assert .assertThrows ;
4041import  static  org .mockito .ArgumentMatchers .any ;
4142import  static  org .mockito .ArgumentMatchers .eq ;
@@ -62,16 +63,16 @@ public void testFromXContentWhenCurrentTokenIsNotStartObject() throws IOExceptio
6263
6364        ShareWith  shareWith  = ShareWith .fromXContent (parser );
6465
65-         MatcherAssert . assertThat (shareWith , notNullValue ());
66+         assertThat (shareWith , notNullValue ());
6667        Recipients  readOnly  = shareWith .atAccessLevel ("read_only" );
67-         MatcherAssert . assertThat (readOnly , notNullValue ());
68+         assertThat (readOnly , notNullValue ());
6869
6970        Map <Recipient , Set <String >> recipients  = readOnly .getRecipients ();
70-         MatcherAssert . assertThat (recipients , notNullValue ());
71-         MatcherAssert . assertThat (recipients .get (Recipient .USERS ).size (), is (1 ));
72-         MatcherAssert . assertThat (recipients .get (Recipient .USERS ), contains ("user1" ));
73-         MatcherAssert . assertThat (recipients .get (Recipient .ROLES ).size (), is (0 ));
74-         MatcherAssert . assertThat (recipients .get (Recipient .BACKEND_ROLES ).size (), is (0 ));
71+         assertThat (recipients , notNullValue ());
72+         assertThat (recipients .get (Recipient .USERS ).size (), is (1 ));
73+         assertThat (recipients .get (Recipient .USERS ), contains ("user1" ));
74+         assertThat (recipients .get (Recipient .ROLES ).size (), is (0 ));
75+         assertThat (recipients .get (Recipient .BACKEND_ROLES ).size (), is (0 ));
7576    }
7677
7778    @ Test 
@@ -81,9 +82,9 @@ public void testFromXContentWithEmptyInput() throws IOException {
8182
8283        ShareWith  result  = ShareWith .fromXContent (parser );
8384
84-         MatcherAssert . assertThat (result , notNullValue ());
85-         MatcherAssert . assertThat (result .isPrivate (), is (true ));
86-         MatcherAssert . assertThat (result .isPublic (), is (false ));
85+         assertThat (result , notNullValue ());
86+         assertThat (result .isPrivate (), is (true ));
87+         assertThat (result .isPublic (), is (false ));
8788    }
8889
8990    @ Test 
@@ -110,22 +111,22 @@ public void testFromXContentWithStartObject() throws IOException {
110111
111112        ShareWith  shareWith  = ShareWith .fromXContent (parser );
112113
113-         MatcherAssert . assertThat (shareWith , notNullValue ());
114+         assertThat (shareWith , notNullValue ());
114115
115116        Recipients  defaultAccessLevel  = shareWith .atAccessLevel ("default" );
116117
117118        Recipients  readOnly  = shareWith .atAccessLevel ("read-only" );
118119
119-         MatcherAssert . assertThat (defaultAccessLevel , notNullValue ());
120-         MatcherAssert . assertThat (readOnly , notNullValue ());
120+         assertThat (defaultAccessLevel , notNullValue ());
121+         assertThat (readOnly , notNullValue ());
121122
122-         MatcherAssert . assertThat (defaultAccessLevel .getRecipientsByType (Recipient .USERS ).size (), is (2 ));
123-         MatcherAssert . assertThat (defaultAccessLevel .getRecipientsByType (Recipient .ROLES ).size (), is (1 ));
124-         MatcherAssert . assertThat (defaultAccessLevel .getRecipientsByType (Recipient .BACKEND_ROLES ).size (), is (1 ));
123+         assertThat (defaultAccessLevel .getRecipientsByType (Recipient .USERS ).size (), is (2 ));
124+         assertThat (defaultAccessLevel .getRecipientsByType (Recipient .ROLES ).size (), is (1 ));
125+         assertThat (defaultAccessLevel .getRecipientsByType (Recipient .BACKEND_ROLES ).size (), is (1 ));
125126
126-         MatcherAssert . assertThat (readOnly .getRecipientsByType (Recipient .USERS ).size (), is (1 ));
127-         MatcherAssert . assertThat (readOnly .getRecipientsByType (Recipient .ROLES ).size (), is (1 ));
128-         MatcherAssert . assertThat (readOnly .getRecipientsByType (Recipient .BACKEND_ROLES ).size (), is (1 ));
127+         assertThat (readOnly .getRecipientsByType (Recipient .USERS ).size (), is (1 ));
128+         assertThat (readOnly .getRecipientsByType (Recipient .ROLES ).size (), is (1 ));
129+         assertThat (readOnly .getRecipientsByType (Recipient .BACKEND_ROLES ).size (), is (1 ));
129130    }
130131
131132    @ Test 
@@ -136,9 +137,9 @@ public void testFromXContentWithUnexpectedEndOfInput() throws IOException {
136137
137138        ShareWith  result  = ShareWith .fromXContent (mockParser );
138139
139-         MatcherAssert . assertThat (result , notNullValue ());
140-         MatcherAssert . assertThat (result .isPrivate (), is (true ));
141-         MatcherAssert . assertThat (result .isPublic (), is (false ));
140+         assertThat (result , notNullValue ());
141+         assertThat (result .isPrivate (), is (true ));
142+         assertThat (result .isPublic (), is (false ));
142143    }
143144
144145    @ Test 
@@ -155,8 +156,8 @@ public void testToXContentBuildsCorrectly() throws IOException {
155156
156157        String  expected  = "{\" actionGroup1\" :{\" users\" :[\" bleh\" ]}}" ;
157158
158-         MatcherAssert . assertThat (expected .length (), equalTo (result .length ()));
159-         MatcherAssert . assertThat (expected , equalTo (result ));
159+         assertThat (expected .length (), equalTo (result .length ()));
160+         assertThat (expected , equalTo (result ));
160161    }
161162
162163    @ Test 
@@ -206,8 +207,8 @@ public void test_fromXContent_emptyObject() throws IOException {
206207
207208        ShareWith  shareWith  = ShareWith .fromXContent (parser );
208209
209-         MatcherAssert . assertThat (shareWith .isPrivate (), is (true ));
210-         MatcherAssert . assertThat (shareWith .isPublic (), is (false ));
210+         assertThat (shareWith .isPrivate (), is (true ));
211+         assertThat (shareWith .isPublic (), is (false ));
211212    }
212213
213214    @ Test 
@@ -241,7 +242,7 @@ public void testAdd_NewAndMerge() {
241242        // existing level merged 
242243        verify (orig , times (1 )).share (patchRec );
243244        // new level added 
244-         MatcherAssert . assertThat (result .atAccessLevel ("write" ), equalTo (patchRec ));
245+         assertThat (result .atAccessLevel ("write" ), equalTo (patchRec ));
245246    }
246247
247248    @ Test 
@@ -260,7 +261,25 @@ public void testRevoke_ExistingAndNoop() {
260261        // revoke called on existing 
261262        verify (orig , times (1 )).revoke (revokeRec );
262263        // non-existing level noop 
263-         MatcherAssert .assertThat (result .atAccessLevel ("write" ), nullValue ());
264+         assertThat (result .atAccessLevel ("write" ), nullValue ());
265+     }
266+ 
267+     @ Test 
268+     public  void  testRevoke_NonExisting () {
269+         ShareWith  base  = new  ShareWith (new  HashMap <>());
270+         Recipients  revokeRec  = mock (Recipients .class );
271+         Map <String , Recipients > revokeMap  = new  HashMap <>();
272+         revokeMap .put ("read" , revokeRec );
273+         revokeMap .put ("write" , revokeRec );
274+         ShareWith  revokeSw  = new  ShareWith (revokeMap );
275+ 
276+         assertThat (base .getSharingInfo ().size (), is (0 ));
277+ 
278+         ShareWith  result  = base .revoke (revokeSw );
279+         // revoke called on existing 
280+         assertThat ("Revoke on empty base should return the same object" , result , sameInstance (base ));
281+         // assert no levels were added or removed 
282+         assertThat (result .getSharingInfo ().size (), is (0 ));
264283    }
265284
266285    @ Test 
0 commit comments