У меня есть этот код для тестирования:Spring Test Junit бросает исключение нулевой указатель
private static final Integer documentSetId = 1143;
private static final Integer dsLifeCycleStateId = 1;
private static final String dsLifecycleState = "CVS_CREATED";
CVBusiness cvBusinessTest;
DocumentService documentService;
DocumentSetRepository documentSetRepository;
private DocumentSet documentSet;
private DSLifeCycleState dsLifeCycleState;
@Before
public void setUp(){
cvBusinessTest = new CVBusinessImpl();
documentService = mock(DocumentService.class);
documentSetRepository = mock(DocumentSetRepository.class);
documentSet = new DocumentSet();
dsLifeCycleState = new DSLifeCycleState();
documentSet.setActive(true);
documentSet.setDocumentSetId(documentSetId);
documentSet.setMarkedForTranslation(false);
dsLifeCycleState.setDsLifeCycleStateId(dsLifeCycleStateId);
dsLifeCycleState.setLabel(dsLifecycleState);
documentSet.setDsLifeCycleState(dsLifeCycleState);
when(documentService.getDocumentSetById(documentSetId)).thenReturn(documentSet);
when(documentService.updateDocumentSet(documentSet)).thenReturn(documentSet);
when(documentSetRepository.findOne(documentSetId)).thenReturn(documentSet);
}
@Test
public void markedForTranslationTest() {
boolean retValue = true;
DocumentSet docSet = documentService.getDocumentSetById(documentSetId);
dsLifeCycleState = docSet.getDsLifeCycleState();
if (dsLifeCycleState.getLabel().equals(LifeCycleStateEnum.CVS_CREATED.message()) && docSet.isActive() && !docSet.isMarkedForTranslation() && ((docSet.getfDR() == null) || docSet.getfDR().equals(""))){
documentSet.setMarkedForTranslation(true);
retValue = documentService.updateDocumentSet(documentSet) != null;
}
// retValue = cvBusinessTest.markedForTranslation(documentSetId);
assertTrue(retValue);
}
и когда я бегу JUnit, он закончил с ошибками: java.lang Исключение нулевого указателя.
Какие ошибки указывает метод сильфона
DocumentSet documentSet = documentService.getDocumentSetById (ID)
, который находится в пакете CVBusiness продлен CVBusinessImpl.
Мой вопрос, почему documentService в CVBusinessImpl выбрасывает исключение Null? Спасибо!
Можете ли вы разместить исключение? – Augusto
Где происходит исключение, какая строка? –
Исключение происходит, когда я раскомментирую эту строку: retValue = cvBusinessTest.markedForTranslation (documentSetId); и ссылается на строку CVBusiness.java 100, которая содержит этот метод. У меня есть сообщение выше (DocumentSet documentSet = documentService.getDocumentSetById (id)) – wolver