Skip to content

Instantly share code, notes, and snippets.

@rooZzz
Last active July 9, 2016 15:08
Show Gist options
  • Save rooZzz/abcb56f515eddd0630796924529119c2 to your computer and use it in GitHub Desktop.
Save rooZzz/abcb56f515eddd0630796924529119c2 to your computer and use it in GitHub Desktop.
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;
}
}
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