我有测试此代码:春季测试的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引发空异常? 谢谢!
您可以发布例外吗? – Augusto
发生异常的地方是哪一行? –
当我取消注释此行时发生异常: retValue = cvBusinessTest.markedForTranslation(documentSetId); 并引用CVBusiness.java行100包含此方法我有上面的帖子(DocumentSet documentSet = documentService.getDocumentSetById(id)) – wolver