7
7
import org .apache .flink .connector .datagen .source .GeneratorFunction ;
8
8
import org .apache .flink .connector .kafka .sink .KafkaRecordSerializationSchema ;
9
9
import org .apache .flink .connector .kafka .sink .KafkaSink ;
10
- import org .junit .Test ;
11
- import static org .junit .Assert .*;
10
+ import org .junit .jupiter . api . Test ;
11
+ import static org .junit .jupiter . api . Assertions .*;
12
12
import java .util .Properties ;
13
13
import java .util .HashMap ;
14
14
import java .util .Map ;
@@ -33,20 +33,20 @@ public void testCreateDataGeneratorSource() throws Exception {
33
33
DataGeneratorSource <StockPrice > source = (DataGeneratorSource <StockPrice >) createDataGeneratorSourceMethod .invoke (
34
34
null , dataGenProps , generatorFunction , typeInfo );
35
35
36
- assertNotNull ("DataGeneratorSource should not be null" , source );
36
+ assertNotNull (source , "DataGeneratorSource should not be null" );
37
37
38
38
// Test with null properties (should use default rate)
39
39
source = (DataGeneratorSource <StockPrice >) createDataGeneratorSourceMethod .invoke (
40
40
null , null , generatorFunction , typeInfo );
41
41
42
- assertNotNull ("DataGeneratorSource should not be null with null properties" , source );
42
+ assertNotNull (source , "DataGeneratorSource should not be null with null properties" );
43
43
44
44
// Test with empty properties (should use default rate)
45
45
Properties emptyProps = new Properties ();
46
46
source = (DataGeneratorSource <StockPrice >) createDataGeneratorSourceMethod .invoke (
47
47
null , emptyProps , generatorFunction , typeInfo );
48
48
49
- assertNotNull ("DataGeneratorSource should not be null with empty properties" , source );
49
+ assertNotNull (source , "DataGeneratorSource should not be null with empty properties" );
50
50
}
51
51
52
52
@ Test
@@ -72,7 +72,7 @@ public void testCreateKafkaSink() throws Exception {
72
72
KafkaSink <StockPrice > kafkaSink = (KafkaSink <StockPrice >) createKafkaSinkMethod .invoke (
73
73
null , kafkaProps , recordSerializationSchema );
74
74
75
- assertNotNull ("KafkaSink should not be null" , kafkaSink );
75
+ assertNotNull (kafkaSink , "KafkaSink should not be null" );
76
76
}
77
77
78
78
@ Test
@@ -85,20 +85,18 @@ public void testKafkaPartitioningKey() {
85
85
byte [] key1 = stock1 .getTicker ().getBytes ();
86
86
byte [] key2 = stock2 .getTicker ().getBytes ();
87
87
88
- assertNotNull ("Kafka key should not be null" , key1 );
89
- assertNotNull ("Kafka key should not be null" , key2 );
90
- assertTrue ("Kafka key should not be empty" , key1 . length > 0 );
91
- assertTrue ("Kafka key should not be empty" , key2 . length > 0 );
88
+ assertNotNull (key1 , "Kafka key should not be null" );
89
+ assertNotNull (key2 , "Kafka key should not be null" );
90
+ assertTrue (key1 . length > 0 , "Kafka key should not be empty" );
91
+ assertTrue (key2 . length > 0 , "Kafka key should not be empty" );
92
92
93
93
// Test that different tickers produce different keys
94
- assertFalse ("Different tickers should produce different keys" ,
95
- java .util .Arrays .equals (key1 , key2 ));
94
+ assertFalse (java .util .Arrays .equals (key1 , key2 ), "Different tickers should produce different keys" );
96
95
97
96
// Test that same ticker produces same key
98
97
StockPrice stock3 = new StockPrice ("2024-01-15T10:30:47" , "AAPL" , 175.50f );
99
98
byte [] key3 = stock3 .getTicker ().getBytes ();
100
- assertTrue ("Same ticker should produce same key" ,
101
- java .util .Arrays .equals (key1 , key3 ));
99
+ assertTrue (java .util .Arrays .equals (key1 , key3 ), "Same ticker should produce same key" );
102
100
}
103
101
104
102
@ Test
@@ -109,9 +107,9 @@ public void testConditionalSinkValidation() {
109
107
// Test with no sinks configured - should be invalid
110
108
boolean hasKinesis = appProperties .get ("KinesisSink" ) != null ;
111
109
boolean hasKafka = appProperties .get ("KafkaSink" ) != null ;
112
- assertFalse ("Should not have Kinesis sink when not configured" , hasKinesis );
113
- assertFalse ("Should not have Kafka sink when not configured" , hasKafka );
114
- assertTrue ("Should require at least one sink" , ! hasKinesis && ! hasKafka );
110
+ assertFalse (hasKinesis , "Should not have Kinesis sink when not configured" );
111
+ assertFalse (hasKafka , "Should not have Kafka sink when not configured" );
112
+ assertTrue (! hasKinesis && ! hasKafka , "Should require at least one sink" );
115
113
116
114
// Test with only Kinesis configured - should be valid
117
115
Properties kinesisProps = new Properties ();
@@ -121,9 +119,9 @@ public void testConditionalSinkValidation() {
121
119
122
120
hasKinesis = appProperties .get ("KinesisSink" ) != null ;
123
121
hasKafka = appProperties .get ("KafkaSink" ) != null ;
124
- assertTrue ("Should have Kinesis sink when configured" , hasKinesis );
125
- assertFalse ("Should not have Kafka sink when not configured" , hasKafka );
126
- assertTrue ("Should be valid with one sink" , hasKinesis || hasKafka );
122
+ assertTrue (hasKinesis , "Should have Kinesis sink when configured" );
123
+ assertFalse (hasKafka , "Should not have Kafka sink when not configured" );
124
+ assertTrue (hasKinesis || hasKafka , "Should be valid with one sink" );
127
125
128
126
// Test with only Kafka configured - should be valid
129
127
appProperties .clear ();
@@ -134,17 +132,17 @@ public void testConditionalSinkValidation() {
134
132
135
133
hasKinesis = appProperties .get ("KinesisSink" ) != null ;
136
134
hasKafka = appProperties .get ("KafkaSink" ) != null ;
137
- assertFalse ("Should not have Kinesis sink when not configured" , hasKinesis );
138
- assertTrue ("Should have Kafka sink when configured" , hasKafka );
139
- assertTrue ("Should be valid with one sink" , hasKinesis || hasKafka );
135
+ assertFalse (hasKinesis , "Should not have Kinesis sink when not configured" );
136
+ assertTrue (hasKafka , "Should have Kafka sink when configured" );
137
+ assertTrue (hasKinesis || hasKafka , "Should be valid with one sink" );
140
138
141
139
// Test with both configured - should be valid
142
140
appProperties .put ("KinesisSink" , kinesisProps );
143
141
144
142
hasKinesis = appProperties .get ("KinesisSink" ) != null ;
145
143
hasKafka = appProperties .get ("KafkaSink" ) != null ;
146
- assertTrue ("Should have Kinesis sink when configured" , hasKinesis );
147
- assertTrue ("Should have Kafka sink when configured" , hasKafka );
148
- assertTrue ("Should be valid with both sinks" , hasKinesis || hasKafka );
144
+ assertTrue (hasKinesis , "Should have Kinesis sink when configured" );
145
+ assertTrue (hasKafka , "Should have Kafka sink when configured" );
146
+ assertTrue (hasKinesis || hasKafka , "Should be valid with both sinks" );
149
147
}
150
148
}
0 commit comments