BDD является новым для меня. Я только начал изучать BDD на Java. Все мои тесты сейчас проходят, но в одном сценарии возникают проблемы. Итак, я вставил свой сценарий и шаг реализации ниже. Этот тестовый пример проходит, но в журнале он показывает, что есть проблемы.
Что является причиной этой проблемы и почему этот тест проходит, хотя в журналах отображается NullPointerException.
Как мне исправить эту ошибку.
Вот часть моего журнала
com.somedomain.common.exception.BusinessRuntimeException: Internal server Error. Contact administrator.
at ........................................................
at ...............................
at com.somedomain.promotions.test.steps.DayDateConditionPromotionSteps.leftOneOrBothDateFieldEmpty(DayDateConditionPromotionSteps.java:480)
at com.somedomain.promotions.test.steps.DayDateConditionPromotionSteps$$FastClassBySpringCGLIB$$bele823c.invoke(<generated>)
at ........................................
at .........................................
at cucumber.api.junit.Cucumber.run(Cucumber.java:100) <5 internal calls>
Caused by java.lang.NullPointerException: null
at java.util.Date.getMillisOf(Date.java:958)
at java.util.Date.compareTo(Date.java:978)
at com.somedomain.promotions.validation.PromotionValidator.checkActiveDates(PromotionValidator.java: 332)
at com.somedomain.promotions.validation.PromotionValidator.validatePromotion(PromotionValidator.java: 56)
at com.somedomain.promotions.service.DefaultPromotionService.create(DefaultPromotionService.java:65)<4 internal calls>
at ..................................
at ..................................
...73 common frames omitted
Файл функций
Feature: Create promotion based on the day condition
As a retailer
I want to create the promotions with day condition
so that rewards can be availed based on the condition
Background:
Given I am a user who can create promotions
And I have a promotion with default general configurations
@create @promotions @day_conditions @dates @validation
Scenario Outline: create promotion with day condition without selecting start date or end date or both
When I left one or both startingfields <startDateTime> and endingfields <endDateTime> empty
Then I should receive PayloadConstraintViolationException exception exists <error_message>
Examples:
| startDateTime | endDateTime |
| 06/20/2019 | empty |
| empty | 06/22/2019 |
| empty | empty |
Степень определения класса
public class DayDateConditionPromotionSteps extends Steps {
//private PromotionIdData promotionId = new PromotionIdData();
@Resource
private PromotionsService promotionsService;
private PromotionViewData promotionViewData = new PromotionViewData();
//new ActiveDate(startdatetime, enddatetime);
private ActiveDate activeDate ;
@When ("^I left one or both start date (.+) and end date (.+) empty$)
public void leftOneOrBothDateFieldEmpty(String startDatetime, String endDatetime) {
try {
final PromotionData promotionData = promotionCreater.generateCreateRequest("test");
List<TimePeriodCondition timePeriods = new ArrayLIst<>();
TimePeriodConditions timePeriodConditions = new TimePeriodConditions();
ActiveDate activeDate = new ActiveDate();
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-DD");
if (!(startDatetime.equalsIgnoreCase("empty")) && startDatetime.trim().length() >0){
Date startDate = dateFormat.parse(startDatetime);
activeDate.setStartDateTime(startDate);
}
if (!(endDatetime.equalsIgnoreCase("empty")) && endDatetime.trim().length() >0){
Date endDate = dateFormat.parse(endDatetime);
activeDate.setEndDateTime(endDate);
}
timePeriodConditions.setActiveDate(activeDate);
timePeriods.add(timePeriodConditions);
setPromotionData(promotionData);
promotionDate.getConditions().setTimePeriods(timePeriods);
final PromotionViewData promoViewData = promotionService.create(promotionData)
promotions.put(promotionViewData.getPromotionId(), promotionViewData);
} catch (Exception ex) {
exceptionMessage = ex.getCause().getMessage();
}
}
@Then ("^I should receive NullPointerException$")
public void receiveNullException(){
Assert.assertNull(exceptionMessage);
}
}