TwitterSession extends Session<TwitterAuthToken> { @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (userName != null ? userName.hashCode() : 0); return result; } TwitterSession(TwitterAuthToken authToken, long userId, String userName); long getUserId(); String getUserName(); @Override boolean equals(Object o); @Override int hashCode(); static final long UNKNOWN_USER_ID; static final String UNKNOWN_USER_NAME; }
@Test public void testEquals_sameObjects() throws Exception { final TwitterSession session = new TwitterSession( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.USER_ID, TestFixtures.SCREEN_NAME); final TwitterSession newSession = new TwitterSession( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.USER_ID, TestFixtures.SCREEN_NAME); assertEquals(session.hashCode(), newSession.hashCode()); assertEquals(session, newSession); }
@Test public void testEquals_sameObjectsWithNullUserName() throws Exception { final TwitterSession session = new TwitterSession( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.USER_ID, null); final TwitterSession newSession = new TwitterSession( new TwitterAuthToken(TestFixtures.TOKEN, TestFixtures.SECRET), TestFixtures.USER_ID, null); assertEquals(session.hashCode(), newSession.hashCode()); assertEquals(session, newSession); }