Search in sources :

Example 6 with SuppressField

use of samples.suppressfield.SuppressField in project powermock by powermock.

the class SuppressFieldTest method assertThatSpecificInstanceFieldSuppressionWorks.

@Test
public void assertThatSpecificInstanceFieldSuppressionWorks() throws Exception {
    suppress(field(SuppressField.class, "mySecondValue"));
    SuppressField suppressField = new SuppressField();
    assertNull(suppressField.getMySecondValue());
}
Also used : SuppressField(samples.suppressfield.SuppressField) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with SuppressField

use of samples.suppressfield.SuppressField in project powermock by powermock.

the class MemberModificationExampleTest method suppressSingleFieldExample.

@Test
public void suppressSingleFieldExample() throws Exception {
    suppress(field(SuppressField.class, "domainObject"));
    SuppressField tested = new SuppressField();
    assertNull(tested.getDomainObject());
}
Also used : SuppressField(samples.suppressfield.SuppressField) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with SuppressField

use of samples.suppressfield.SuppressField 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());
}
Also used : SuppressField(samples.suppressfield.SuppressField) SuppressMethod(samples.suppressmethod.SuppressMethod) SuppressConstructorHierarchy(samples.suppressconstructor.SuppressConstructorHierarchy) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with SuppressField

use of samples.suppressfield.SuppressField in project powermock by powermock.

the class SuppressFieldTest method assertThatSpecificInstanceFinalPrimitiveFieldSuppressionWorks.

@Ignore("Final primitive types doesn't work, see issue at https://github.com/jayway/powermock/issues/105")
@Test
public void assertThatSpecificInstanceFinalPrimitiveFieldSuppressionWorks() throws Exception {
    suppress(field(SuppressField.class, "myBoolean"));
    SuppressField suppressField = new SuppressField();
    assertEquals(false, suppressField.isMyBoolean());
}
Also used : SuppressField(samples.suppressfield.SuppressField) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with SuppressField

use of samples.suppressfield.SuppressField in project powermock by powermock.

the class SuppressFieldTest method assertThatAllFieldSuppressionWorks.

// TODO Add final tests here as well when they work
@Test
public void assertThatAllFieldSuppressionWorks() throws Exception {
    suppress(fields(SuppressField.class));
    SuppressField suppressField = new SuppressField();
    assertNull(suppressField.getMySecondValue());
    assertEquals(' ', suppressField.getMyChar());
    assertNull(suppressField.getMyWrappedBoolean());
    assertNull(SuppressField.getMyObject());
}
Also used : SuppressField(samples.suppressfield.SuppressField) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SuppressField (samples.suppressfield.SuppressField)11 Ignore (org.junit.Ignore)1 SuppressConstructorHierarchy (samples.suppressconstructor.SuppressConstructorHierarchy)1 SuppressMethod (samples.suppressmethod.SuppressMethod)1