### Question:
SecurityChecker { public static void checkAnyUser() { if (!SecurityContextHolder.get().userId().isPresent()) { throw new CredentialsMissingException(); } }  static void checkUser(final String userId); static void checkTeam(final String teamId); static void checkAnyUser(); static void checkAnyTeam();  }### Answer:
@Test public void shouldPassAnyUserCheck_withUserIdInSecurityContext() { when(mockSecurityContext.userId()).thenReturn(Optional.of(randomId())); Exception thrownException = null; try { SecurityChecker.checkAnyUser(); } catch (final Exception e) { thrownException = e; } assertNull(thrownException); }
@Test public void shouldNotPassAnyUserCheck_withNoUserIdInSecurityContext() { when(mockSecurityContext.userId()).thenReturn(Optional.empty()); CredentialsMissingException thrownException = null; try { SecurityChecker.checkAnyUser(); } catch (final CredentialsMissingException e) { thrownException = e; } assertNotNull(thrownException); }