I am trying to make fun of the DateTimeFormatter class. I have done the following:
@RunWith(PowerMockRunner.class)
@PrepareForTest({DateTimeFormatter.class})
public class UnitTest {
private DateTimeFormatter mockDateFormatter;
private AwesomeClass awesomeClass;
@Before
public void setUp() {
mockDateFormatter = PowerMockito.mock(DateTimeFormatter.class);
awesomeClass = new AwesomeClass(mockDateFormatter);
}
@Test
public void shouldToTestSomethingAwesome() {
PowerMockito.when(mockDateFormatter.format(any(LocalDate.class)))
.thenReturn("20150224");
}
AwesomeClassuses it for formatting LocalDateTime.now(ZoneId.of("UTC"));. Then the formatted string is used to generate another string. I need to make sure the string is correctly generated. Therefore, I need to return a consistent date either from formatting, or state the static method LocalDateTime.now (..)
What am I doing wrong?
source
share