-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61ef8fa
commit 668de8b
Showing
3 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...t/java/org/apache/rocketmq/remoting/protocol/header/GetConsumeStatsRequestHeaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.rocketmq.remoting.protocol.header; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class GetConsumeStatsRequestHeaderTest { | ||
|
||
private GetConsumeStatsRequestHeader header; | ||
|
||
@Before | ||
public void setUp() { | ||
header = new GetConsumeStatsRequestHeader(); | ||
} | ||
|
||
@Test | ||
public void updateTopicList_NullTopicList_DoesNotUpdate() { | ||
header.updateTopicList(null); | ||
assertNull(header.getTopicList()); | ||
} | ||
|
||
@Test | ||
public void updateTopicList_EmptyTopicList_SetsEmptyString() { | ||
header.updateTopicList(Collections.emptyList()); | ||
assertNull(header.getTopicList()); | ||
} | ||
|
||
@Test | ||
public void updateTopicList_SingleTopic_SetsSingleTopicString() { | ||
List<String> topicList = Collections.singletonList("TopicA"); | ||
header.updateTopicList(topicList); | ||
assertEquals("TopicA;", header.getTopicList()); | ||
} | ||
|
||
@Test | ||
public void updateTopicList_MultipleTopics_SetsMultipleTopicsString() { | ||
List<String> topicList = Arrays.asList("TopicA", "TopicB", "TopicC"); | ||
header.updateTopicList(topicList); | ||
assertEquals("TopicA;TopicB;TopicC;", header.getTopicList()); | ||
} | ||
|
||
@Test | ||
public void updateTopicList_RepeatedTopics_SetsRepeatedTopicsString() { | ||
List<String> topicList = Arrays.asList("TopicA", "TopicA", "TopicB"); | ||
header.updateTopicList(topicList); | ||
assertEquals("TopicA;TopicA;TopicB;", header.getTopicList()); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_NullTopicList_ReturnsEmptyList() { | ||
header.setTopicList(null); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Collections.emptyList(), topicList); | ||
|
||
header.updateTopicList(new ArrayList<>()); | ||
topicList = header.fetchTopicList(); | ||
assertEquals(Collections.emptyList(), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_EmptyTopicList_ReturnsEmptyList() { | ||
header.setTopicList(""); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Collections.emptyList(), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_BlankTopicList_ReturnsEmptyList() { | ||
header.setTopicList(" "); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Collections.emptyList(), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_SingleTopic_ReturnsSingleTopicList() { | ||
header.setTopicList("TopicA"); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Collections.singletonList("TopicA"), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_MultipleTopics_ReturnsTopicList() { | ||
header.setTopicList("TopicA;TopicB;TopicC"); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Arrays.asList("TopicA", "TopicB", "TopicC"), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_TopicListEndsWithSeparator_ReturnsTopicList() { | ||
header.setTopicList("TopicA;TopicB;"); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Arrays.asList("TopicA", "TopicB"), topicList); | ||
} | ||
|
||
@Test | ||
public void fetchTopicList_TopicListStartsWithSeparator_ReturnsTopicList() { | ||
header.setTopicList(";TopicA;TopicB"); | ||
List<String> topicList = header.fetchTopicList(); | ||
assertEquals(Arrays.asList("TopicA", "TopicB"), topicList); | ||
} | ||
} |