-
Notifications
You must be signed in to change notification settings - Fork 215
/
TotalSubscribeResultTest.java
99 lines (85 loc) · 3.84 KB
/
TotalSubscribeResultTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.connectivity.service.messaging.mqtt.hivemq;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.eclipse.ditto.connectivity.model.Source;
import org.eclipse.ditto.connectivity.service.messaging.mqtt.hivemq.subscribing.SubscribeResult;
import org.junit.Test;
import org.mockito.Mockito;
import nl.jqno.equalsverifier.EqualsVerifier;
/**
* Unit test for {@link ConnectionTesterActor.TotalSubscribeResult}.
*/
public final class TotalSubscribeResultTest {
@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(ConnectionTesterActor.TotalSubscribeResult.class)
.usingGetClass()
.verify();
}
@Test
public void ofWithNullSourceSubscribeResultsThrowsException() {
Assertions.assertThatNullPointerException()
.isThrownBy(() -> ConnectionTesterActor.TotalSubscribeResult.of(null))
.withMessage("The sourceSubscribeResults must not be null!")
.withNoCause();
}
@Test
public void totalSubscribeResultsWithSuccessResultsOnlyHasNoFailures() {
final var source = Mockito.mock(Source.class);
final var underTest = ConnectionTesterActor.TotalSubscribeResult.of(List.of(
getSuccessfulSubscribeResult(source),
getSuccessfulSubscribeResult(source),
getSuccessfulSubscribeResult(source)
));
assertThat(underTest.hasFailures()).isFalse();
}
private static SubscribeResult getSuccessfulSubscribeResult(final Source connectionSource) {
final var result = Mockito.mock(SubscribeResult.class);
Mockito.when(result.isSuccess()).thenReturn(true);
Mockito.when(result.getConnectionSource()).thenReturn(connectionSource);
return result;
}
@Test
public void gettersOfMixedTotalSubscribeResultReturnExpected() {
final var source = Mockito.mock(Source.class);
final var sourceSubscribeResults = List.of(
getSuccessfulSubscribeResult(source),
getFailedSubscribeResult(source),
getSuccessfulSubscribeResult(source),
getFailedSubscribeResult(source),
getSuccessfulSubscribeResult(source)
);
final var underTest = ConnectionTesterActor.TotalSubscribeResult.of(sourceSubscribeResults);
try (final var softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(underTest.hasFailures()).as("has failures").isTrue();
softly.assertThat(underTest.failedSubscribeResults())
.as("failed results")
.containsExactly(sourceSubscribeResults.get(1), sourceSubscribeResults.get(3));
softly.assertThat(underTest.successfulSubscribeResults())
.as("successful results")
.containsExactly(sourceSubscribeResults.get(0),
sourceSubscribeResults.get(2),
sourceSubscribeResults.get(4));
}
}
private static SubscribeResult getFailedSubscribeResult(final Source connectionSource) {
final var result = Mockito.mock(SubscribeResult.class);
Mockito.when(result.isSuccess()).thenReturn(false);
Mockito.when(result.getConnectionSource()).thenReturn(connectionSource);
return result;
}
}