use of samples.expectnew.ITarget in project powermock by powermock.
the class WhenNewCases method canDefineSeveralMockResultForNew.
@Test
public void canDefineSeveralMockResultForNew() throws Exception {
final Target expectedTarget = new Target(UNKNOWN_TARGET_NAME, UNKNOWN_TARGET_ID);
whenNew(Target.class).withArguments(eq(TARGET_NAME), eq(TARGET_ID)).thenThrow(new CreationException());
whenNew(Target.class).withArguments(eq("Unknown"), eq(-1)).thenReturn(expectedTarget);
Target actualTarget = new ExpectNewDemo().createTarget(new ITarget() {
@Override
public int getId() {
return TARGET_ID;
}
@Override
public String getName() {
return TARGET_NAME;
}
});
assertThat(actualTarget).isEqualToComparingFieldByField(expectedTarget);
}
use of samples.expectnew.ITarget in project powermock by powermock.
the class ExpectNewCases method canDefineSeveralMockResultForNew.
@Test
public void canDefineSeveralMockResultForNew() throws Exception {
final Target expectedTarget = new Target(UNKNOWN_TARGET_NAME, UNKNOWN_TARGET_ID);
expectNew(Target.class, TARGET_NAME, TARGET_ID).andThrow(new CreationException());
expectNew(Target.class, "Unknown", -1).andReturn(expectedTarget);
replay(Target.class);
Target actualTarget = new ExpectNewDemo().createTarget(new ITarget() {
@Override
public int getId() {
return TARGET_ID;
}
@Override
public String getName() {
return TARGET_NAME;
}
});
assertThat(actualTarget).isEqualToComparingFieldByField(expectedTarget);
}
Aggregations