This is my first junit tests using Mockito. I'm facing the issue of NPE for the service that was used in @InjectMocks. I looked at the other solutions, but even after following them, it shows same. Here is my code.
@RunWith(MockitoJUnitRunner.class)
public class CustomerStatementServiceTests {
@InjectMocks
private BBServiceImpl bbService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
/**
* This test is to verify SUCCESS response
*/
@Test
public void testSuccess() {
BBResponse response = bbService.processDetails(txs);
assertEquals("SUCCESSFUL" ,response.getResult());
}
}
BBServiceImpl
@Service
public class BBServiceImpl implements BBService {
final static Logger log = Logger.getLogger(BBServiceImpl.class);
public BBResponse process(List<Customer> customers) {
// My business logic goes here
}
}
Pom.xml
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
My "bbService" object is null here
Am I missing anything here?