Last active
July 9, 2016 15:08
-
-
Save rooZzz/abcb56f515eddd0630796924529119c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package math; | |
class Counter { | |
private int counter; | |
Counter() { | |
counter = 0; | |
} | |
Counter increment() { | |
counter = 1; | |
return this; | |
} | |
Counter decrement() { | |
counter = -1; | |
return this; | |
} | |
int getCounter() { | |
return counter; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package math; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import static org.junit.Assert.assertEquals; | |
@RunWith(JUnit4.class) | |
public class CounterTest { | |
private Counter sut; | |
@Before | |
public void setup() { | |
sut = new Counter(); | |
} | |
@Test | |
public void whenInitialised_thenCounterIsZero() { | |
final int expected = 0; | |
final int actual = sut.getCounter(); | |
assertEquals(expected, actual); | |
} | |
@Test | |
public void whenIncrement_thenCounterIsPlusOne() { | |
final int expected = 1; | |
final int actual = sut.increment().getCounter(); | |
assertEquals(expected, actual); | |
} | |
@Test | |
public void whenDecrement_thenCounterIsMinusOne() { | |
final int expected = -1; | |
final int actual = sut.decrement().getCounter(); | |
assertEquals(expected, actual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment