It's easier, but a little sloppy. As the title suggests, we use PowerMockito.
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
public class MyTest {
@Test
public void test() {
final Integer a = mock(Integer.class);
when(a.intValue()).thenReturn(1, 2, 3);
assertTrue(a == 1 && a == 2 && a == 3);
}
}
As you know, PowerMockito is a library that allows you to create mockups of the final
class and make them various.
Auto unboxing allows you to compare a ʻInteger object with a primitive ʻint
by ==
.
Also, since ʻInteger # intValue` is called in auto unboxing, the values to be returned at this time were specified in order with PowerMockito.
Recommended Posts