### Question:
DefaultSecurityContext implements SecurityContext { @Override public Optional<String> userId() { return userId; } DefaultSecurityContext(final String userId, final String teamId, final String agentUserId,
            final String appId);  DefaultSecurityContext(final String userId, final String teamId);  DefaultSecurityContext(final String userId); @Override @Deprecated String principal(); @Override Optional<String> userId(); @Override Optional<String> teamId(); @Override Optional<String> agentUserId(); @Override Optional<String> appId();  }### Answer:
@Test public void shouldReturnUserId_withUserInContext() { final String userId = randomId(); final String teamId = randomBoolean() ? null : randomId(); final String agentUserId = randomBoolean() ? null : randomId(); final String appId = randomBoolean() ? null : randomId(); final DefaultSecurityContext context = new DefaultSecurityContext(userId, teamId, agentUserId, appId); final Optional<String> returnedUserId = context.userId(); assertEquals(Optional.of(userId), returnedUserId); }
@Test public void shouldReturnEmptyUserId_withNoUserInContext() { final String userId = null; final String teamId = null; final String agentUserId = null; final String appId = null; final DefaultSecurityContext context = new DefaultSecurityContext(userId, teamId, agentUserId, appId); final Optional<String> returnedUserId = context.userId(); assertEquals(Optional.empty(), returnedUserId); }