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); }
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); }
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); }
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); }
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); }
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); }
private void assertReportWrongNumberOfMatchers(TestInterface testObject) { Recorder<TestInterface> recorder = TestObject.createRecorder(testObject); recorder .record(testObject.methodWithArguments((String) recorder.matchObject(Any.ANY), 10)) .andReturn("value"); }