Replace anonymous inner classes with lambdas in tests
Closes gh-24808
This commit is contained in:
parent
7db00c9e22
commit
7c831d2ef4
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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<String> 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<String> 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Integer> deferredResult = new DeferredResult<>();
|
||||
deferredResult.onTimeout(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
deferredResult.setResult(23);
|
||||
}
|
||||
});
|
||||
deferredResult.onTimeout(() -> deferredResult.setResult(23));
|
||||
|
||||
this.asyncManager.startDeferredResultProcessing(deferredResult);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue