コード例 #1
0
  @Test
  public void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
    AnnotationConfigApplicationContext context =
        new AnnotationConfigApplicationContext(Spr13081Config.class);
    Spr13081Service bean = context.getBean(Spr13081Service.class);

    this.thrown.expect(IllegalStateException.class);
    this.thrown.expectMessage(MyCacheResolver.class.getName());
    bean.getSimple(null);
  }
コード例 #2
0
  @Test
  public void spr13081ConfigNoCacheNameIsRequired() {
    AnnotationConfigApplicationContext context =
        new AnnotationConfigApplicationContext(Spr13081Config.class);
    MyCacheResolver cacheResolver = context.getBean(MyCacheResolver.class);
    Spr13081Service bean = context.getBean(Spr13081Service.class);

    assertNull(cacheResolver.getCache("foo").get("foo"));
    Object result = bean.getSimple("foo"); // cache name = id
    assertEquals(result, cacheResolver.getCache("foo").get("foo").get());
  }