I have the following JUnit tests, and can't work out why the second test does not pass, the value of i
is 1 in both tests.
public class TestTest {
private AtomicInteger ai = new AtomicInteger(1);
@Test
public void test1() {
int i = ai.getAndIncrement();
Assert.assertEquals(1, i);
}
@Test
public void test2() {
int i = ai.getAndIncrement();
Assert.assertEquals(2, i);
}
}
test1
passes and test2
fails with the following message:
java.lang.AssertionError:
Expected :2
Actual :1