-3

I am testing a method in a class. Which is calling a method of abstract class.

Eg:

class abstract Abstract {
  public ReturnObject abstractMethod(SomeObject value) {
    // do something
    return returnObject;
  }
}

class Concreate extends Abstract {
   public ReturnObject concreteMethod(SomeObject value) {
   //do something
   returnObject = abstractMethod(value);
   return returnObject;
   }

}

My UT is 

class ConcreateTest {
  @InjectMocks
  private Concreate conctrete;

  @Mock
  private Concreate conctrete2;

  @Test
  public void test_method() {
     when(conctrete2.abstractMethod(value)).thenReturn(returnObject);
     conctrete.concreteMethod(value);
  }

}

This way it is returning me NullPointerException.

smali
  • 4,687
  • 7
  • 38
  • 60
  • 1
    You didn't add minimal code that could be compiled? seeing your code we can't help you out, and add error trace too. to get quick solution. – smali May 13 '16 at 04:20
  • 1
    @FaizAli Sorry I rejected your edit by mistake thinking that you are removing the spaces, I apologize For that. But it will be approved, not to worry. – Shree Krishna May 13 '16 at 04:30

1 Answers1

0

From what you are showing, I see very little of your code to tell for sure what's going on, but one thing I see is that you are mocking one Concreate and then injecting that mock into another Concreate. I don't see in the code you are showing anywhere that tells me that a Concreate uses another injected Concreate. This essentially is just pseudo-code. So essentially I am assuming that your main Concreate is being injected in an application context and that your other Concreate is being injected in the first one.

You need @Named to solve this ambiguity or more generically speaking you must give your beans an individual name, even if they are mocked.