The other answers have provide some good suggestions about the code formatting and styling, so here's mine on the logic.
The way I see it, you only need to call verifyEventDetailFull()
when the test data is generated and currentPage
is true
(I'm not quite sure why the title containing a certain value is 'current page', but that's beyond my point). Otherwise, you 'handle the error' by saying that 'Page synchronize failed' if the test data is generated but currentPage
is false
, or say 'Test data is not generated' if that is indeed the case.
Given some slight, and in my humble opinion reasonable, assumptions based on the cases I have described above, I have an implementation for the handle error part:
private void handleError(final String testCaseName, final String errorDescription) {
WriteTo.testgoal(testCaseName, TestgoalState.NOK, errorDescription);
throw new Exception(errorDescription);
}
I think it's fair enough to use one errorDescription
for printing some output and using it for the Exception
message. I will now present the full suggestion:
public void synchronizePageAndExcecuteVerifyNode() throws Exception {
final String testCaseName = this.getClass().getSimpleName();
WriteTo.testgoal(testCaseName, TestgoalState.nvt, "");
boolean isTestDataGenerated = eventTestData.eventDetailMultipleDays;
if (isTestDataGenerated && driver.getTitle().contains(Value.TITLE_EVENT_MULTIPLE_DAYS)) {
verifyEventDetailFull();
} else {
handleError(testCaseName, isTestDataGenerated ? "Page synchronize failed" : "Test data is not generated");
}
}
private void handleError(final String testCaseName, final String errorDescription) {
WriteTo.testgoal(testCaseName, TestgoalState.NOK, errorDescription);
throw new Exception(errorDescription);
}
The only boolean
value I need to store first is isTestDataGenerated
. It is a good naming convention to begin boolean
variables with is
. Inside the else
part, isTestDataGenerated
allows us to switch between the correct error description. As mentioned above, we will only encounter the 'Page synchronize failed' case when the if
condition holds true
for isTestDataGenerated
but false
for 'current page'. Or you can simply read it as there is no test data generated, hence that error description in the false
clause of the conditional operator.