### Question:
SecurityChecker { public static void checkTeam(final String teamId) { checkAnyTeam(); final String contextTeamId = SecurityContextHolder.get().teamId().get(); if (!contextTeamId.equals(teamId)) { throw new SecurityConstraintViolationException("Access denied for team: " + contextTeamId); } }  static void checkUser(final String userId); static void checkTeam(final String teamId); static void checkAnyUser(); static void checkAnyTeam();  }### Answer:
@Test public void shouldPassTeamCheck_withMatchingTeamIdInSecurityContext() { final String teamId = randomId(); when(mockSecurityContext.teamId()).thenReturn(Optional.of(teamId)); Exception thrownException = null; try { SecurityChecker.checkTeam(teamId); } catch (final Exception e) { thrownException = e; } assertNull(thrownException); }
@Test public void shouldNotPassTeamCheck_withNoTeamIdInSecurityContext() { final String teamId = randomId(); when(mockSecurityContext.teamId()).thenReturn(Optional.empty()); CredentialsMissingException thrownException = null; try { SecurityChecker.checkTeam(teamId); } catch (final CredentialsMissingException e) { thrownException = e; } assertNotNull(thrownException); }
@Test public void shouldNotPassTeamCheck_withDifferentTeamIdInSecurityContext() { final String teamId = randomId(); when(mockSecurityContext.teamId()).thenReturn(Optional.of(randomId())); SecurityConstraintViolationException thrownException = null; try { SecurityChecker.checkTeam(teamId); } catch (final SecurityConstraintViolationException e) { thrownException = e; } assertNotNull(thrownException); }