Skip to content

Commit 8273407

Browse files
committed
Improve test caching wot service.
1 parent fa280a0 commit 8273407

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

hub/src/test/java/ch/iterate/hub/workflows/CachingWoTServiceTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import org.mockito.Mockito;
99

1010
import java.text.ParseException;
11+
import java.util.HashMap;
1112

1213
import ch.iterate.hub.client.ApiException;
14+
import ch.iterate.hub.client.model.TrustedUserDto;
1315
import ch.iterate.hub.workflows.exceptions.AccessException;
1416
import ch.iterate.hub.workflows.exceptions.SecurityFailure;
1517
import com.nimbusds.jose.JOSEException;
1618

19+
import static org.junit.jupiter.api.Assertions.assertEquals;
1720
import static org.mockito.ArgumentMatchers.any;
1821
import static org.mockito.Mockito.times;
1922

@@ -22,10 +25,15 @@ class CachingWoTServiceTest {
2225
@Test
2326
void testGetTrustLevelsPerUserId() throws AccessException, SecurityFailure, ApiException {
2427
final WoTService proxyMock = Mockito.mock(WoTService.class);
28+
final HashMap<String, Integer> trustLevels = new HashMap<String, Integer>() {{
29+
put("alkdajf", 5);
30+
put("lakdjfa", 42);
31+
}};
32+
Mockito.when(proxyMock.getTrustLevelsPerUserId(any())).thenReturn(trustLevels);
2533
final CachingWoTService service = new CachingWoTService(proxyMock);
26-
service.getTrustLevelsPerUserId(null);
34+
assertEquals(trustLevels, service.getTrustLevelsPerUserId(null));
2735
Mockito.verify(proxyMock, times(1)).getTrustLevelsPerUserId(any());
28-
service.getTrustLevelsPerUserId(null);
36+
assertEquals(trustLevels, service.getTrustLevelsPerUserId(null));
2937
Mockito.verify(proxyMock, times(1)).getTrustLevelsPerUserId(any());
3038
}
3139

@@ -42,10 +50,12 @@ void testVerify() throws AccessException, SecurityFailure, ApiException {
4250
@Test
4351
void testSign() throws AccessException, SecurityFailure, ParseException, JOSEException, ApiException {
4452
final WoTService proxyMock = Mockito.mock(WoTService.class);
53+
final TrustedUserDto trustedUser = new TrustedUserDto();
54+
Mockito.when(proxyMock.sign(any(), any())).thenReturn(trustedUser);
4555
final CachingWoTService service = new CachingWoTService(proxyMock);
46-
service.sign(null, null);
56+
assertEquals(trustedUser, service.sign(null, null));
4757
Mockito.verify(proxyMock, times(1)).sign(any(), any());
48-
service.sign(null, null);
58+
assertEquals(trustedUser, service.sign(null, null));
4959
Mockito.verify(proxyMock, times(2)).sign(any(), any());
5060
}
5161
}

0 commit comments

Comments
 (0)