http://code.google.com/p/powermock/issues/detail?id=354
UUID uuid = org.powermock.api.mockito.PowerMockito.mock(UUID.class)
returns an actual UUID instance and not a mock.
I have this class:
public class SecurityService {
public String generatePerishableToken() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
}
and the test class looks like:
@RunWith(PowerMockRunner.class)
@PrepareForTest({ SecurityService.class })
public class SecurityServiceTest {
private SecurityService service;
private UUID uuid;
@Before
public void setUp() {
service = new SecurityService();
uuid = mock(UUID.class);
}
@Test
public void testGeneratePerishableToken() {
// given
mockStatic(UUID.class);
given(UUID.randomUUID()).willReturn(uuid);
given(uuid.toString()).willReturn("my-perishable-token");
// when
String actual = service.generatePerishableToken();
// then
assertEquals("myperishabletoken", actual);
// TODO verify
}
}