Skip to content

Commit 8a2abb3

Browse files
author
admitrov
committed
test: remove redundant Kafka port and bootstrap server mocks
1 parent 7dcb368 commit 8a2abb3

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

embedded-native-kafka/src/test/java/com/playtika/testcontainer/nativekafka/configuration/NativeKafkaContainerConfigurationTest.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,13 @@ void shouldCreateNetworkWithProperConfiguration() {
6565
void shouldCreateKafkaContainerWithProperConfiguration() {
6666
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
6767
when(properties.getFileSystemBind()).thenReturn(new NativeKafkaConfigurationProperties.FileSystemBind());
68-
when(properties.getKafkaPort()).thenReturn(9092);
6968

7069
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
7170
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
7271

7372
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
7473
.thenReturn(kafkaContainer);
7574

76-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
77-
when(kafkaContainer.getHost()).thenReturn("localhost");
78-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
79-
8075
GenericContainer<?> result = configuration.nativeKafka(properties, network);
8176

8277
assertThat(result).isEqualTo(kafkaContainer);
@@ -92,18 +87,13 @@ void shouldConfigureFileSystemBindWhenEnabled() throws IOException {
9287

9388
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
9489
when(properties.getFileSystemBind()).thenReturn(fileSystemBind);
95-
when(properties.getKafkaPort()).thenReturn(9092);
9690

9791
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
9892
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
9993

10094
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
10195
.thenReturn(kafkaContainer);
10296

103-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
104-
when(kafkaContainer.getHost()).thenReturn("localhost");
105-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
106-
10797
GenericContainer<?> result = configuration.nativeKafka(properties, network);
10898

10999
assertThat(result).isEqualTo(kafkaContainer);
@@ -121,18 +111,13 @@ void shouldNotConfigureFileSystemBindWhenDisabled() {
121111

122112
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
123113
when(properties.getFileSystemBind()).thenReturn(fileSystemBind);
124-
when(properties.getKafkaPort()).thenReturn(9092);
125114

126115
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
127116
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
128117

129118
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
130119
.thenReturn(kafkaContainer);
131120

132-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
133-
when(kafkaContainer.getHost()).thenReturn("localhost");
134-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
135-
136121
GenericContainer<?> result = configuration.nativeKafka(properties, network);
137122

138123
assertThat(result).isEqualTo(kafkaContainer);
@@ -145,18 +130,13 @@ void shouldNotConfigureFileSystemBindWhenDisabled() {
145130
void shouldRegisterPropertiesCorrectly() {
146131
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
147132
when(properties.getFileSystemBind()).thenReturn(new NativeKafkaConfigurationProperties.FileSystemBind());
148-
when(properties.getKafkaPort()).thenReturn(9092);
149133

150134
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
151135
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
152136

153137
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
154138
.thenReturn(kafkaContainer);
155139

156-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
157-
when(kafkaContainer.getHost()).thenReturn("localhost");
158-
when(kafkaContainer.getMappedPort(9092)).thenReturn(12345);
159-
160140
configuration.nativeKafka(properties, network);
161141
}
162142
}
@@ -181,18 +161,13 @@ void shouldHandleDirectoryCreationWithProperPermissions() {
181161

182162
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
183163
when(properties.getFileSystemBind()).thenReturn(fileSystemBind);
184-
when(properties.getKafkaPort()).thenReturn(9092);
185164

186165
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
187166
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
188167

189168
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
190169
.thenReturn(kafkaContainer);
191170

192-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
193-
when(kafkaContainer.getHost()).thenReturn("localhost");
194-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
195-
196171
configuration.nativeKafka(properties, network);
197172

198173
assertThat(Files.exists(testPath)).isTrue();
@@ -212,18 +187,13 @@ void shouldHandleParentDirectoryCreation() throws IOException {
212187

213188
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
214189
when(properties.getFileSystemBind()).thenReturn(fileSystemBind);
215-
when(properties.getKafkaPort()).thenReturn(9092);
216190

217191
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
218192
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
219193

220194
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
221195
.thenReturn(kafkaContainer);
222196

223-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
224-
when(kafkaContainer.getHost()).thenReturn("localhost");
225-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
226-
227197
configuration.nativeKafka(properties, network);
228198

229199
assertThat(Files.exists(parentPath)).isTrue();
@@ -249,18 +219,13 @@ void shouldHandleExistingDirectoryScenario() throws IOException {
249219

250220
when(properties.getDefaultDockerImage()).thenReturn("apache/kafka-native:4.0.0");
251221
when(properties.getFileSystemBind()).thenReturn(fileSystemBind);
252-
when(properties.getKafkaPort()).thenReturn(9092);
253222

254223
try (MockedStatic<com.playtika.testcontainer.common.utils.ContainerUtils> containerUtilsMock =
255224
mockStatic(com.playtika.testcontainer.common.utils.ContainerUtils.class)) {
256225

257226
containerUtilsMock.when(() -> configureCommonsAndStart(any(KafkaContainer.class), eq(properties), any()))
258227
.thenReturn(kafkaContainer);
259228

260-
when(kafkaContainer.getBootstrapServers()).thenReturn("localhost:9092");
261-
when(kafkaContainer.getHost()).thenReturn("localhost");
262-
when(kafkaContainer.getMappedPort(9092)).thenReturn(9092);
263-
264229
configuration.nativeKafka(properties, network);
265230

266231
assertThat(Files.exists(existingPath)).isTrue();

0 commit comments

Comments
 (0)