Skip to content

Instantly share code, notes, and snippets.

@rooZzz rooZzz/Counter.java
Last active Jul 9, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.