I am developing a JUnit test into a Spring Controller, the Controller calls a bunch of Services. My JUnit test code is above:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebApplicationConfiguration.class, DatabaseConfiguration.class, ServiceConfiguration.class})
@WebAppConfiguration
public class ProcessFileControllerTest {
private MockMvc mockMvc;
@Test
public void getPageTest() throws Exception{
final ProcessFileController controller = new ProcessFileController();
SecurityHelperUtility.setupSecurityContext("user", "pass", "ROLE_ADMIN");
mockMvc = standaloneSetup(controller).build();
mockMvc.perform(get(URI.create("/processFile.html")).sessionAttr("freeTrialEmailAddress", "")).andExpect(view().name("processFile"));
}
When I run the JUnit test, I get a NullPointerExcelption
when I call this particular line of code of my ProcessFileController.java
final Company company = companyService.getCompanyByUser(userName);
I can see that the Service
is Null
.
In my ProcessFileController.java
the Service
is being declared as:
@Autowired private CompanyService companyService;
Any clue? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire