diff --git a/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java b/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java index 16e0000c88a..d037fb9bda0 100644 --- a/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -657,18 +657,15 @@ public class DefaultLifecycleProcessorTests { // invocation order in the 'stoppedBeans' list stop(); final int delay = this.shutdownDelay; - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(delay); - } - catch (InterruptedException e) { - // ignore - } - finally { - callback.run(); - } + new Thread(() -> { + try { + Thread.sleep(delay); + } + catch (InterruptedException e) { + // ignore + } + finally { + callback.run(); } }).start(); } diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java index 89d7e09c9c3..f509333a931 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -422,12 +422,7 @@ public class EnableSchedulingTests { public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(taskScheduler()); taskRegistrar.addFixedRateTask(new IntervalTask( - new Runnable() { - @Override - public void run() { - worker().executedByThread = Thread.currentThread().getName(); - } - }, + () -> worker().executedByThread = Thread.currentThread().getName(), 10, 0)); } } diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java index d89ea3a73aa..a14ecf5f4e9 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -229,16 +229,13 @@ class SettableListenableFutureTests { void getWaitsForCompletion() throws ExecutionException, InterruptedException { final String string = "hello"; - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(20L); - settableListenableFuture.set(string); - } - catch (InterruptedException ex) { - throw new RuntimeException(ex); - } + new Thread(() -> { + try { + Thread.sleep(20L); + settableListenableFuture.set(string); + } + catch (InterruptedException ex) { + throw new RuntimeException(ex); } }).start(); @@ -258,16 +255,13 @@ class SettableListenableFutureTests { void getWithTimeoutWaitsForCompletion() throws ExecutionException, InterruptedException, TimeoutException { final String string = "hello"; - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(20L); - settableListenableFuture.set(string); - } - catch (InterruptedException ex) { - throw new RuntimeException(ex); - } + new Thread(() -> { + try { + Thread.sleep(20L); + settableListenableFuture.set(string); + } + catch (InterruptedException ex) { + throw new RuntimeException(ex); } }).start(); @@ -347,16 +341,13 @@ class SettableListenableFutureTests { @Test void cancelStateThrowsExceptionWhenCallingGetWithTimeout() throws ExecutionException, TimeoutException, InterruptedException { - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(20L); - settableListenableFuture.cancel(true); - } - catch (InterruptedException ex) { - throw new RuntimeException(ex); - } + new Thread(() -> { + try { + Thread.sleep(20L); + settableListenableFuture.cancel(true); + } + catch (InterruptedException ex) { + throw new RuntimeException(ex); } }).start(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java index fe0effcdfdf..d4be2565f1f 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java @@ -42,15 +42,11 @@ public class EmbeddedDatabaseBuilderTests { @Test public void addDefaultScripts() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = new EmbeddedDatabaseBuilder()// - .addDefaultScripts()// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = new EmbeddedDatabaseBuilder()// + .addDefaultScripts()// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @@ -62,105 +58,77 @@ public class EmbeddedDatabaseBuilderTests { @Test public void addScript() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .addScript("db-schema.sql")// - .addScript("db-test-data.sql")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .addScript("db-schema.sql")// + .addScript("db-test-data.sql")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void addScripts() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .addScripts("db-schema.sql", "db-test-data.sql")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .addScripts("db-schema.sql", "db-test-data.sql")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void addScriptsWithDefaultCommentPrefix() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .addScripts("db-schema-comments.sql", "db-test-data.sql")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .addScripts("db-schema-comments.sql", "db-test-data.sql")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void addScriptsWithCustomCommentPrefix() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .addScripts("db-schema-custom-comments.sql", "db-test-data.sql")// - .setCommentPrefix("~")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .addScripts("db-schema-custom-comments.sql", "db-test-data.sql")// + .setCommentPrefix("~")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void addScriptsWithCustomBlockComments() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .addScripts("db-schema-block-comments.sql", "db-test-data.sql")// - .setBlockCommentStartDelimiter("{*")// - .setBlockCommentEndDelimiter("*}")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .addScripts("db-schema-block-comments.sql", "db-test-data.sql")// + .setBlockCommentStartDelimiter("{*")// + .setBlockCommentEndDelimiter("*}")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void setTypeToH2() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .setType(H2)// - .addScripts("db-schema.sql", "db-test-data.sql")// - .build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .setType(H2)// + .addScripts("db-schema.sql", "db-test-data.sql")// + .build(); + assertDatabaseCreatedAndShutdown(db); }); } @Test public void setTypeToDerbyAndIgnoreFailedDrops() throws Exception { - doTwice(new Runnable() { - - @Override - public void run() { - EmbeddedDatabase db = builder// - .setType(DERBY)// - .ignoreFailedDrops(true)// - .addScripts("db-schema-derby-with-drop.sql", "db-test-data.sql").build(); - assertDatabaseCreatedAndShutdown(db); - } + doTwice(() -> { + EmbeddedDatabase db = builder// + .setType(DERBY)// + .ignoreFailedDrops(true)// + .addScripts("db-schema-derby-with-drop.sql", "db-test-data.sql").build(); + assertDatabaseCreatedAndShutdown(db); }); } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java index bb0bcc0e2bc..609f12f7beb 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,12 +130,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests { return; } final CountDownLatch latch = new CountDownLatch(1); - this.activeMQBroker.addShutdownHook(new Runnable() { - @Override - public void run() { - latch.countDown(); - } - }); + this.activeMQBroker.addShutdownHook(latch::countDown); this.activeMQBroker.stop(); assertThat(latch.await(5, TimeUnit.SECONDS)).as("Broker did not stop").isTrue(); logger.debug("Broker stopped"); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java index e079c5beb4d..7a6f91b25f7 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/DeferredResultTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,12 +93,7 @@ public class DeferredResultTests { final StringBuilder sb = new StringBuilder(); DeferredResult result = new DeferredResult<>(); - result.onCompletion(new Runnable() { - @Override - public void run() { - sb.append("completion event"); - } - }); + result.onCompletion(() -> sb.append("completion event")); result.getInterceptor().afterCompletion(null, null); @@ -114,12 +109,7 @@ public class DeferredResultTests { DeferredResult result = new DeferredResult<>(null, "timeout result"); result.setResultHandler(handler); - result.onTimeout(new Runnable() { - @Override - public void run() { - sb.append("timeout event"); - } - }); + result.onTimeout(() -> sb.append("timeout event")); result.getInterceptor().handleTimeout(null, null); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java index 7fcba13b179..e07100c0045 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/WebAsyncManagerTimeoutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -215,12 +215,7 @@ public class WebAsyncManagerTimeoutTests { public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception { final DeferredResult deferredResult = new DeferredResult<>(); - deferredResult.onTimeout(new Runnable() { - @Override - public void run() { - deferredResult.setResult(23); - } - }); + deferredResult.onTimeout(() -> deferredResult.setResult(23)); this.asyncManager.startDeferredResultProcessing(deferredResult);