Created
October 13, 2016 21:41
-
-
Save jirkapenzes/ea09ffeb835a960c8b6dfc7cde9fe800 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 demo; | |
public class Calculator { | |
enum Operation { | |
Addition, Subtraction | |
} | |
public int calculate(Operation operation, int a, int b) { | |
switch (operation) { | |
case Addition: | |
return addition(a, b); | |
case Subtraction: | |
return subtraction(a, b); | |
} | |
throw new RuntimeException("Unsupported exception"); | |
} | |
private int addition(int a, int b) { | |
return a + b; | |
} | |
private int subtraction(int a, int b) { | |
return a - b; | |
} | |
} |
This file contains hidden or 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 demo; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class CalculatorTest { | |
private Calculator calculator; | |
@Before | |
public void setUp() throws Exception { | |
calculator = new Calculator(); | |
} | |
@Test | |
public void shouldPerformAddition() throws Exception { | |
int actual = calculator.calculate(Calculator.Operation.Addition, 1, 3); | |
int expected = 4; | |
Assert.assertEquals(expected, actual); | |
} | |
@Test | |
public void shouldPerformSubtraction() throws Exception { | |
int actual = calculator.calculate(Calculator.Operation.Subtraction, 3, 1); | |
int expected = 2; | |
Assert.assertEquals(expected, actual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment