Skip to content

Commit 131e765

Browse files
committed
Polishing.
Simplify code and tests. See #3009
1 parent 94190c2 commit 131e765

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
* @author Thomas Darimont
102102
* @author Mark Paluch
103103
* @author John Blum
104-
* @author SEONGJUN LEE
104+
* @author Seongjun Lee
105105
* @see MessageListener
106106
* @see SubscriptionListener
107107
*/
@@ -555,8 +555,8 @@ public final boolean isActive() {
555555
* Adds a message listener to the (potentially running) container. If the container is running, the listener starts
556556
* receiving (matching) messages as soon as possible.
557557
*
558-
* @param listener message listener
559-
* @param topics message listener topic
558+
* @param listener message listener.
559+
* @param topics message listener topic.
560560
*/
561561
public void addMessageListener(MessageListener listener, Collection<? extends Topic> topics) {
562562
addListener(listener, topics);
@@ -566,8 +566,8 @@ public void addMessageListener(MessageListener listener, Collection<? extends To
566566
* Adds a message listener to the (potentially running) container. If the container is running, the listener starts
567567
* receiving (matching) messages as soon as possible.
568568
*
569-
* @param listener message listener
570-
* @param topic message topic
569+
* @param listener message listener.
570+
* @param topic message topic.
571571
*/
572572
public void addMessageListener(MessageListener listener, Topic topic) {
573573
addMessageListener(listener, Collections.singleton(topic));
@@ -580,8 +580,8 @@ public void addMessageListener(MessageListener listener, Topic topic) {
580580
* Note that this method obeys the Redis (p)unsubscribe semantics - meaning an empty/null collection will remove
581581
* listener from all channels.
582582
*
583-
* @param listener message listener
584-
* @param topics message listener topics
583+
* @param listener message listener.
584+
* @param topics message listener topics.
585585
*/
586586
public void removeMessageListener(@Nullable MessageListener listener, Collection<? extends Topic> topics) {
587587
removeListener(listener, topics);
@@ -594,8 +594,8 @@ public void removeMessageListener(@Nullable MessageListener listener, Collection
594594
* Note that this method obeys the Redis (p)unsubscribe semantics - meaning an empty/null collection will remove
595595
* listener from all channels.
596596
*
597-
* @param listener message listener
598-
* @param topic message topic
597+
* @param listener message listener.
598+
* @param topic message topic.
599599
*/
600600
public void removeMessageListener(@Nullable MessageListener listener, Topic topic) {
601601
removeMessageListener(listener, Collections.singleton(topic));
@@ -605,7 +605,7 @@ public void removeMessageListener(@Nullable MessageListener listener, Topic topi
605605
* Removes the given message listener completely (from all topics). If the container is running, the listener stops
606606
* receiving (matching) messages as soon as possible.
607607
*
608-
* @param listener message listener
608+
* @param listener message listener.
609609
*/
610610
public void removeMessageListener(MessageListener listener) {
611611

@@ -774,7 +774,7 @@ private void remove(@Nullable MessageListener listener, Topic topic, ByteArrayWr
774774
Map<ByteArrayWrapper, Collection<MessageListener>> mapping, List<byte[]> topicToRemove) {
775775

776776
Collection<MessageListener> listeners = mapping.get(holder);
777-
if (listeners == null || listeners.isEmpty()) {
777+
if (CollectionUtils.isEmpty(listeners)) {
778778
return;
779779
}
780780

src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java

+9-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3232
import org.springframework.core.task.SyncTaskExecutor;
3333
import org.springframework.data.redis.RedisConnectionFailureException;
34-
import org.springframework.data.redis.connection.*;
34+
import org.springframework.data.redis.connection.MessageListener;
35+
import org.springframework.data.redis.connection.RedisConnection;
36+
import org.springframework.data.redis.connection.RedisConnectionFactory;
37+
import org.springframework.data.redis.connection.Subscription;
38+
import org.springframework.data.redis.connection.SubscriptionListener;
3539
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
3640
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
3741
import org.springframework.data.redis.listener.adapter.RedisListenerExecutionFailedException;
@@ -42,6 +46,7 @@
4246
*
4347
* @author Mark Paluch
4448
* @author Christoph Strobl
49+
* @author Seongjun Lee
4550
*/
4651
class RedisMessageListenerContainerUnitTests {
4752

@@ -220,23 +225,9 @@ void failsOnDuplicateInit() {
220225
assertThatIllegalStateException().isThrownBy(() -> container.afterPropertiesSet());
221226
}
222227

223-
@Test
224-
void shouldRemoveSpecificListenerFromMappingAndListenerTopics() {
225-
MessageListener listener1 = mock(MessageListener.class);
226-
MessageListener listener2 = mock(MessageListener.class);
227-
Topic topic = new ChannelTopic("topic1");
228-
229-
container.addMessageListener(listener1, Collections.singletonList(topic));
230-
container.addMessageListener(listener2, Collections.singletonList(topic));
231-
232-
container.removeMessageListener(listener1, Collections.singletonList(topic));
233-
234-
container.addMessageListener(listener2, Collections.singletonList(topic));
235-
verify(listener1, never()).onMessage(any(), any());
236-
}
237-
238-
@Test
228+
@Test // GH-3009
239229
void shouldRemoveAllListenersWhenListenerIsNull() {
230+
240231
MessageListener listener1 = mock(MessageListener.class);
241232
MessageListener listener2 = mock(MessageListener.class);
242233
Topic topic = new ChannelTopic("topic1");
@@ -246,7 +237,6 @@ void shouldRemoveAllListenersWhenListenerIsNull() {
246237

247238
container.removeMessageListener(null, Collections.singletonList(topic));
248239

249-
verify(listener1, never()).onMessage(any(), any());
250-
verify(listener2, never()).onMessage(any(), any());
240+
assertThatNoException().isThrownBy(() -> container.removeMessageListener(null, Collections.singletonList(topic)));
251241
}
252242
}

0 commit comments

Comments
 (0)