title: how to mock and test inside/outside get and set methods?
body: <p>I don<code>t know why but I</code>m always getting NullPointer and no idea why and how exactly this test should looks like. Its about method: webServiceTemplate():</p>
  <pre><code>@Configuration
  public class ErdConfiguration {
      
      @Autowired
      private EJwtProperties eJwtProperties;
      
      public Jaxb2Marshaller marshaller() {
          Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
          // this package must match the package in the &lt;generatePackage&gt; specified in pom.xml
          marshaller.setContextPath(&quot;erdUserRoles.wsdl&quot;);
          return marshaller;
      }
  
      public WebServiceTemplate webServiceTemplate() {
          WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
          webServiceTemplate.setMarshaller(marshaller());
          webServiceTemplate.setUnmarshaller(marshaller());
          webServiceTemplate.setDefaultUri(eJwtProperties.getRoles().getErdServiceUri());
      
          return webServiceTemplate;
      }
  }
  </code></pre>
  <p>and EJwtProperties class which it uses:</p>
  <pre><code>public class EJwtProperties {
  private Map&lt;String, String&gt; claims = new HashMap&lt;&gt;();
  private String signingKey;
  private SourceTokenConfig sourceToken = new SourceTokenConfig();
  private RolesConfig roles = new RolesConfig();
  private List&lt;String&gt; generateEjwtRoles = Collections.emptyList();
  private boolean cacheDisabled = false;
  
  @Data
  public static class SourceTokenConfig {
      private boolean embedSourceToken = false;
      private String embeddedTokenClaimName = &quot;source-token&quot;;
  }
  
  @Data
  public static class RolesConfig {
      private boolean rolesEnabled = false;
      private String rolesClaimName = &quot;roles&quot;;
      private String erdAppId;
      private String erdServiceUri;
  }
  }
  </code></pre>
  <p>My code so far looks like this and got null pointer while Im trying to check getRoles() in when-thenReturn :</p>
  <pre><code>    @Mock
      private EJwtProperties eJwtProperties;
  
      @InjectMocks
      private ErdConfiguration underTest;
  
      Jaxb2Marshaller marshaller;
  
      @BeforeEach
      void setUp() {
          MockitoAnnotations.openMocks(this);
      }
  
      @Test
      void webServiceTemplateTest() {
  
          EJwtProperties.RolesConfig roles = new EJwtProperties.RolesConfig();
          roles.setErdServiceUri(&quot;testErdServiceUri&quot;);
          
          eJwtProperties.setRoles(roles);
          
          underTest = new ErdConfiguration();
      
          when(eJwtProperties.getRoles()).thenReturn(roles);  //this one passed
              when(eJwtProperties.getRoles().getErdServiceUri()).thenReturn(roles.getErdServiceUri()); //here nullPointer
  
       //   underTest.webServiceTemplate();  //this is what I was planning to do next
  //assertEquals(underTest.webServiceTemplate(), eJwtProperties.getRoles().getErdServiceUri());  //or this
  //        assertEquals(marshaller, underTest.webServiceTemplate().getMarshaller());
  //        assertEquals(marshaller, underTest.webServiceTemplate().getUnmarshaller());
      }
  }
  </code></pre>
  <p>Please keep in mind that I'm still learning tests. Id be thankful for any help. How the hack it should looks like? What am I missing that it return null ? Should I initialize whole properties??</p>