@Test
 @DirtiesContext
 public void testRefreshFails() throws Exception {
   assertEquals("Hello scope!", service.getMessage());
   // Change the dynamic property source...
   EnvironmentTestUtils.addEnvironment(environment, "message:Foo", "delay:foo");
   // ...and then refresh, so the bean is re-initialized:
   scope.refreshAll();
   try {
     // If a refresh fails (e.g. a binding error in this case) the application is
     // basically hosed.
     assertEquals("Hello scope!", service.getMessage());
     fail("expected BeanCreationException");
   } catch (BeanCreationException e) {
   }
   // But we can fix it by fixing the binding error:
   EnvironmentTestUtils.addEnvironment(environment, "delay:0");
   // ...and then refresh, so the bean is re-initialized:
   scope.refreshAll();
   assertEquals("Foo", service.getMessage());
 }
 @Test
 @DirtiesContext
 public void testRefresh() throws Exception {
   assertEquals("Hello scope!", service.getMessage());
   String id1 = service.toString();
   // Change the dynamic property source...
   EnvironmentTestUtils.addEnvironment(environment, "message:Foo");
   // ...and then refresh, so the bean is re-initialized:
   scope.refreshAll();
   String id2 = service.toString();
   assertEquals("Foo", service.getMessage());
   assertEquals(2, TestService.getInitCount());
   assertEquals(1, TestService.getDestroyCount());
   assertNotSame(id1, id2);
 }