/** Test add follower. */
  @Test
  public void testAddFollower() {
    DomainGroup group = jpaGroupMapper.findByShortName("group1");

    Person fordp2 = jpaPersonMapper.findByAccountId("fordp2");
    Person csagan = jpaPersonMapper.findByAccountId("csagan");

    // Verify initial state
    assertFalse(jpaGroupMapper.isFollowing("fordp2", "group1"));
    assertFalse(jpaGroupMapper.isFollowing("csagan", "group1"));
    assertEquals(0, fordp2.getFollowingCount());
    assertEquals(0, fordp2.getGroupCount());
    assertEquals(0, csagan.getFollowingCount());
    assertEquals(1, csagan.getGroupCount());

    // ford wants to follow the group
    jpaGroupMapper.addFollower(fordp2.getId(), group.getId());

    getEntityManager().clear();

    fordp2 = jpaPersonMapper.findByAccountId("fordp2");
    csagan = jpaPersonMapper.findByAccountId("csagan");

    // verify new state
    assertTrue(jpaGroupMapper.isFollowing("fordp2", "group1"));
    // Test case insensitivity (everything should be lower cased by the mapper).
    assertTrue(jpaGroupMapper.isFollowing("fordp2", "Group1"));
    assertFalse(jpaGroupMapper.isFollowing("csagan", "group1"));
    assertEquals(0, fordp2.getFollowingCount());
    assertEquals(1, fordp2.getGroupCount());
    assertEquals(0, csagan.getFollowingCount());
    assertEquals(1, csagan.getGroupCount());

    // csagan wants to follow the group
    jpaGroupMapper.addFollower(csagan.getId(), group.getId());

    getEntityManager().clear();

    fordp2 = jpaPersonMapper.findByAccountId("fordp2");
    csagan = jpaPersonMapper.findByAccountId("csagan");

    // verify new state
    assertTrue(jpaGroupMapper.isFollowing("fordp2", "group1"));
    assertTrue(jpaGroupMapper.isFollowing("csagan", "group1"));
    // and verify csagan's counts after the change
    assertEquals(0, csagan.getFollowingCount());
    assertEquals(2, csagan.getGroupCount());
  }
  /** Test remove follower. */
  @Test
  @Transactional
  public void testRemoveFollower() {
    DomainGroup group = jpaGroupMapper.findByShortName("group1");
    Person burns = jpaPersonMapper.findByAccountId("mrburns");

    assertEquals(0, burns.getFollowingCount());
    assertEquals(1, burns.getGroupCount());
    assertEquals(3, group.getFollowersCount());
    assertTrue(jpaGroupMapper.isFollowing("mrburns", "group1"));

    jpaGroupMapper.removeFollower(burns.getId(), group.getId());
    getEntityManager().clear();
    group = jpaGroupMapper.findByShortName("group1");
    burns = jpaPersonMapper.findByAccountId("mrburns");

    assertEquals(0, burns.getFollowingCount());
    assertEquals(0, burns.getGroupCount());
    assertEquals(2, group.getFollowersCount());
    assertFalse(jpaGroupMapper.isFollowing("mrburns", "group1"));
  }