diff --git a/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LambdaAnswer.java b/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LambdaAnswer.java index 33dbfee5e4..c67fe71c96 100644 --- a/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LambdaAnswer.java +++ b/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LambdaAnswer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 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. @@ -17,9 +17,9 @@ package org.springframework.amqp.rabbit.test.mockito; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.mockito.internal.stubbing.defaultanswers.ForwardsInvocations; import org.mockito.invocation.InvocationOnMock; @@ -33,6 +33,8 @@ * @param the return type. * * @author Gary Russell + * @author Artem Bilan + * * @since 1.6 * */ @@ -43,7 +45,7 @@ public class LambdaAnswer extends ForwardsInvocations { private final ValueToReturn callback; - private final Set exceptions = Collections.synchronizedSet(new LinkedHashSet<>()); + private final Set exceptions = ConcurrentHashMap.newKeySet(); private final boolean hasDelegate; @@ -88,9 +90,7 @@ public T answer(InvocationOnMock invocation) throws Throwable { * @since 2.2.3 */ public Collection getExceptions() { - synchronized (this.exceptions) { - return new LinkedHashSet<>(this.exceptions); - } + return new LinkedHashSet<>(this.exceptions); } @FunctionalInterface diff --git a/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LatchCountDownAndCallRealMethodAnswer.java b/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LatchCountDownAndCallRealMethodAnswer.java index d455693706..08b65fafc6 100644 --- a/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LatchCountDownAndCallRealMethodAnswer.java +++ b/spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/mockito/LatchCountDownAndCallRealMethodAnswer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 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. @@ -17,9 +17,9 @@ package org.springframework.amqp.rabbit.test.mockito; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -33,6 +33,8 @@ * method and counts down a latch. Captures any exceptions thrown. * * @author Gary Russell + * @author Artem Bilan + * * @since 1.6 * */ @@ -42,7 +44,7 @@ public class LatchCountDownAndCallRealMethodAnswer extends ForwardsInvocations { private final transient CountDownLatch latch; - private final Set exceptions = Collections.synchronizedSet(new LinkedHashSet<>()); + private final Set exceptions = ConcurrentHashMap.newKeySet(); private final boolean hasDelegate; @@ -101,9 +103,7 @@ public CountDownLatch getLatch() { */ @Nullable public Collection getExceptions() { - synchronized (this.exceptions) { - return new LinkedHashSet<>(this.exceptions); - } + return new LinkedHashSet<>(this.exceptions); } }