Skip to content

Commit e782cd8

Browse files
committed
[broker-23] organize imports, refactor tests
1 parent 00bef5c commit e782cd8

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

src/main/java/com/ss/mqtt/broker/service/impl/SimpleSubscriptionService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import static com.ss.mqtt.broker.model.ActionResult.EMPTY;
44
import static com.ss.mqtt.broker.model.ActionResult.FAILED;
5+
import static com.ss.mqtt.broker.model.reason.code.SubscribeAckReasonCode.SHARED_SUBSCRIPTIONS_NOT_SUPPORTED;
6+
import static com.ss.mqtt.broker.model.reason.code.SubscribeAckReasonCode.UNSPECIFIED_ERROR;
7+
import static com.ss.mqtt.broker.model.reason.code.SubscribeAckReasonCode.WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED;
58
import static com.ss.mqtt.broker.model.reason.code.UnsubscribeAckReasonCode.*;
69
import static com.ss.mqtt.broker.util.TopicUtils.*;
710
import com.ss.mqtt.broker.model.*;
@@ -61,11 +64,11 @@ public class SimpleSubscriptionService implements SubscriptionService {
6164
if (session == null) {
6265
return null;
6366
} else if (!config.isSharedSubscriptionAvailable() && isShared(topic)) {
64-
return SubscribeAckReasonCode.SHARED_SUBSCRIPTIONS_NOT_SUPPORTED;
67+
return SHARED_SUBSCRIPTIONS_NOT_SUPPORTED;
6568
} else if (!config.isWildcardSubscriptionAvailable() && hasWildcard(topic)) {
66-
return SubscribeAckReasonCode.WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED;
69+
return WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED;
6770
} else if (isInvalid(topic)) {
68-
return SubscribeAckReasonCode.UNSPECIFIED_ERROR;
71+
return UNSPECIFIED_ERROR;
6972
} else {
7073
session.addSubscriber(subscribe);
7174
topicSubscribers.addSubscriber(client, subscribe);
@@ -91,7 +94,7 @@ public class SimpleSubscriptionService implements SubscriptionService {
9194
if (session == null) {
9295
return null;
9396
} else if (isInvalid(topic)) {
94-
return UNSPECIFIED_ERROR;
97+
return UnsubscribeAckReasonCode.UNSPECIFIED_ERROR;
9598
} else if (topicSubscribers.removeSubscriber(client, topic)) {
9699
session.removeSubscriber(topic);
97100
return SUCCESS;

src/test/groovy/com/ss/mqtt/broker/test/model/TopicTest.groovy

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import static com.ss.mqtt.broker.util.TopicUtils.*
99
class TopicTest extends Specification {
1010

1111
@Unroll
12-
def "should create topic name: #stringTopicName"(String stringTopicName, int levelsCount) {
12+
def "should create topic name: [#stringTopicName]"() {
1313
when:
1414
def topicName = buildTopicName(stringTopicName)
1515
then:
@@ -23,11 +23,9 @@ class TopicTest extends Specification {
2323
}
2424

2525
@Unroll
26-
def "should fail create topic name: #stringTopicName"(String stringTopicName) {
27-
when:
28-
def topicName = buildTopicName(stringTopicName)
29-
then:
30-
isInvalid(topicName)
26+
def "should fail create topic name: [#stringTopicName]"() {
27+
expect:
28+
isInvalid(buildTopicName(stringTopicName))
3129
where:
3230
stringTopicName << [
3331
"",
@@ -37,7 +35,7 @@ class TopicTest extends Specification {
3735
}
3836

3937
@Unroll
40-
def "should create topic filter: #stringTopicFilter"(String stringTopicFilter, int levelsCount) {
38+
def "should create topic filter: [#stringTopicFilter]"() {
4139
when:
4240
def topicFilter = buildTopicFilter(stringTopicFilter)
4341
then:
@@ -53,11 +51,9 @@ class TopicTest extends Specification {
5351
}
5452

5553
@Unroll
56-
def "should fail create topic filter: #stringTopicFilter"(String stringTopicFilter) {
57-
when:
58-
def topicFilter = buildTopicFilter(stringTopicFilter)
59-
then:
60-
isInvalid(topicFilter)
54+
def "should fail create topic filter: [#stringTopicFilter]"() {
55+
expect:
56+
isInvalid(buildTopicFilter(stringTopicFilter))
6157
where:
6258
stringTopicFilter << [
6359
"",
@@ -71,7 +67,7 @@ class TopicTest extends Specification {
7167
}
7268

7369
@Unroll
74-
def "should match topicFilter[#topicFilter] with topicName[#topicName]"(String topicFilter, String topicName) {
70+
def "should match topic filter: [#topicFilter] with topic name: [#topicName]"() {
7571
expect:
7672
buildTopicName(topicName).match(buildTopicFilter(topicFilter))
7773
where:
@@ -83,7 +79,7 @@ class TopicTest extends Specification {
8379
}
8480

8581
@Unroll
86-
def "should not match topicFilter[#topicFilter] with topicName[#topicName]"(String topicFilter, String topicName) {
82+
def "should not match topic filter: [#topicFilter] with topic name: [#topicName]"() {
8783
expect:
8884
!buildTopicName(topicName).match(buildTopicFilter(topicFilter))
8985
where:

src/test/groovy/com/ss/mqtt/broker/test/util/TopicUtilsTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import static com.ss.mqtt.broker.util.TopicUtils.*
99
class TopicUtilsTest extends Specification {
1010

1111
@Unroll
12-
def "should create valid topic name: #topicName"(String topicName) {
12+
def "should create valid topic name: [#topicName]"() {
1313
expect:
1414
!isInvalid(buildTopicName(topicName))
1515
where:
@@ -19,7 +19,7 @@ class TopicUtilsTest extends Specification {
1919
}
2020

2121
@Unroll
22-
def "should create valid topic filter: #topicFilter"(String topicFilter) {
22+
def "should create valid topic filter: [#topicFilter]"() {
2323
expect:
2424
!isInvalid(buildTopicFilter(topicFilter))
2525
where:
@@ -31,7 +31,7 @@ class TopicUtilsTest extends Specification {
3131
}
3232

3333
@Unroll
34-
def "should detect invalid topic name: #topicName"(String topicName) {
34+
def "should detect invalid topic name: [#topicName]"() {
3535
expect:
3636
isInvalid(buildTopicName(topicName))
3737
where:
@@ -43,7 +43,7 @@ class TopicUtilsTest extends Specification {
4343
}
4444

4545
@Unroll
46-
def "should detect invalid topic filter: #topicFilter"(String topicFilter) {
46+
def "should detect invalid topic filter: [#topicFilter]"() {
4747
expect:
4848
isInvalid(buildTopicFilter(topicFilter))
4949
where:

0 commit comments

Comments
 (0)