/** Test correct method on mapper is called. */ @Test public void testRemovePersistentLogin() { final PersistentLoginMapper loginMapper = context.mock(PersistentLoginMapper.class); context.checking( new Expectations() { { oneOf(loginMapper).deletePersistentLogin(with("theuser")); } }); PersistentLoginRepositoryImpl sut = new PersistentLoginRepositoryImpl(loginMapper); sut.removePersistentLogin("theuser"); context.assertIsSatisfied(); }
/** Test correct method on mapper is called. */ @Test public void testCreateOrUpdatePersistentLogin() { final PersistentLoginMapper loginMapper = context.mock(PersistentLoginMapper.class); final PersistentLogin login = context.mock(PersistentLogin.class); context.checking( new Expectations() { { oneOf(loginMapper).createOrUpdate(with(login)); } }); PersistentLoginRepositoryImpl sut = new PersistentLoginRepositoryImpl(loginMapper); sut.createOrUpdatePersistentLogin(login); context.assertIsSatisfied(); }
/** Test that exception is swallowed and null is returned if mapper throws exception. */ @Test public void testGetPersistentLoginDataFail() { final PersistentLoginMapper loginMapper = context.mock(PersistentLoginMapper.class); context.checking( new Expectations() { { oneOf(loginMapper).findByAccountId(with("theuser")); will(throwException(new Exception())); } }); PersistentLoginRepositoryImpl sut = new PersistentLoginRepositoryImpl(loginMapper); assertNull("Should return null if mapper throws exception.", sut.getPersistentLogin("theuser")); context.assertIsSatisfied(); }
/** Test correct method on mapper is called and that PersistentLogin is returned to caller. */ @Test public void testGetPersistentLoginDataSuccess() { final PersistentLoginMapper loginMapper = context.mock(PersistentLoginMapper.class); final PersistentLogin login = context.mock(PersistentLogin.class); context.checking( new Expectations() { { oneOf(loginMapper).findByAccountId(with("theuser")); will(returnValue(login)); } }); PersistentLoginRepositoryImpl sut = new PersistentLoginRepositoryImpl(loginMapper); assertNotNull( "Did not return PersistentLogin retreived from DB", sut.getPersistentLogin("theuser")); context.assertIsSatisfied(); }