### Question:
SocialContext implements ConnectionSignUp, SignInAdapter { public boolean isSignedIn(HttpServletRequest request, HttpServletResponse response) { boolean retVal = false; String userId = userCookieGenerator.readCookieValue(request); if (isValidId(userId)) { if (isConnectedFacebookUser(userId)) { retVal = true; } else { userCookieGenerator.removeCookie(response); } } currentUser.set(userId); return retVal; } SocialContext(UsersConnectionRepository connectionRepository, UserCookieGenerator userCookieGenerator,
			Facebook facebook); @Override String signIn(String userId, Connection<?> connection, NativeWebRequest request); @Override String execute(Connection<?> connection); boolean isSignedIn(HttpServletRequest request, HttpServletResponse response); String getUserId(); Facebook getFacebook();  }### Answer:
@Test public void testIsSignedInWithNoExistingCookieAvailable() throws Exception { expect(request.getCookies()).andReturn(null); replay(); boolean results = instance.isSignedIn(request, response); verify(); assertFalse(results); }
@Test public void testIsSignedInWithDisconnectedUser() throws Exception { final String COOKIE_NAME = "captain_debug_social_user"; final String COOKIE_VALUE = "qwerty"; Cookie[] cookies = new Cookie[1]; Cookie cookie = new Cookie(COOKIE_NAME, COOKIE_VALUE); cookies[0] = cookie; expect(request.getCookies()).andReturn(cookies); expect(userConnectionRespository.createConnectionRepository(COOKIE_VALUE)).andReturn(connectionRespository); expect(connectionRespository.findPrimaryConnection(Facebook.class)).andReturn(null); cookie = new Cookie(COOKIE_NAME, ""); response.addCookie(cookie); replay(); boolean result = instance.isSignedIn(request, response); verify(); assertFalse(result); }
@Test public void testIsSignedIn() { final String COOKIE_NAME = "captain_debug_social_user"; final String COOKIE_VALUE = "qwerty"; Cookie[] cookies = new Cookie[1]; Cookie cookie = new Cookie(COOKIE_NAME, COOKIE_VALUE); cookies[0] = cookie; expect(request.getCookies()).andReturn(cookies); expect(userConnectionRespository.createConnectionRepository(COOKIE_VALUE)).andReturn(connectionRespository); expect(connectionRespository.findPrimaryConnection(Facebook.class)).andReturn(facebookConnection); replay(); boolean result = instance.isSignedIn(request, response); verify(); assertTrue(result); }