package com.blogspot.toomuchcoding.book.chapter2._2_CreatingMocksByAnnotations.hamcrest; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.*; import static org.mockito.BDDMockito.*; import static org.mockito.Matchers.any; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import com.blogspot.toomuchcoding.book.chapter2.common.MeanTaxFactorCalculator; import com.blogspot.toomuchcoding.book.chapter2.common.TaxService; import com.blogspot.toomuchcoding.person.Person; @RunWith(MockitoJUnitRunner.class) public class MeanTaxFactorCalculatorTest { static final double TAX_FACTOR = 10; @Mock TaxService taxService; @InjectMocks MeanTaxFactorCalculator systemUnderTest; @Test public void should_calculate_mean_tax_factor() { // given given(taxService.getCurrentTaxFactorFor(any(Person.class))).willReturn(TAX_FACTOR); // when double meanTaxFactor = systemUnderTest.calculateMeanTaxFactorFor(new Person()); // then assertThat(meanTaxFactor, equalTo(TAX_FACTOR)); } }