@SpringBootTest
@RunWith(MockitoJUnitRunner.class)
public class EmpCompSTest {
@Mock
private CompCl compCl;
@Test
public void testGetEmpCompS() {
EmpRequest request = new EmpRequest();
Map<Long, List<CompCl.CompeSc>> comp = new HashMap<>();
CompCl.CompSc compSc1
= new CompCl.CompSc();
comp.put(1L, Arrays.asList(compSc1));
when(compCl.getUsrSc(request.getComp().keySet())).thenReturn(comp);
}
}
When debugging, an NullPointerException pops up on the line with when()
and the class compCL
is null
.
CodePudding user response:
Is this Junit5 (Jupiter)? In that case use @ExtendWith(MockitoExtension.class)
instead of @RunWith(MockitoJUnitRunner.class)
.
CodePudding user response:
Should have been set Comp
for EmpRequest
.