Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.fail;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Ignore;
- import org.junit.Test;
- public class CalculatorTest {
- private static Calculator calculator;
- @BeforeClass
- public static void setUpClass() throws Exception {
- calculator = new Calculator();
- }
- @AfterClass
- public static void tearDownClass() throws Exception {
- calculator.switchOff();
- }
- @Before
- public void setUp() throws Exception {
- calculator.clear();
- }
- @After
- public void tearDown() throws Exception {
- calculator.clear();
- }
- /**
- * Test of add method, of class Calculator.
- */
- @Test
- public void testAdd() {
- System.out.println("add");
- int n = 0;
- calculator.set(0);
- calculator.add(5);
- assertEquals(5, calculator.getResult());
- }
- /**
- * Test of substract method, of class Calculator.
- */
- @Test
- public void testSubstract() {
- System.out.println("substract");
- int n = 3;
- calculator.set(5);
- calculator.substract(n);
- assertEquals(2, calculator.getResult());
- }
- /**
- * Test of multiply method, of class Calculator.
- */
- @Test
- public void testMultiply() {
- System.out.println("multiply");
- int n = 2;
- calculator.set(4);
- calculator.multiply(n);
- assertEquals(8, calculator.getResult());
- }
- /**
- * Test of divide method, of class Calculator.
- */
- @Test(/* expected= ArithmeticException.class */)
- public void testDivide() {
- System.out.println("divide");
- int n = 0;
- calculator.set(10);
- calculator.divide(n);
- }
- /**
- * Test of square method, of class Calculator.
- */
- @Test
- public void testSquare() {
- System.out.println("square");
- int n = 0;
- calculator.square(n);
- }
- /**
- * Test of squareRoot method, of class Calculator.
- */
- @Test
- public void testSquareRoot() {
- System.out.println("squareRoot");
- int n = 0;
- calculator.set(0);
- calculator.squareRoot(n);
- }
- /**
- * Test of clear method, of class Calculator.
- */
- @Test
- // @Ignore
- public void testClear() {
- System.out.println("clear");
- Calculator instance = new Calculator();
- instance.clear();
- // TODO review the generated test code and remove the default call to
- // fail.
- fail("The test case is a prototype.");
- }
- /**
- * Test of switchOn method, of class Calculator.
- */
- @Test
- public void testSwitchOn() {
- System.out.println("switchOn");
- calculator.switchOn();
- }
- /**
- * Test of switchOff method, of class Calculator.
- */
- @Test
- public void testSwitchOff() {
- System.out.println("switchOff");
- calculator.switchOff();
- }
- /**
- * Test of getResult method, of class Calculator.
- */
- @Test
- public void testGetResult() {
- System.out.println("getResult");
- int expResult = 0;
- int result = calculator.getResult();
- assertEquals(expResult, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement