title: How to assert that the controller has been created in Spring Boot?
body: <p>According to the tutorial <a href="https://spring.io/guides/gs/testing-web/#_test_the_application" rel="nofollow noreferrer">Testing the Web Layer</a>, testing that the controller has been created can be done with the following code:</p>
  
  <pre><code>@Test
  public void contexLoads() throws Exception {
      assertThat(controller).isNotNull();
  }
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <pre><code>The method assertThat(T, Matcher&lt;? super T&gt;) in the type Assert is not applicable for the arguments (HomeController)"
  </code></pre>
  
  <p>even with the statement:</p>
  
  <pre><code>import static org.junit.Assert.assertThat;
  </code></pre>
  
  <p>The code of my class is the same than the one given in the example:</p>
  
  <pre><code>package com.my_org.my_app;
  
  import static org.assertj.core.api.Assertions.assertThat;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest
  public class SmokeTest {
  
      @Autowired
      private HomeController controller;
  
      @Test
      public void contexLoads() throws Exception {
          assertThat(controller).isNotNull();
      }
  }
  </code></pre>
  
  <p>If I change the assert statement to:</p>
  
  <pre><code>@Test
  public void contexLoads() throws Exception {
      assertNotNull(controller);
  }
  </code></pre>
  
  <p>it works as expected.</p>
  
  <p>My controller class has some Autowired objects, but since they are managed by Spring Boot it should not be an issue. Any idea of what could be wrong with <code>assertThat(controller).isNotNull();</code>? Thanks in advance.</p>