Skip to content

Commit b375a06

Browse files
committed
Polish DefaultMessageListenerContainer[Tests]
1 parent 0e9cd2a commit b375a06

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,14 @@ public void setRecoveryInterval(long recoveryInterval) {
256256

257257
/**
258258
* Specify the level of caching that this listener container is allowed to apply,
259-
* in the form of the name of the corresponding constant: e.g. "CACHE_CONNECTION".
259+
* in the form of the name of the corresponding constant — for example,
260+
* {@code "CACHE_CONNECTION"}.
260261
* @see #setCacheLevel
262+
* @see #CACHE_NONE
263+
* @see #CACHE_CONNECTION
264+
* @see #CACHE_SESSION
265+
* @see #CACHE_CONSUMER
266+
* @see #CACHE_AUTO
261267
*/
262268
public void setCacheLevelName(String constantName) throws IllegalArgumentException {
263269
if (!constantName.startsWith("CACHE_")) {
@@ -282,6 +288,7 @@ public void setCacheLevelName(String constantName) throws IllegalArgumentExcepti
282288
* @see #CACHE_CONNECTION
283289
* @see #CACHE_SESSION
284290
* @see #CACHE_CONSUMER
291+
* @see #CACHE_AUTO
285292
* @see #setCacheLevelName
286293
* @see #setTransactionManager
287294
*/

spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
import static org.mockito.Mockito.verify;
3939

4040
/**
41+
* Tests for {@link DefaultMessageListenerContainer}.
42+
*
4143
* @author Stephane Nicoll
4244
* @author Juergen Hoeller
4345
*/
44-
public class DefaultMessageListenerContainerTests {
46+
class DefaultMessageListenerContainerTests {
4547

4648
@Test
47-
public void applyBackOff() {
49+
void applyBackOff() {
4850
BackOff backOff = mock();
4951
BackOffExecution execution = mock();
5052
given(execution.nextBackOff()).willReturn(BackOffExecution.STOP);
@@ -65,7 +67,7 @@ public void applyBackOff() {
6567
}
6668

6769
@Test
68-
public void applyBackOffRetry() {
70+
void applyBackOffRetry() {
6971
BackOff backOff = mock();
7072
BackOffExecution execution = mock();
7173
given(execution.nextBackOff()).willReturn(50L, BackOffExecution.STOP);
@@ -84,7 +86,7 @@ public void applyBackOffRetry() {
8486
}
8587

8688
@Test
87-
public void recoverResetBackOff() {
89+
void recoverResetBackOff() {
8890
BackOff backOff = mock();
8991
BackOffExecution execution = mock();
9092
given(execution.nextBackOff()).willReturn(50L, 50L, 50L); // 3 attempts max
@@ -103,7 +105,7 @@ public void recoverResetBackOff() {
103105
}
104106

105107
@Test
106-
public void stopAndRestart() {
108+
void stopAndRestart() {
107109
DefaultMessageListenerContainer container = createRunningContainer();
108110
container.stop();
109111

@@ -112,7 +114,7 @@ public void stopAndRestart() {
112114
}
113115

114116
@Test
115-
public void stopWithCallbackAndRestart() throws InterruptedException {
117+
void stopWithCallbackAndRestart() throws InterruptedException {
116118
DefaultMessageListenerContainer container = createRunningContainer();
117119

118120
TestRunnable stopCallback = new TestRunnable();
@@ -124,7 +126,7 @@ public void stopWithCallbackAndRestart() throws InterruptedException {
124126
}
125127

126128
@Test
127-
public void stopCallbackIsInvokedEvenIfContainerIsNotRunning() throws InterruptedException {
129+
void stopCallbackIsInvokedEvenIfContainerIsNotRunning() throws InterruptedException {
128130
DefaultMessageListenerContainer container = createRunningContainer();
129131
container.stop();
130132

@@ -137,7 +139,7 @@ public void stopCallbackIsInvokedEvenIfContainerIsNotRunning() throws Interrupte
137139
}
138140

139141

140-
private DefaultMessageListenerContainer createRunningContainer() {
142+
private static DefaultMessageListenerContainer createRunningContainer() {
141143
DefaultMessageListenerContainer container = createContainer(createSuccessfulConnectionFactory());
142144
container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONNECTION);
143145
container.setBackOff(new FixedBackOff(100, 1));
@@ -146,7 +148,7 @@ private DefaultMessageListenerContainer createRunningContainer() {
146148
return container;
147149
}
148150

149-
private ConnectionFactory createSuccessfulConnectionFactory() {
151+
private static ConnectionFactory createSuccessfulConnectionFactory() {
150152
try {
151153
ConnectionFactory connectionFactory = mock();
152154
given(connectionFactory.createConnection()).willReturn(mock());
@@ -157,7 +159,7 @@ private ConnectionFactory createSuccessfulConnectionFactory() {
157159
}
158160
}
159161

160-
private DefaultMessageListenerContainer createContainer(ConnectionFactory connectionFactory) {
162+
private static DefaultMessageListenerContainer createContainer(ConnectionFactory connectionFactory) {
161163
Destination destination = new Destination() {};
162164

163165
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
@@ -167,7 +169,7 @@ private DefaultMessageListenerContainer createContainer(ConnectionFactory connec
167169
return container;
168170
}
169171

170-
private ConnectionFactory createFailingContainerFactory() {
172+
private static ConnectionFactory createFailingContainerFactory() {
171173
try {
172174
ConnectionFactory connectionFactory = mock();
173175
given(connectionFactory.createConnection()).will(invocation -> {
@@ -180,7 +182,7 @@ private ConnectionFactory createFailingContainerFactory() {
180182
}
181183
}
182184

183-
private ConnectionFactory createRecoverableContainerFactory(final int failingAttempts) {
185+
private static ConnectionFactory createRecoverableContainerFactory(final int failingAttempts) {
184186
try {
185187
ConnectionFactory connectionFactory = mock();
186188
given(connectionFactory.createConnection()).will(new Answer<Object>() {
@@ -213,7 +215,7 @@ public void run() {
213215
this.countDownLatch.countDown();
214216
}
215217

216-
public void waitForCompletion() throws InterruptedException {
218+
void waitForCompletion() throws InterruptedException {
217219
this.countDownLatch.await(1, TimeUnit.SECONDS);
218220
assertThat(this.countDownLatch.getCount()).as("callback was not invoked").isEqualTo(0);
219221
}

0 commit comments

Comments
 (0)