Update your question with ready-to-use code. Here are some code review guidelines:
Problems with this question code:
- Article.java missing import: org.springframework.beans.factory.annotation.Autowired
- Article.java missing import: org.springframework.transaction.annotation.Transactional
- Article.java attribute syntax problem: dbRequestHandler
- Article.java: filesystemRequestHandler attribute syntax problem
- The Article.java method does not have an initialized return statement: articleDTO
Here is what you might need to use when you asked a question with the above problems:
Article.java
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; public class Article { @Autowired private Object dbRequestHandler; @Autowired private Object filesystemRequestHandler; @Transactional public ArticleDTO getArticleContents() {
IntegrationTest.java is a bad name for testClass because it is common. I would suggest ArticleTest for java unit test.
ArticleTest.java
import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.beans.factory.annotation.Autowired; @RunWith(PowerMockRunner.class) @PrepareForTest(ClassWithPrivate.class) public class ArticleTest { @InjectMocks private Article cut; @Mock private Object dbRequestHandler; @Mock private Object filesystemRequestHandler; @Test public void testeExtractImages() { Article articleMock = Mockito.spy(cut); Mockito.doNothing().when(articleMock).extractImages(); ArticleDTO result = cut.getArticleContents(); Assert.assertNull(result); } }
source share