title: How do you fake a vaadin session for integration tests?
body: <p>Let's say I have a custom annotation</p>
  
  <pre class="lang-java prettyprint-override"><code>@ViewScope //&lt;-- the issue
  @Qualifier
  @Component
  @Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.TYPE, ElementType.FIELD,ElementType.PARAMETER,ElementType.METHOD, ElementType.ANNOTATION_TYPE})
  public @interface Foo { ... }
  </code></pre>
  
  <p>I now want to test a method that is supposed to retrieve all the beans with that annotation.</p>
  
  <p>How do I fake the vaadin session s.t. such an integration test</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner::class)
  @SpringBootTest
  @WebAppConfiguration
  class FooAnnotationIT{
  
      @Autowired(required = false) //required=false --&gt; empty list instead of exception when none are found
      @Foo
      val foos:List&lt;Any&gt; = mutableListOf()
  
      @Test
      fun `all beans are present`(){
          assertThat(foos.size).isEqualTo(5)
      }
  }
  </code></pre>
  
  <p>succeeds instead of crashing with </p>
  
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blah.blah.blah.FooAnnotationIT': Unsatisfied dependency expressed through field 'foos'
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewCache': Scope 'vaadin-ui' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
      Caused by: java.lang.IllegalStateException: No VaadinSession bound to current thread
  </code></pre>