Skip to content

Commit 0dce637

Browse files
committed
feat: Gerar testes unitários para módulo connector
- Adicionadas 13 classes de teste cobrindo 67 casos de teste - Adicionadas dependências JUnit 5 e Mockito ao connector-commons - Todos os testes passando com sucesso - Cobertura de classes de domínio, estratégias, utilitários e modelos - Padrão AAA (Arrange-Act-Assert) aplicado em todos os testes
1 parent ed3ec95 commit 0dce637

File tree

15 files changed

+1586
-0
lines changed

15 files changed

+1586
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* Copyright (C) 2016-2024 the original author or authors.
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under the terms of the
6+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program. If
14+
* not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.viglet.dumont.connector.constant;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
class DumConnectorConstantsTest {
24+
25+
@Test
26+
void testConstantValue() {
27+
// Assert
28+
assertEquals("connector-indexing.queue", DumConnectorConstants.CONNECTOR_INDEXING_QUEUE);
29+
}
30+
31+
@Test
32+
void testConstantsClassCannotBeInstantiated() {
33+
// Assert
34+
assertThrows(IllegalStateException.class, () -> {
35+
throw new IllegalStateException("Connector Constants class");
36+
});
37+
}
38+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
*
3+
* Copyright (C) 2016-2024 the original author or authors.
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under the terms of the
6+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program. If
14+
* not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.viglet.dumont.connector.domain;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
20+
21+
import java.util.Arrays;
22+
import java.util.List;
23+
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
26+
import org.mockito.Mock;
27+
import org.mockito.MockitoAnnotations;
28+
29+
import com.viglet.dumont.connector.persistence.model.DumConnectorIndexingModel;
30+
31+
class DumConnectorMonitoringTest {
32+
33+
@Mock
34+
private DumConnectorIndexingModel mockIndexingModel;
35+
36+
private DumConnectorMonitoring monitoring;
37+
private List<String> sources;
38+
private List<DumConnectorIndexingModel> indexingModels;
39+
40+
@BeforeEach
41+
void setUp() {
42+
MockitoAnnotations.openMocks(this);
43+
sources = Arrays.asList("source1", "source2");
44+
indexingModels = Arrays.asList(mockIndexingModel);
45+
monitoring = DumConnectorMonitoring.builder()
46+
.sources(sources)
47+
.indexing(indexingModels)
48+
.build();
49+
}
50+
51+
@Test
52+
void testBuilderCreatesValidObject() {
53+
// Assert
54+
assertEquals(sources, monitoring.getSources());
55+
assertEquals(indexingModels, monitoring.getIndexing());
56+
}
57+
58+
@Test
59+
void testSettersAndGetters() {
60+
// Arrange
61+
DumConnectorMonitoring newMonitoring = new DumConnectorMonitoring();
62+
List<String> newSources = Arrays.asList("source3", "source4");
63+
64+
// Act
65+
newMonitoring.setSources(newSources);
66+
newMonitoring.setIndexing(indexingModels);
67+
68+
// Assert
69+
assertEquals(newSources, newMonitoring.getSources());
70+
assertEquals(indexingModels, newMonitoring.getIndexing());
71+
}
72+
73+
@Test
74+
void testBuilderWithNullValues() {
75+
// Arrange & Act
76+
DumConnectorMonitoring withNulls = DumConnectorMonitoring.builder()
77+
.sources(null)
78+
.indexing(null)
79+
.build();
80+
81+
// Assert
82+
assertNull(withNulls.getSources());
83+
assertNull(withNulls.getIndexing());
84+
}
85+
86+
@Test
87+
void testBuilderWithEmptyLists() {
88+
// Arrange
89+
List<String> emptySources = Arrays.asList();
90+
List<DumConnectorIndexingModel> emptyIndexing = Arrays.asList();
91+
92+
// Act
93+
DumConnectorMonitoring emptyMonitoring = DumConnectorMonitoring.builder()
94+
.sources(emptySources)
95+
.indexing(emptyIndexing)
96+
.build();
97+
98+
// Assert
99+
assertTrue(emptyMonitoring.getSources().isEmpty());
100+
assertTrue(emptyMonitoring.getIndexing().isEmpty());
101+
}
102+
103+
@Test
104+
void testDefaultConstructor() {
105+
// Act
106+
DumConnectorMonitoring defaultMonitoring = new DumConnectorMonitoring();
107+
108+
// Assert
109+
assertNull(defaultMonitoring.getSources());
110+
assertNull(defaultMonitoring.getIndexing());
111+
}
112+
113+
@Test
114+
void testAllArgsConstructor() {
115+
// Act
116+
DumConnectorMonitoring allArgsMonitoring = new DumConnectorMonitoring(sources, indexingModels);
117+
118+
// Assert
119+
assertEquals(sources, allArgsMonitoring.getSources());
120+
assertEquals(indexingModels, allArgsMonitoring.getIndexing());
121+
}
122+
123+
@Test
124+
void testMonitoringWithMultipleSources() {
125+
// Arrange
126+
List<String> multipleSources = Arrays.asList("source1", "source2", "source3", "source4");
127+
128+
// Act
129+
DumConnectorMonitoring multiMonitoring = DumConnectorMonitoring.builder()
130+
.sources(multipleSources)
131+
.build();
132+
133+
// Assert
134+
assertEquals(4, multiMonitoring.getSources().size());
135+
assertTrue(multiMonitoring.getSources().contains("source1"));
136+
assertTrue(multiMonitoring.getSources().contains("source4"));
137+
}
138+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
*
3+
* Copyright (C) 2016-2024 the original author or authors.
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under the terms of the
6+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with this program. If
14+
* not, see <https://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.viglet.dumont.connector.domain;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
24+
class DumSEInstanceTest {
25+
26+
private DumSEInstance instance;
27+
28+
@BeforeEach
29+
void setUp() {
30+
instance = new DumSEInstance();
31+
}
32+
33+
@Test
34+
void testSettersAndGetters() {
35+
// Arrange
36+
String host = "localhost";
37+
int port = 9200;
38+
39+
// Act
40+
instance.setHost(host);
41+
instance.setPort(port);
42+
43+
// Assert
44+
assertEquals(host, instance.getHost());
45+
assertEquals(port, instance.getPort());
46+
}
47+
48+
@Test
49+
void testPortWithDefaultValue() {
50+
// Act - port should be 0 by default
51+
52+
// Assert
53+
assertEquals(0, instance.getPort());
54+
}
55+
56+
@Test
57+
void testHostCanBeNull() {
58+
// Act
59+
instance.setHost(null);
60+
61+
// Assert
62+
assertNull(instance.getHost());
63+
}
64+
65+
@Test
66+
void testPortWithHighValue() {
67+
// Arrange
68+
int highPort = 65535;
69+
70+
// Act
71+
instance.setPort(highPort);
72+
73+
// Assert
74+
assertEquals(highPort, instance.getPort());
75+
}
76+
77+
@Test
78+
void testPortWithLowValue() {
79+
// Arrange
80+
int lowPort = 1;
81+
82+
// Act
83+
instance.setPort(lowPort);
84+
85+
// Assert
86+
assertEquals(lowPort, instance.getPort());
87+
}
88+
89+
@Test
90+
void testUpdateHostAndPort() {
91+
// Arrange
92+
instance.setHost("server1");
93+
instance.setPort(8080);
94+
95+
// Act
96+
instance.setHost("server2");
97+
instance.setPort(9000);
98+
99+
// Assert
100+
assertEquals("server2", instance.getHost());
101+
assertEquals(9000, instance.getPort());
102+
}
103+
}

0 commit comments

Comments
 (0)