title: Mock Service class that has Autowired dependencies
body: <p>I have a Service class &amp; a config class as below:</p>
  <pre><code>public class MyService{
  
   @Autowired
   MyConfig myconfig;
  
   @Autowired
   private WebClient webClient;
  
   private String result;
  
   public String fetchResult(){
     return webClient.get().uri(myConfig.getUrl()).retrieve().bodyToMono(String.class).block();
   }
  }
  
  @ConfigurationProperties(&quot;prefix=&quot;somefield&quot;)
  @Component
  class MyConfig{
     private String url;
     //getter &amp; setter
    }
  }
  </code></pre>
  <p><strong>Below is the Junit:</strong></p>
  <pre><code>@Runwith(MockitoJUnitRunner.class)
  public class TestMe{
  
      @InjectMocks
      MyService myService;
  
      @Test
      public void myTest(){
         when(myService.fetchResult().then return(&quot;dummy&quot;);
      }
  }
  </code></pre>
  <p>I am getting null pointer error when I run this class at webClient in Service class.
  What could be the issue. I am new to JUnits.
  How do I write a proper JUnit for this.</p>