11package com .baeldung .awaitility ;
22
3+ import org .awaitility .Awaitility ;
4+ import org .awaitility .Duration ;
5+ import org .junit .Before ;
6+ import org .junit .BeforeClass ;
7+ import org .junit .Test ;
8+
9+ import java .util .concurrent .Callable ;
10+ import java .util .concurrent .TimeUnit ;
11+
312import static org .awaitility .Awaitility .await ;
413import static org .awaitility .Awaitility .fieldIn ;
514import static org .awaitility .Awaitility .given ;
615import static org .awaitility .proxy .AwaitilityClassProxy .to ;
716import static org .hamcrest .Matchers .equalTo ;
817
9- import java .util .concurrent .Callable ;
10- import java .util .concurrent .TimeUnit ;
11-
12- import org .awaitility .Awaitility ;
13- import org .awaitility .Duration ;
14- import org .junit .Before ;
15- import org .junit .Test ;
16-
1718public class AsyncServiceUnitTest {
1819 private AsyncService asyncService ;
1920
@@ -25,18 +26,18 @@ public void setUp() {
2526 @ Test
2627 public void givenAsyncService_whenInitialize_thenInitOccurs1 () {
2728 asyncService .initialize ();
28- Callable <Boolean > isInitialized = () -> asyncService . isInitialized () ;
29+ Callable <Boolean > isInitialized = asyncService :: isInitialized ;
2930 await ().until (isInitialized );
3031 }
3132
3233 @ Test
3334 public void givenAsyncService_whenInitialize_thenInitOccurs2 () {
3435 asyncService .initialize ();
35- Callable <Boolean > isInitialized = () -> asyncService . isInitialized () ;
36+ Callable <Boolean > isInitialized = asyncService :: isInitialized ;
3637 await ().atLeast (Duration .ONE_HUNDRED_MILLISECONDS )
37- .atMost (Duration .FIVE_SECONDS )
38- .with ().pollInterval (Duration .ONE_HUNDRED_MILLISECONDS )
39- .until (isInitialized );
38+ .atMost (Duration .FIVE_SECONDS )
39+ .with ().pollInterval (Duration .ONE_HUNDRED_MILLISECONDS )
40+ .until (isInitialized );
4041 }
4142
4243 @ Test
@@ -46,7 +47,7 @@ public void givenAsyncService_whenInitialize_thenInitOccurs_withDefualts() {
4647 Awaitility .setDefaultTimeout (Duration .ONE_MINUTE );
4748
4849 asyncService .initialize ();
49- await ().until (() -> asyncService . isInitialized () );
50+ await ().until (asyncService :: isInitialized );
5051 }
5152
5253 @ Test
@@ -59,14 +60,14 @@ public void givenAsyncService_whenInitialize_thenInitOccurs_withProxy() {
5960 public void givenAsyncService_whenInitialize_thenInitOccurs3 () {
6061 asyncService .initialize ();
6162 await ().until (fieldIn (asyncService )
62- .ofType (boolean .class )
63- .andWithName ("initialized" ), equalTo (true ));
63+ .ofType (boolean .class )
64+ .andWithName ("initialized" ), equalTo (true ));
6465 }
6566
6667 @ Test
6768 public void givenValue_whenAddValue_thenValueAdded () {
6869 asyncService .initialize ();
69- await ().until (() -> asyncService . isInitialized () );
70+ await ().until (asyncService :: isInitialized );
7071 long value = 5 ;
7172 asyncService .addValue (value );
7273 await ().until (asyncService ::getValue , equalTo (value ));
@@ -76,9 +77,9 @@ public void givenValue_whenAddValue_thenValueAdded() {
7677 public void givenAsyncService_whenGetValue_thenExceptionIgnored () {
7778 asyncService .initialize ();
7879 given ().ignoreException (IllegalStateException .class )
79- .await ()
80- .atMost (Duration .FIVE_SECONDS )
81- .atLeast (Duration .FIVE_HUNDRED_MILLISECONDS )
82- .until (asyncService ::getValue , equalTo (0L ));
80+ .await ()
81+ .atMost (Duration .FIVE_SECONDS )
82+ .atLeast (Duration .FIVE_HUNDRED_MILLISECONDS )
83+ .until (asyncService ::getValue , equalTo (0L ));
8384 }
8485}
0 commit comments