I want to write unit-test to check work of log.error function when exception is catched. I have this class:
class SalesMasterModelDateSequenceWrapper {
public static List<EMDate> getDatesClass(IAnalysisExpressionContext context, IContract contract, EMDate analysisDate, IExpressionLogger log, Lookup lookup) {
try {
StringBuilder scenarioName = new StringBuilder();
scenarioName.append(contract.getStringFDA(lookup.getServerFDA("NewContractsForecastName").toLowerCase()));
if (scenarioName.toString().length()==0) return new ArrayList<>();
scenarioName.append("_").append(analysisDate.year()).append(analysisDate.month()).append(analysisDate.day());
if (!context.getScenarioName().contains(scenarioName.toString())){
return Arrays.asList(contract.getValueDate());
}
}
catch (Exception e) {
StringBuilder sb = new StringBuilder();
sb.append("SalesMasterModelDateSequence: ").append(e.getMessage()).append("\n");
for (StackTraceElement stackTraceElement : e.getStackTrace())
{
sb.append(stackTraceElement.toString()).append("\n");
}
log.error(sb.toString());
}
return new ArrayList<>();
}
I want to verify that I'll take the result of log.error(sb.toString()). Can somebody help with this issue? Thanks in advance.