use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class StubMethodTest method whenStubbingInstanceMethodByPassingTheMethodTheMethodReturnsTheStubbedValue.
@Test
public void whenStubbingInstanceMethodByPassingTheMethodTheMethodReturnsTheStubbedValue() throws Exception {
String expected = "Hello";
stub(method(SuppressMethod.class, "getObject")).toReturn(expected);
SuppressMethod tested = new SuppressMethod();
assertEquals(expected, tested.getObject());
assertEquals(expected, tested.getObject());
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class StubMethodTest method whenStubbingInstanceMethodWithWrongReturnTypeThenClasscastExceptionIsThrown.
@Test(expected = ClassCastException.class)
public void whenStubbingInstanceMethodWithWrongReturnTypeThenClasscastExceptionIsThrown() throws Exception {
String illegalReturnType = "Hello";
stub(method(SuppressMethod.class, "getFloat")).toReturn(illegalReturnType);
SuppressMethod tested = new SuppressMethod();
tested.getFloat();
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class SupressMethodExampleTest method verifySuppression.
@Test
public void verifySuppression() throws Exception {
getObjectSuppression.doIt();
getIntSuppression.doIt();
fieldSuppression.doIt();
assertEquals("getObject return-value", getObjectSuppression.expectedReturnValue, new SuppressMethod().getObject());
assertEquals("getInt return-value", getIntSuppression.expectedReturnValue, new SuppressMethod().getInt());
assertThat("Value from field", new SuppressField().getDomainObject(), is(fieldSuppression.expectation));
if (suppressConstructor) {
suppress(constructor(SuppressConstructorHierarchy.class));
} else {
expectedException.expect(RuntimeException.class);
}
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
assertTrue("Or a runtime exception should have been thrown by now", suppressConstructor);
assertEquals(42, tested.getNumber());
assertNull(tested.getMessage());
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class MemberModificationExampleTest method changingReturnValueExample.
@Test
public void changingReturnValueExample() throws Exception {
replace(method(SuppressMethod.class, "getObjectWithArgument")).with(new ReturnValueChangingInvocationHandler());
final SuppressMethod tested = new SuppressMethod();
assertThat(tested.getObjectWithArgument("don't do anything"), is(instanceOf(Object.class)));
assertEquals("hello world", tested.getObjectWithArgument("make it a string"));
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class MemberModificationExampleTest method suppressAllMethodsExample.
@Test
public void suppressAllMethodsExample() throws Exception {
suppress(methodsDeclaredIn(SuppressMethod.class));
final SuppressMethod tested = new SuppressMethod();
assertNull(tested.getObject());
assertNull(SuppressMethod.getObjectStatic());
assertEquals(0, tested.getByte());
}
Aggregations