示例#1
0
  private void assertUseCustomMatcher(TestInterface testObject) {
    String returnedValue = "returnedValue";
    String stringArg = "stringarg";
    int intArg = -1;
    Recorder<TestInterface> recorder = new Recorder<TestInterface>(testObject);
    recorder
        .record(
            testObject.methodWithArguments(
                (String)
                    recorder.matchObject(
                        new Matcher() {
                          @Override
                          public boolean matches(Object aActual) {
                            return ((String) aActual).startsWith("s");
                          }
                        }),
                recorder.matchInt(
                    new Matcher() {
                      @Override
                      public boolean matches(Object aActual) {
                        return ((Integer) aActual).intValue() < 0;
                      }
                    })))
        .andReturn(returnedValue);

    String actual = testObject.methodWithArguments(stringArg, intArg);
    assertEquals(actual, returnedValue);
  }
示例#2
0
  private void assertVoidMethodWithParamMatching(TestInterface testObject) {
    Recorder<TestInterface> recorder = new Recorder<TestInterface>(testObject);

    String arg = "arg";
    testObject.methodWithArguments(arg);
    recorder.recordForLastCall().andThrow(new RuntimeException());

    testObject.methodWithArguments("otherstring");
    testObject.methodWithArguments(arg);
  }
示例#3
0
  private void assertRecordingUseArgumentMatching(TestInterface testObject) {
    String stringArg = "arg";
    int intArg = 11;
    String returnedValue = "returnedValue";
    Recorder<TestInterface> recorder = TestObject.createRecorder(testObject);
    recorder.record(testObject.methodWithArguments(stringArg, intArg)).andReturn(returnedValue);

    String actual = testObject.methodWithArguments("otherArg", -1);
    assertNull(actual);

    actual = testObject.methodWithArguments(stringArg, intArg);
    assertEquals(actual, returnedValue);
  }
示例#4
0
  private void assertUseLooseArgumentMatching(TestInterface testObject) {
    String returnedValue = "returnedValue";
    Recorder<TestInterface> recorder = TestObject.createRecorder(testObject);
    recorder
        .record(
            testObject.methodWithArguments(
                (String) recorder.matchObject(Any.ANY), recorder.matchInt(Any.ANY)))
        .andReturn(returnedValue);

    String actual = testObject.methodWithArguments("otherArg", -1);
    ;
    assertEquals(actual, returnedValue);
  }
示例#5
0
  private void assertNullParametersMatched(TestInterface testObject) {
    String stringArg = null;
    int intArg = 11;
    String returnedValue = "returnedValue";
    Recorder<TestInterface> recorder = new Recorder<TestInterface>(testObject);
    recorder.record(testObject.methodWithArguments(stringArg, intArg)).andReturn(returnedValue);

    String actual = testObject.methodWithArguments("string", -1);
    assertNull(actual);

    actual = testObject.methodWithArguments(stringArg, intArg);
    assertEquals(actual, returnedValue);
  }
示例#6
0
  private void assertEqMatcher(TestInterface testObject) {
    String returnedValue = "returnedValue";
    String stringArg = "stringarg";
    int intArg = -1;
    Recorder<TestInterface> recorder = TestObject.createRecorder(testObject);
    recorder
        .record(
            testObject.methodWithArguments(
                (String) recorder.matchObject(new Eq(stringArg)),
                recorder.matchInt(new Eq(intArg))))
        .andReturn(returnedValue);

    String actual = testObject.methodWithArguments(stringArg, intArg);
    assertEquals(actual, returnedValue);
  }
示例#7
0
  private void assertReportWrongNumberOfMatchers(TestInterface testObject) {
    Recorder<TestInterface> recorder = TestObject.createRecorder(testObject);

    recorder
        .record(testObject.methodWithArguments((String) recorder.matchObject(Any.ANY), 10))
        .andReturn("value");
  }