### Question:
OAuthUserProvider extends AbstractProvider<OAuthUser> { @Override public OAuthUser take() { var user = userSessionRepository.take().getUser(); if (user instanceof OAuthUser) { return (OAuthUser) user; } throw new NoUserFoundException("No OAuth users found in the repository."); } OAuthUserProvider();  OAuthUserProvider(final CyclicUserSessionRepository<UserSession> userSessionRepository); @Override OAuthUser take(); OAuthUser take(User excludedUser); @Override String name();  }### Answer:
@Test public void testTake() { var oAuthUser = new OAuthUserImpl(null, TEST_USER_1, TEST_PW, ACCESS_TOKEN, REFRESH_TOKEN, SCOPE, CLIENT_ID, USER_ID, US_REGION ); var usUserSession = new UserSessionImpl(oAuthUser); when(repo.take()).thenReturn(usUserSession); var authUserProvider = new OAuthUserProvider(repo); assertThat(authUserProvider.take(), equalTo(usUserSession.getUser())); }
@Test public void testTakeDifferentUsers() { var oAuthUser1 = new OAuthUserImpl(null, TEST_USER_1, TEST_PW, ACCESS_TOKEN, REFRESH_TOKEN, SCOPE, CLIENT_ID, USER_ID, US_REGION ); var usUserSession1 = new UserSessionImpl(oAuthUser1); var oAuthUser2 = new OAuthUserImpl(null, TEST_USER_2, TEST_PW, ACCESS_TOKEN, REFRESH_TOKEN, SCOPE, CLIENT_ID, USER_ID, US_REGION ); var usUserSession2 = new UserSessionImpl(oAuthUser2); when(repo.take()).thenReturn(usUserSession1, usUserSession2); var authUserProvider = new OAuthUserProvider(repo); assertThat(authUserProvider.take(usUserSession1.getUser()), not(equalTo(usUserSession1.getUser()))); }
@Test(expected = NoUserFoundException.class) public void testTakeSameUserWhileExpectingAnother() { var oAuthUser1 = new OAuthUserImpl(null, TEST_USER_1, TEST_PW, ACCESS_TOKEN, REFRESH_TOKEN, SCOPE, CLIENT_ID, USER_ID, US_REGION ); var userSession = new UserSessionImpl(oAuthUser1); when(repo.take()).thenReturn(userSession, userSession, userSession); var authUserProvider = new OAuthUserProvider(repo); assertThat(authUserProvider.take(userSession.getUser()), not(equalTo(userSession.getUser()))); }