コード例 #1
0
  @Test
  public void importMocksFromMultipleExpectationBlocks() {
    SubDependency subDependency = new SubDependency();

    new NonStrictExpectations() {
      Dependency mock;
    };

    new NonStrictExpectations() {
      SubDependency mock;

      {
        mock.notifyBeforeSave();
        result = true;
      }
    };

    subDependency.notifyBeforeSave();

    new FullVerificationsInOrder() {
      Dependency mock1;
      SubDependency mock2;

      {
        mock1.editABunchMoreStuff();
        times = 0;
        mock2.notifyBeforeSave();
      }
    };
  }
コード例 #2
0
  @Test(expected = UnexpectedInvocation.class)
  public void verifyAllInvocationsToSubclassMethods_whenNotVerified(final SubDependency mock2) {
    mock.prepare();
    mock2.getValue();

    new FullVerificationsInOrder(1, mock2.getClass()) {
      {
        mock.prepare();
      }
    };
  }
コード例 #3
0
  @Test
  public void verifyAllInvocationsToSubclassMethods(final SubDependency mock2) {
    mock.prepare();
    mock2.getValue();

    new FullVerifications(1, mock2.getClass()) {
      {
        mock2.getValue();
      }
    };
  }
コード例 #4
0
  @Test(expected = UnexpectedInvocation.class)
  public void verifyAllInvocationsToMethodsOfBaseClassAndOfSubclass_whenInheritedMethodNotVerified(
      final SubDependency mock2) {
    mock2.prepare();
    mock2.getValue();

    new FullVerificationsInOrder(mock2) {
      {
        mock2.getValue();
      }
    };
  }
コード例 #5
0
  @Test
  public void verifyAllInvocationsToMethodsOfBaseClassAndOfSubclass(final SubDependency mock2) {
    mock2.prepare();
    mock2.getValue();

    new FullVerifications(mock2) {
      {
        mock2.prepare();
        mock2.getValue();
      }
    };
  }
コード例 #6
0
  @Test
  public void importMocksFromExpectationBlocksWhereTheFirstHasNoMockFields(
      final SubDependency sub) {
    new NonStrictExpectations() {
      {
        sub.setSomethingElse(anyString);
        result = 1;
      }
    };

    new NonStrictExpectations() {
      Dependency mock;

      {
        mock.notifyBeforeSave();
        result = true;
      }
    };

    sub.notifyBeforeSave();
    sub.notifyBeforeSave();

    new Verifications() {
      Dependency mock1;
      SubDependency mock2;

      {
        mock1.notifyBeforeSave();
        minTimes = 2;
      }
    };
  }
コード例 #7
0
  @Test(expected = UnexpectedInvocation.class)
  public void unverifiedStaticInvocationForSpecifiedSubclassInstance(final SubDependency mock2) {
    mock2.getValue();
    Dependency.staticMethod("test");

    new FullVerificationsInOrder(1, mock2) {
      {
        mock2.getValue();
      }
    };
  }
コード例 #8
0
  @Test
  public void verifyAllInvocationsToInheritedMethods(SubDependency mock2) {
    mock.prepare();
    mock2.getValue();

    new FullVerificationsInOrder(1, mock) {
      {
        mock.prepare();
      }
    };
    new FullVerificationsInOrder(Dependency.class) {
      {
        mock.prepare();
      }
    };
  }