0

I am working on Spring Boot Rest Controller and everything is working fine including its unit testing.

When I added the Spring-jdbc(4.3.5.RELEASE) in my maven configuration, all my unit test classes are failing due to a null pointer exception. And if I remove it all my spring related unit testing classes are working fine again.

I have been using Spring so many years but this is the first time I have encountered this issue.

What is the root cause? I am using Spring boot 1.4.2.

Code:

@Test
public void verifyEmail() throws Exception {           
    mockServer.expect(requestTo("localhost:8080//api/v1/userEmails?email=test@test.com&catalogId=10051"))
        .andExpect(method(HttpMethod.GET))
        .andRespond(withSuccess("True", MediaType.APPLICATION_JSON));

    String s = acquisitionService.verifyEmail("test@test.com","10051");

    mockServer.verify();

    assertEquals("Assert Status", s, "True");                
}

Error Stack trace:

java.lang.NullPointerException
    at org.dmc.api.service.AcquisitionServiceImpl.getOrderConfirmData(AcquisitionServiceImpl.java:461)
    at org.dmc.api.service.AcquisitionServiceTest.orderConfirmDataTest(AcquisitionServiceTest.java:547)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
bcsb1001
  • 2,834
  • 3
  • 24
  • 35
  • 1
    Can you provide the stack trace? – Sean Carroll Jul 11 '17 at 19:32
  • can you please post your code here along with stacktrace – Akash Jul 11 '17 at 19:37
  • String s = xxxxxService.verifyEmail("test@test.com","10051"); – Shannon Riz Yabut Jul 11 '17 at 19:55
  • The DI is working fine for the xxxxService that I have created but the verifyEmail method in it is throwing a Null pointer exception. – Shannon Riz Yabut Jul 11 '17 at 20:01
  • java.lang.NullPointerException at org.dmc.api.service.AcquisitionServiceImpl.getOrderConfirmData(AcquisitionServiceImpl.java:461) at org.dmc.api.service.AcquisitionServiceTest.orderConfirmDataTest(AcquisitionServiceTest.java:547) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) – Shannon Riz Yabut Jul 11 '17 at 20:05
  • @ShannonRizYabut, If I could make a suggestion, instead of adding this information in comments I think it would be better to edit your question with these details – Sean Carroll Jul 11 '17 at 20:07
  • Thanks Sean Carrol. I just edited my question and added the one of the failing unit test classes and its stack trace. Take note that I haven't implemented anything related to spring JDBC yet, I just simply added the Spring JDBC library in the maven config and then it throws null pointers exception for all spring related unit test classes. – Shannon Riz Yabut Jul 11 '17 at 20:16
  • It might be issues of dependency conflict. You can check in POM.xml in Dependency Hierarchy section. – Darshan Jul 14 '17 at 03:06

0 Answers0