Ejemplo n.º 1
0
 @Test(expected = PositionException.class)
 public void testNoPosition() {
   EasyMock.expect(calcMethod.calc(Position.BOSS)).andReturn(70000.0);
   EasyMock.replay(calcMethod);
   calc.setCalcMethod(calcMethod);
   calc.calc();
 }
Ejemplo n.º 2
0
  @Test(expected = PositionException.class)
  public void testCalc2() {
    // Setting up the expected value of the method call calc
    EasyMock.expect(calcMethod.calc(Position.SURFER))
        .andThrow(new PositionException("Don't know this guy"))
        .times(1);

    // Setup is finished need to activate the mock
    EasyMock.replay(calcMethod);
    calc.setPosition(Position.SURFER);
    calc.setCalcMethod(calcMethod);
    calc.calc();
  }
Ejemplo n.º 3
0
  @Test
  public void testCalc1() {
    // Setting up the expected value of the method call calc
    EasyMock.expect(calcMethod.calc(Position.BOSS)).andReturn(70000.0).times(2);
    EasyMock.expect(calcMethod.calc(Position.PROGRAMMER)).andReturn(50000.0);
    // Setup is finished need to activate the mock
    EasyMock.replay(calcMethod);

    calc.setCalcMethod(calcMethod);
    try {
      calc.calc();
      fail("Exception did not occur");
    } catch (PositionException e) {

    }
    calc.setPosition(Position.BOSS);
    assertEquals(70000.0, calc.calc());
    assertEquals(70000.0, calc.calc());
    calc.setPosition(Position.PROGRAMMER);
    assertEquals(50000.0, calc.calc());
    calc.setPosition(Position.SURFER);
    EasyMock.verify(calcMethod);
  }