@Test public void aDependencyInjectorShouldInitResetterWithRequiredDependencies() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final AccrualGroupRepository repository = mock(AccrualGroupRepository.class); resetter.init(repository); Field accrualGroupRepositoryField = AccrualGroupResetter.class.getDeclaredField("accrualGroupRepository"); accrualGroupRepositoryField.setAccessible(true); assertThat(accrualGroupRepositoryField.get(resetter), is(not(accrualGroupRepository))); assertThat(accrualGroupRepositoryField.get(resetter), is(repository)); }
@Test public void shouldResetAccrualGroupBeneficiaryCountAndAmountBeforePersistingChanges() { final UserSession us = mock(UserSession.class); final StateTransition transition = mock(StateTransition.class); final AccrualGroup target = new AccrualGroup(); target.setBeneficiaryCount(BigInteger.valueOf(17)); target.setAmount(BigDecimal.valueOf(13)); when(transition.getTarget()).thenReturn(target); resetter.handleTransition(transition, us); assertThat(target.getBeneficiaryCount(), is(BigInteger.ZERO)); assertThat(target.getAmount(), is(BigDecimal.ZERO)); verify(accrualGroupRepository).edit(target); }