Exemplo n.º 1
0
  @Test
  public void recordExpectationsOnNonStrictFinalLocalMockField() {
    YetAnotherCollaborator collaborator = new YetAnotherCollaborator();

    new Expectations() {
      @NonStrict final YetAnotherCollaborator mock3 = new YetAnotherCollaborator();

      {
        mock3.doSomething();
        times = 1;
      }
    };

    collaborator.doSomething();
    assertEquals(0, collaborator.getValue());
  }
Exemplo n.º 2
0
  @Test
  public void recordExpectationsOnStaticMethodAndConstructorOfFinalLocalMockField() {
    new Expectations() {
      @NonStrict final YetAnotherCollaborator unused = null;

      {
        new YetAnotherCollaborator(true);
        result = new RuntimeException();
        YetAnotherCollaborator.doSomethingStatic();
        result = 123;
      }
    };

    try {
      new YetAnotherCollaborator(true);
      fail();
    } catch (RuntimeException ignore) {
    }

    assertEquals(123, YetAnotherCollaborator.doSomethingStatic());
  }