package com.blogspot.toomuchcoding.book.chapter9.InjectingWithSpring; import com.blogspot.toomuchcoding.person.Person; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.BDDAssertions.then; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/chapter9/InjectingWithSpring/application-context.xml", "/chapter9/InjectingWithSpring/mock-application-context-with-spy.xml"}) public class TaxTransfererXmlConfigurationWithSpyTest { @Autowired TaxTransferer taxTransferer; @Autowired TaxService taxService; @Test public void should_transfer_tax_for_person() { // given Person person = new Person(); doNothing().when(taxService).transferTaxFor(person); // when boolean transferSuccessful = taxTransferer.transferTaxFor(person); // then then(transferSuccessful).isTrue(); verify(taxService).transferTaxFor(person); } }