title: Spring HATEOAS Resource assembler is not instantiated in unit test
body: <p>I am trying to write a unit test for a REST controller which generates HATEOAS links via Resource assembler class. Everything is OK in production, but with the unit test Resource assembler class is not being injected into the controller. </p>
  
  <p>my resource assembler class is:</p>
  
  <pre><code>@Component
  public class ModelResourceAssembler extends ResourceAssemblerSupport&lt;Model, ModelResource&gt; {
      public ModelResourceAssembler() {
      super(ModelRestController.class, ModelResource.class);
  
      }
  
      @Bean 
      public ModelResourceAssembler modelResourceAssembler(){
        return new ModelResourceAssembler();
      }
     @Override
     public ModelResource toResource(Model model) {
     ...
    }
  }
  </code></pre>
  
  <p>The controller is:</p>
  
  <pre><code>@Controller
  @RequestMapping("/demo")
  @ComponentScan(basePackages = {"com.foo.demo"} )
  public class ModelRestController {
      @Autowired
      private ModelPersistenceHandler modelPersistenceHandler;
  
      @Autowired
      private ModelResourceAssembler modelResourceAssembler;
  ...
  }
  </code></pre>
  
  <p>And the unit test:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes=    {ModelResourceAssembler.class, ModelRestController.class})
  public class ModelRestControllerTest {
      private MockMvc mockMvc;
  
      @InjectMocks
      private ModelRestController modelRestController;
  
      @Mock
      private ModelPersistenceHandler modelPersistenceHandler;
  
  
      @Before
      public void setup()  {
         MockitoAnnotations.initMocks(this);
         mockMvc = MockMvcBuilders.standaloneSetup(modelRestController).build();
     }
     ...
  }
  </code></pre>
  
  <p>No matter what I do the ModelResourceAssembler instance is always null. Since the application is Spring Boot it does not have the WebCoonfig classes and autowired WebApplicationContext is always null, so I cannot (and really don't want to since I am running a unit test) instantiate MockMvc via webAppContextSetup</p>