/*for validator.java*/publicclassDemoLegValida{publicvoidvalidateCounterparty(Demosnapshotsnapshot) {
for (demosnapshot demosnapshot : snapshot.getDemoLegs()) {
ValidationExceptionUtil.notEmpty(demosnapshot.getCounterParty().getCounterPartyPOGroup(), "POGroup must be specified");
ValidationExceptionUtil.notEmpty(demosnapshot.getCounterParty().getCounterPartyPOUnit(), "POUnit must be specified");
ValidationExceptionUtil.notEmpty(demosnapshot.getCounterParty().getCounterPartyIdentifier(), "Counterparty must be specified");
}
}
/* UnitTest.java */publicclassDemoLegValidatorTest {@TestpublicvoidtestcounterpartyValidatorWithNoError() {
DemoSnapshot snapshot = mock(DemoSnapshot.class);
List<DemoLegSnapshot> legList = MockDemoLegUtil.getMockedDemoLegSnapshot();
given(snapshot.getDemoLegs()).willReturn(legList);
DemoLegValidatorDemoLegValidator= new DemoLegValidator();
DemoLegValidator.validateCounterparty(snapshot);
}
@TestpublicvoidtestcounterpartyValidatorWithEmptyPartyIdentifier() {
DemoSnapshot snapshot = mock(DemoSnapshot.class);
List<DemoLegSnapshot> legList = MockDemoLegUtil.getMockedDemoLegSnapshot_emptyCounterPartyIdentifier();
given(snapshot.getDemoLegs()).willReturn(legList);
DemoLegValidatorDemoLegValidator= new DemoLegValidator();
catchException(DemoLegValidator).validateCounterparty(snapshot);
assertThat(caughtException(),
allOf(instanceOf(ValidationException.class),
hasMessage("Counterparty must be specified")));
}
@TestpublicvoidtestcounterpartyValidatorWithEmptyPOGroup() {
DemoSnapshot snapshot = mock(DemoSnapshot.class);
List<DemoLegSnapshot> legList = MockDemoLegUtil.getMockedDemoLegSnapshot_emptyCounterPartyPOGroup();
given(snapshot.getDemoLegs()).willReturn(legList);
DemoLegValidatorDemoLegValidator= new DemoLegValidator();
catchException(DemoLegValidator).validateCounterparty(snapshot);
assertThat(caughtException(),
allOf(instanceOf(ValidationException.class),
hasMessage("POGroup must be specified")));
}
@TestpublicvoidtestcounterpartyValidatorWithEmptyPOUnit() {
DemoSnapshot snapshot = mock(DemoSnapshot.class);
List<DemoLegSnapshot> legList = MockDemoLegUtil.getMockedDemoLegSnapshot_emptyCounterPartyPOUnit();
given(snapshot.getDemoLegs()).willReturn(legList);
DemoLegValidatorDemoLegValidator= new DemoLegValidator();
catchException(DemoLegValidator).validateCounterparty(snapshot);
assertThat(caughtException(),
allOf(instanceOf(ValidationException.class),
hasMessage("POUnit must be specified")));
}
/*for validator.java*/public class DemoLegValida{ public void validateCounterparty(Demosnapshotsnapshot) { for (demosnapshot demosnapshot : snapshot.getDemoLegs()) { ValidationE