1010import org .mockito .Mock ;
1111import org .mockito .MockedStatic ;
1212import org .mockito .junit .jupiter .MockitoExtension ;
13- import org .springframework .core .env .ConfigurableEnvironment ;
14- import org .springframework .core .env .MutablePropertySources ;
1513import org .testcontainers .containers .GenericContainer ;
1614import org .testcontainers .containers .Network ;
1715import org .testcontainers .kafka .KafkaContainer ;
2523import static org .mockito .ArgumentMatchers .any ;
2624import static org .mockito .ArgumentMatchers .eq ;
2725import static org .mockito .Mockito .mockStatic ;
28- import static org .mockito .Mockito .verify ;
2926import static org .mockito .Mockito .when ;
3027
3128@ ExtendWith (MockitoExtension .class )
@@ -35,9 +32,6 @@ class NativeKafkaContainerConfigurationTest {
3532 @ Mock
3633 private NativeKafkaConfigurationProperties properties ;
3734
38- @ Mock
39- private ConfigurableEnvironment environment ;
40-
4135 @ Mock
4236 private Network network ;
4337
@@ -47,9 +41,6 @@ class NativeKafkaContainerConfigurationTest {
4741 @ Mock
4842 private GenericContainer <?> genericContainer ;
4943
50- @ Mock
51- private MutablePropertySources mutablePropertySources ;
52-
5344 @ TempDir
5445 private Path tempDir ;
5546
@@ -72,7 +63,6 @@ void shouldCreateNetworkWithProperConfiguration() {
7263 @ Test
7364 @ DisplayName ("should create kafka container with proper docker image and network configuration" )
7465 void shouldCreateKafkaContainerWithProperConfiguration () {
75- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
7666 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
7767 when (properties .getFileSystemBind ()).thenReturn (new NativeKafkaConfigurationProperties .FileSystemBind ());
7868 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -87,7 +77,7 @@ void shouldCreateKafkaContainerWithProperConfiguration() {
8777 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
8878 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
8979
90- GenericContainer <?> result = configuration .nativeKafka (properties , environment , network );
80+ GenericContainer <?> result = configuration .nativeKafka (properties , network );
9181
9282 assertThat (result ).isEqualTo (kafkaContainer );
9383 containerUtilsMock .verify (() -> configureCommonsAndStart (any (KafkaContainer .class ), eq (properties ), any ()));
@@ -100,7 +90,6 @@ void shouldConfigureFileSystemBindWhenEnabled() throws IOException {
10090 NativeKafkaConfigurationProperties .FileSystemBind fileSystemBind =
10191 new NativeKafkaConfigurationProperties .FileSystemBind (true , tempDir .toString ());
10292
103- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
10493 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
10594 when (properties .getFileSystemBind ()).thenReturn (fileSystemBind );
10695 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -115,7 +104,7 @@ void shouldConfigureFileSystemBindWhenEnabled() throws IOException {
115104 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
116105 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
117106
118- GenericContainer <?> result = configuration .nativeKafka (properties , environment , network );
107+ GenericContainer <?> result = configuration .nativeKafka (properties , network );
119108
120109 assertThat (result ).isEqualTo (kafkaContainer );
121110
@@ -130,7 +119,6 @@ void shouldNotConfigureFileSystemBindWhenDisabled() {
130119 NativeKafkaConfigurationProperties .FileSystemBind fileSystemBind =
131120 new NativeKafkaConfigurationProperties .FileSystemBind (false , tempDir .toString ());
132121
133- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
134122 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
135123 when (properties .getFileSystemBind ()).thenReturn (fileSystemBind );
136124 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -145,17 +133,16 @@ void shouldNotConfigureFileSystemBindWhenDisabled() {
145133 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
146134 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
147135
148- GenericContainer <?> result = configuration .nativeKafka (properties , environment , network );
136+ GenericContainer <?> result = configuration .nativeKafka (properties , network );
149137
150138 assertThat (result ).isEqualTo (kafkaContainer );
151139 assertThat (Files .exists (tempDir .resolve ("embedded-native-kafka-data" ))).isFalse ();
152140 }
153141 }
154142
155143 @ Test
156- @ DisplayName ("should register environment properties correctly" )
157- void shouldRegisterEnvironmentPropertiesCorrectly () {
158- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
144+ @ DisplayName ("should register properties correctly" )
145+ void shouldRegisterPropertiesCorrectly () {
159146 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
160147 when (properties .getFileSystemBind ()).thenReturn (new NativeKafkaConfigurationProperties .FileSystemBind ());
161148 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -170,9 +157,7 @@ void shouldRegisterEnvironmentPropertiesCorrectly() {
170157 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
171158 when (kafkaContainer .getMappedPort (9092 )).thenReturn (12345 );
172159
173- configuration .nativeKafka (properties , environment , network );
174-
175- verify (environment ).getPropertySources ();
160+ configuration .nativeKafka (properties , network );
176161 }
177162 }
178163
@@ -194,7 +179,6 @@ void shouldHandleDirectoryCreationWithProperPermissions() {
194179 NativeKafkaConfigurationProperties .FileSystemBind fileSystemBind =
195180 new NativeKafkaConfigurationProperties .FileSystemBind (true , testPath .toString ());
196181
197- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
198182 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
199183 when (properties .getFileSystemBind ()).thenReturn (fileSystemBind );
200184 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -209,7 +193,7 @@ void shouldHandleDirectoryCreationWithProperPermissions() {
209193 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
210194 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
211195
212- configuration .nativeKafka (properties , environment , network );
196+ configuration .nativeKafka (properties , network );
213197
214198 assertThat (Files .exists (testPath )).isTrue ();
215199 assertThat (Files .isDirectory (testPath )).isTrue ();
@@ -226,7 +210,6 @@ void shouldHandleParentDirectoryCreation() throws IOException {
226210 NativeKafkaConfigurationProperties .FileSystemBind fileSystemBind =
227211 new NativeKafkaConfigurationProperties .FileSystemBind (true , testPath .toString ());
228212
229- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
230213 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
231214 when (properties .getFileSystemBind ()).thenReturn (fileSystemBind );
232215 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -241,7 +224,7 @@ void shouldHandleParentDirectoryCreation() throws IOException {
241224 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
242225 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
243226
244- configuration .nativeKafka (properties , environment , network );
227+ configuration .nativeKafka (properties , network );
245228
246229 assertThat (Files .exists (parentPath )).isTrue ();
247230 assertThat (Files .exists (testPath )).isTrue ();
@@ -264,7 +247,6 @@ void shouldHandleExistingDirectoryScenario() throws IOException {
264247 NativeKafkaConfigurationProperties .FileSystemBind fileSystemBind =
265248 new NativeKafkaConfigurationProperties .FileSystemBind (true , existingPath .toString ());
266249
267- when (environment .getPropertySources ()).thenReturn (mutablePropertySources );
268250 when (properties .getDefaultDockerImage ()).thenReturn ("apache/kafka-native:4.0.0" );
269251 when (properties .getFileSystemBind ()).thenReturn (fileSystemBind );
270252 when (properties .getKafkaPort ()).thenReturn (9092 );
@@ -279,9 +261,9 @@ void shouldHandleExistingDirectoryScenario() throws IOException {
279261 when (kafkaContainer .getHost ()).thenReturn ("localhost" );
280262 when (kafkaContainer .getMappedPort (9092 )).thenReturn (9092 );
281263
282- configuration .nativeKafka (properties , environment , network );
264+ configuration .nativeKafka (properties , network );
283265
284266 assertThat (Files .exists (existingPath )).isTrue ();
285267 }
286268 }
287- }
269+ }
0 commit comments