@Test
 public void updateConnectionAccessFields() {
   insertFacebookConnection();
   Connection<TestFacebookApi> facebook =
       connectionRepository.getPrimaryConnection(TestFacebookApi.class);
   assertEquals("234567890", facebook.getApi().getAccessToken());
   facebook.refresh();
   connectionRepository.updateConnection(facebook);
   Connection<TestFacebookApi> facebook2 =
       connectionRepository.getPrimaryConnection(TestFacebookApi.class);
   assertEquals("765432109", facebook2.getApi().getAccessToken());
   ConnectionData data = facebook.createData();
   assertEquals("654321098", data.getRefreshToken());
 }
 @Test
 public void updateConnectionProfileFields() {
   connectionFactoryRegistry.addConnectionFactory(new TestTwitterConnectionFactory());
   insertTwitterConnection();
   Connection<TestTwitterApi> twitter =
       connectionRepository.getPrimaryConnection(TestTwitterApi.class);
   assertEquals("http://twitter.com/kdonald/picture", twitter.getImageUrl());
   twitter.sync();
   assertEquals("http://twitter.com/kdonald/a_new_picture", twitter.getImageUrl());
   connectionRepository.updateConnection(twitter);
   Connection<TestTwitterApi> twitter2 =
       connectionRepository.getPrimaryConnection(TestTwitterApi.class);
   assertEquals("http://twitter.com/kdonald/a_new_picture", twitter2.getImageUrl());
 }
 @Test
 public void findUserIdWithConnection() {
   insertFacebookConnection();
   List<String> userIds =
       usersConnectionRepository.findUserIdsWithConnection(
           connectionRepository.getPrimaryConnection(TestFacebookApi.class));
   assertEquals("1", userIds.get(0));
 }
 @Test
 public void addConnection() {
   Connection<TestFacebookApi> connection =
       connectionFactory.createConnection(new AccessGrant("123456789", null, "987654321", 3600L));
   connectionRepository.addConnection(connection);
   Connection<TestFacebookApi> restoredConnection =
       connectionRepository.getPrimaryConnection(TestFacebookApi.class);
   assertEquals(connection, restoredConnection);
   assertNewConnection(restoredConnection);
 }
 @Test
 public void findUserIdWithConnectionMultipleConnectionsToSameProviderUser() {
   insertFacebookConnection();
   insertFacebookConnectionSameFacebookUser();
   List<String> localUserIds =
       usersConnectionRepository.findUserIdsWithConnection(
           connectionRepository.getPrimaryConnection(TestFacebookApi.class));
   assertEquals(2, localUserIds.size());
   assertEquals("1", localUserIds.get(0));
   assertEquals("2", localUserIds.get(1));
 }
 @Test(expected = NotConnectedException.class)
 public void findPrimaryConnectionNotConnected() {
   connectionRepository.getPrimaryConnection(TestFacebookApi.class);
 }
 @Test
 public void findPrimaryConnectionSelectFromMultipleByRank() {
   insertFacebookConnection2();
   insertFacebookConnection();
   assertFacebookConnection(connectionRepository.getPrimaryConnection(TestFacebookApi.class));
 }
 @Test
 public void findPrimaryConnection() {
   insertFacebookConnection();
   assertFacebookConnection(connectionRepository.getPrimaryConnection(TestFacebookApi.class));
 }