title: Spring boot @Autowired not working in unit test case
body: <p>As I understand that if we use spring stereotypes then we don't need to use new keyword to create an instance. Spring manages that for us and provide us with the beans at runtime.</p>
  <p>And in order for Spring to inject those beans we need to use <code>@Autowired</code> annotation where we want Spring to inject that bean.
  Below I have a very simple class where I am using <code>@Component</code> so that spring manages that. This class has one List which I am initializing with my own responsibility and then a small method which does some logic.</p>
  <pre><code>@Slf4j
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  @Component
  public class Parser {
  
      private List&lt;String&gt; strList = new ArrayList&lt;&gt;();
  
      public void parseStrings(final String[] strs) {
  
          Arrays.stream(strs)
                  .map(String::toLowerCase)
                  .filter(str -&gt; str.length() &gt; 8)
                  .filter(str -&gt; str.endsWith(&quot;sam&quot;))
                  .forEach(sam1 -&gt;  { strList.add(sam1); });
      }
  
  }
  </code></pre>
  <p>I also wrote one unit test to test that and here is that.</p>
  <pre><code>import org.junit.jupiter.api.Test;
  import org.junit.runner.RunWith;
  import org.mockito.junit.MockitoJUnitRunner;
  import org.springframework.beans.factory.annotation.Autowired;
  import static org.junit.jupiter.api.Assertions.*;
  @RunWith(MockitoJUnitRunner.class)
  class ParserTest {
  
     @Autowired
     private Parser parser;
  
      @Test
      void parseStrings() {
          String str[] = {&quot;abcsamsam&quot;, &quot;abcsyjhgfed abdul sam&quot;,&quot;abcAhgbkgdjhul samad&quot;, &quot;abcabjhgdulsamsam&quot;, &quot;sa&quot;};
          parser.parseStrings(str);
  
          assertTrue(parser.getStrList().size() == 3);
          assertTrue(parser.getStrList().get(0).equalsIgnoreCase(&quot;abcsamsam&quot;));
  
      }
  }
  </code></pre>
  <p>The test fails with</p>
  <p><code>java.lang.NullPointerException</code> when it tries to call <code>parseStrings</code> method which means that its not able to inject a proper initialized bean at run time.</p>
  <p>Can some one guide that what I am missing?
  Is it necessary to add constructors (which here I am doing using lombok annotations) when using spring stereotypes on a class.</p>