title: Cannot inject @Service in Unit Test in SpringBoot project
body: <p>i have a @Service that I am trying to mock in an Unit Test but i get a null value so far. In the application class I specify what are the scanBasePackages. Do I have to do this in a different way? Thanks.</p>
  
  <p>This is my service class that implements an interface:</p>
  
  <pre><code>@Service
  public class DeviceService implements DeviceServiceDao {
  
  private List&lt;Device&gt; devices;
  
  @Override
  public List&lt;Device&gt; getDevices(long homeId) {
      return devices;
  }
  
  }
  </code></pre>
  
  <p>This is my unit test.</p>
  
  <pre><code>public class SmartHomeControllerTest {
  
      private RestTemplate restTemplate = new RestTemplate();
      private static final String BASE_URL = “..”;
  
      @Mock
      private DeviceService deviceService;
  
  @Test
  public void getHomeRegisteredDevices() throws Exception {
  
      Device activeDevice = new DeviceBuilder()
              .getActiveDevice(true)
              .getName("Alexa")
              .getDeviceId(1)
              .getHomeId(1)
              .build();
      Device inativeDevice = new DeviceBuilder()
              .getInactiveDevice(false)
              .getName("Heater")
              .getDeviceId(2)
              .getHomeId(1)
              .build();
  
      UriComponentsBuilder builder = UriComponentsBuilder
              .fromUriString(BASE_URL + "/1/devices");
  
      List response = restTemplate.getForObject(builder.toUriString(), List.class);
  
      verify(deviceService, times(1)).getDevices(1);
      verifyNoMoreInteractions(deviceService);
  }
  </code></pre>