use of samples.suppressconstructor.SuppressConstructorHierarchy in project powermock by powermock.
the class SuppressConstructorHierarchyDemoTest method testGetNumber.
/**
* This simple test demonstrate that it's possible to continue execution
* with the default {@code PrepareForTest} settings (i.e. using a
* byte-code manipulated version of the SuppressConstructorHierarchyDemo
* class).
*/
@Test
public void testGetNumber() throws Exception {
suppress(constructor(SuppressConstructorHierarchy.class));
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
assertThat(tested.getNumber()).isEqualTo(42);
}
use of samples.suppressconstructor.SuppressConstructorHierarchy in project powermock by powermock.
the class SuppressConstructorHierarchyDemoTest method testSuppressConstructor.
@Test
public void testSuppressConstructor() throws Exception {
suppress(constructor(SuppressConstructorHierarchy.class));
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
final String message = tested.getMessage();
assertNull("Message should have been null since we're skipping the execution of the constructor code. Message was \"" + message + "\".", message);
}
use of samples.suppressconstructor.SuppressConstructorHierarchy 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.suppressconstructor.SuppressConstructorHierarchy in project powermock by powermock.
the class SuppressConstructorHierarchyDemoTest method directConstructorUsage.
@Test
public void directConstructorUsage() throws Exception {
System.out.println("ClassLoader: " + getClass().getClassLoader());
try {
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
if (suppress) {
assertNull("Message should have been null since we're skipping the execution of the constructor code. Message was \"message\".", tested.getMessage());
assertEquals("getNumber() value", 42, tested.getNumber());
} else {
fail("Expected RuntimeException");
}
} catch (RuntimeException ex) {
if (suppress) {
throw ex;
} else {
assertEquals("This should be suppressed!!", ex.getMessage());
}
}
}
use of samples.suppressconstructor.SuppressConstructorHierarchy in project powermock by powermock.
the class SuppressConstructorHierarchyDemoTest method testSuppressConstructorHierarchyAgain.
/**
* This simple test demonstrate that it's possible to continue execution
* with the default {@code PrepareForTest} settings (i.e. using a
* byte-code manipulated version of the SuppressConstructorHierarchyDemo
* class).
*/
@Test
public void testSuppressConstructorHierarchyAgain() throws Exception {
suppress(constructor(SuppressConstructorHierarchy.class));
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
assertEquals(42, tested.getNumber());
}
Aggregations