use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class StubMethodTest method whenStubbingInstanceMethodToThrowExceptionTheMethodThrowsTheStubbedException.
@Test
public void whenStubbingInstanceMethodToThrowExceptionTheMethodThrowsTheStubbedException() throws Exception {
Exception expected = new Exception("message");
stub(method(SuppressMethod.class, "getObject")).toThrow(expected);
SuppressMethod tested = new SuppressMethod();
try {
tested.getObject();
fail();
} catch (Exception e) {
assertEquals("message", e.getMessage());
}
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class StubMethodTest method whenStubbingInstanceMethodTheMethodReturnsTheStubbedValue.
@Test
public void whenStubbingInstanceMethodTheMethodReturnsTheStubbedValue() throws Exception {
String expectedValue = "Hello";
stub(method(SuppressMethod.class, "getObject")).toReturn(expectedValue);
SuppressMethod tested = new SuppressMethod();
assertEquals(expectedValue, tested.getObject());
assertEquals(expectedValue, tested.getObject());
}
use of samples.suppressmethod.SuppressMethod in project powermock by powermock.
the class StubMethodTest method whenStubbingInstanceMethodWithPrimiteValueTheMethodReturnsTheStubbedValue.
@Test
public void whenStubbingInstanceMethodWithPrimiteValueTheMethodReturnsTheStubbedValue() throws Exception {
float expectedValue = 4;
stub(method(SuppressMethod.class, "getFloat")).toReturn(expectedValue);
SuppressMethod tested = new SuppressMethod();
assertEquals(expectedValue, tested.getFloat(), 0.0f);
assertEquals(expectedValue, tested.getFloat(), 0.0f);
}
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 SuppressMethodTest method suppressOverridingMethod.
@Test
public void suppressOverridingMethod() throws Exception {
suppress(method(SuppressMethod.class, "myMethod"));
SuppressMethod tested = new SuppressMethod();
assertEquals(0, tested.myMethod());
}
Aggregations