11/*
2- * Copyright 2013-2020 the original author or authors.
2+ * Copyright 2013-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919import org .apache .commons .logging .Log ;
2020import org .apache .commons .logging .LogFactory ;
2121import org .junit .jupiter .api .AfterEach ;
22- import org .junit .jupiter .api .Assertions ;
2322import org .junit .jupiter .api .BeforeEach ;
2423import org .junit .jupiter .api .Test ;
2524
4241import org .springframework .jmx .export .annotation .ManagedResource ;
4342import org .springframework .test .annotation .DirtiesContext ;
4443
44+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
4545import static org .assertj .core .api .BDDAssertions .then ;
4646
4747@ SpringBootTest (classes = TestConfiguration .class )
@@ -71,27 +71,27 @@ public void close() {
7171 @ Test
7272 @ DirtiesContext
7373 public void testSimpleProperties () {
74- then (this . service .getMessage ()).isEqualTo ("Hello scope!" );
75- then (this . service instanceof Advised ).isTrue ();
74+ then (service .getMessage ()).isEqualTo ("Hello scope!" );
75+ then (service instanceof Advised ).isTrue ();
7676 // Change the dynamic property source...
77- this . properties .setMessage ("Foo" );
77+ properties .setMessage ("Foo" );
7878 // ...but don't refresh, so the bean stays the same:
79- then (this . service .getMessage ()).isEqualTo ("Hello scope!" );
79+ then (service .getMessage ()).isEqualTo ("Hello scope!" );
8080 then (ExampleService .getInitCount ()).isEqualTo (0 );
8181 then (ExampleService .getDestroyCount ()).isEqualTo (0 );
8282 }
8383
8484 @ Test
8585 @ DirtiesContext
8686 public void testRefresh () {
87- then (this . service .getMessage ()).isEqualTo ("Hello scope!" );
88- String id1 = this . service .toString ();
87+ then (service .getMessage ()).isEqualTo ("Hello scope!" );
88+ String id1 = service .toString ();
8989 // Change the dynamic property source...
90- this . properties .setMessage ("Foo" );
90+ properties .setMessage ("Foo" );
9191 // ...and then refresh, so the bean is re-initialized:
92- this . scope .refreshAll ();
93- String id2 = this . service .toString ();
94- then (this . service .getMessage ()).isEqualTo ("Foo" );
92+ scope .refreshAll ();
93+ String id2 = service .toString ();
94+ then (service .getMessage ()).isEqualTo ("Foo" );
9595 then (ExampleService .getInitCount ()).isEqualTo (1 );
9696 then (ExampleService .getDestroyCount ()).isEqualTo (1 );
9797 then (id2 ).isNotSameAs (id1 );
@@ -102,15 +102,15 @@ public void testRefresh() {
102102 @ Test
103103 @ DirtiesContext
104104 public void testRefreshBean () {
105- then (this . service .getMessage ()).isEqualTo ("Hello scope!" );
106- String id1 = this . service .toString ();
105+ then (service .getMessage ()).isEqualTo ("Hello scope!" );
106+ String id1 = service .toString ();
107107 // Change the dynamic property source...
108- this . properties .setMessage ("Foo" );
108+ properties .setMessage ("Foo" );
109109 // ...and then refresh, so the bean is re-initialized:
110- this . scope .refresh ("service" );
111- String id2 = this . service .toString ();
112- then (this . service .getMessage ()).isEqualTo ("Foo" );
113- then (this . service .getMessage ()).isEqualTo ("Foo" );
110+ scope .refresh ("service" );
111+ String id2 = service .toString ();
112+ then (service .getMessage ()).isEqualTo ("Foo" );
113+ then (service .getMessage ()).isEqualTo ("Foo" );
114114 then (ExampleService .getInitCount ()).isEqualTo (1 );
115115 then (ExampleService .getDestroyCount ()).isEqualTo (1 );
116116 then (id2 ).isNotSameAs (id1 );
@@ -122,7 +122,7 @@ public void testRefreshBean() {
122122 @ Test
123123 @ DirtiesContext
124124 public void testCheckedException () {
125- Assertions . assertThrows (ServiceException .class , ( ) -> this . service .throwsException ());
125+ assertThatExceptionOfType (ServiceException .class ). isThrownBy (( ) -> service .throwsException ());
126126 }
127127
128128 public interface Service {
@@ -168,28 +168,28 @@ public void setDelay(long delay) {
168168
169169 @ Override
170170 public void afterPropertiesSet () {
171- logger .debug ("Initializing message: " + this . message );
171+ logger .debug ("Initializing message: " + message );
172172 initCount ++;
173173 }
174174
175175 @ Override
176176 public void destroy () {
177- logger .debug ("Destroying message: " + this . message );
177+ logger .debug ("Destroying message: " + message );
178178 destroyCount ++;
179- this . message = null ;
179+ message = null ;
180180 }
181181
182182 @ Override
183183 public String getMessage () {
184- logger .debug ("Getting message: " + this . message );
184+ logger .debug ("Getting message: " + message );
185185 try {
186- Thread .sleep (this . delay );
186+ Thread .sleep (delay );
187187 }
188188 catch (InterruptedException e ) {
189189 Thread .currentThread ().interrupt ();
190190 }
191- logger .info ("Returning message: " + this . message );
192- return this . message ;
191+ logger .info ("Returning message: " + message );
192+ return message ;
193193 }
194194
195195 public void setMessage (String message ) {
@@ -226,8 +226,8 @@ protected static class TestConfiguration {
226226 @ RefreshScope
227227 public ExampleService service () {
228228 ExampleService service = new ExampleService ();
229- service .setMessage (this . properties .getMessage ());
230- service .setDelay (this . properties .getDelay ());
229+ service .setMessage (properties .getMessage ());
230+ service .setDelay (properties .getDelay ());
231231 return service ;
232232 }
233233
@@ -243,7 +243,7 @@ protected static class TestProperties {
243243
244244 @ ManagedAttribute
245245 public String getMessage () {
246- return this . message ;
246+ return message ;
247247 }
248248
249249 public void setMessage (String message ) {
@@ -252,7 +252,7 @@ public void setMessage(String message) {
252252
253253 @ ManagedAttribute
254254 public int getDelay () {
255- return this . delay ;
255+ return delay ;
256256 }
257257
258258 public void setDelay (int delay ) {
0 commit comments