2626import org .apache .druid .utils .CompressionUtils ;
2727import org .hamcrest .CoreMatchers ;
2828import org .hamcrest .MatcherAssert ;
29- import org .junit .Assert ;
30- import org .junit .Rule ;
31- import org .junit .Test ;
3229import org .junit .internal .matchers .ThrowableMessageMatcher ;
33- import org .junit .rules .ExpectedException ;
30+ import org .junit .jupiter .api .Assertions ;
31+ import org .junit .jupiter .api .Test ;
3432
3533import java .io .IOException ;
3634import java .util .Collections ;
3735
3836public class CsvInputFormatTest extends InitializedNullHandlingTest
3937{
40- @ Rule
41- public ExpectedException expectedException = ExpectedException .none ();
42-
4338 @ Test
4439 public void testSerde () throws IOException
4540 {
4641 final ObjectMapper mapper = new ObjectMapper ();
4742 final CsvInputFormat format = new CsvInputFormat (Collections .singletonList ("a" ), "|" , null , true , 10 , null );
4843 final byte [] bytes = mapper .writeValueAsBytes (format );
4944 final CsvInputFormat fromJson = (CsvInputFormat ) mapper .readValue (bytes , InputFormat .class );
50- Assert .assertEquals (format , fromJson );
45+ Assertions .assertEquals (format , fromJson );
5146 }
5247
5348 @ Test
@@ -58,7 +53,7 @@ public void testDeserializeWithoutColumnsWithHasHeaderRow() throws IOException
5853 "{\" type\" :\" csv\" ,\" hasHeaderRow\" :true}" ,
5954 InputFormat .class
6055 );
61- Assert .assertTrue (inputFormat .isFindColumnsFromHeader ());
56+ Assertions .assertTrue (inputFormat .isFindColumnsFromHeader ());
6257 }
6358
6459 @ Test
@@ -69,14 +64,14 @@ public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderTrue() throws
6964 "{\" type\" :\" csv\" ,\" findColumnsFromHeader\" :true}" ,
7065 InputFormat .class
7166 );
72- Assert .assertTrue (inputFormat .isFindColumnsFromHeader ());
67+ Assertions .assertTrue (inputFormat .isFindColumnsFromHeader ());
7368 }
7469
7570 @ Test
7671 public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderFalse ()
7772 {
7873 final ObjectMapper mapper = new ObjectMapper ();
79- final JsonProcessingException e = Assert .assertThrows (
74+ final JsonProcessingException e = Assertions .assertThrows (
8075 JsonProcessingException .class ,
8176 () -> mapper .readValue (
8277 "{\" type\" :\" csv\" ,\" findColumnsFromHeader\" :false}" ,
@@ -96,7 +91,7 @@ public void testDeserializeWithoutColumnsWithFindColumnsFromHeaderFalse()
9691 public void testDeserializeWithoutColumnsWithBothHeaderProperties ()
9792 {
9893 final ObjectMapper mapper = new ObjectMapper ();
99- final JsonProcessingException e = Assert .assertThrows (
94+ final JsonProcessingException e = Assertions .assertThrows (
10095 JsonProcessingException .class ,
10196 () -> mapper .readValue (
10297 "{\" type\" :\" csv\" ,\" findColumnsFromHeader\" :true,\" hasHeaderRow\" :true}" ,
@@ -115,7 +110,7 @@ public void testDeserializeWithoutColumnsWithBothHeaderProperties()
115110 public void testDeserializeWithoutAnyProperties ()
116111 {
117112 final ObjectMapper mapper = new ObjectMapper ();
118- final JsonProcessingException e = Assert .assertThrows (
113+ final JsonProcessingException e = Assertions .assertThrows (
119114 JsonProcessingException .class ,
120115 () -> mapper .readValue ("{\" type\" :\" csv\" }" , InputFormat .class )
121116 );
@@ -135,83 +130,91 @@ public void testDeserializeWithTryParseNumbers() throws IOException
135130 "{\" type\" :\" csv\" ,\" hasHeaderRow\" :true,\" tryParseNumbers\" :true}" ,
136131 InputFormat .class
137132 );
138- Assert .assertTrue (inputFormat .shouldTryParseNumbers ());
133+ Assertions .assertTrue (inputFormat .shouldTryParseNumbers ());
139134 }
140135
141136 @ Test
142137 public void testComma ()
143138 {
144- expectedException .expect (IllegalArgumentException .class );
145- expectedException .expectMessage ("Column[a,] cannot have the delimiter[,] in its name" );
146- new CsvInputFormat (Collections .singletonList ("a," ), "|" , null , false , 0 , null );
139+ IllegalArgumentException e = Assertions .assertThrows (
140+ IllegalArgumentException .class ,
141+ () -> new CsvInputFormat (Collections .singletonList ("a," ), "|" , null , false , 0 , null )
142+ );
143+ Assertions .assertTrue (e .getMessage ().contains ("Column[a,] cannot have the delimiter[,] in its name" ));
147144 }
148145
149146 @ Test
150147 public void testDelimiter ()
151148 {
152- expectedException .expect (IllegalArgumentException .class );
153- expectedException .expectMessage ("Cannot have same delimiter and list delimiter of [,]" );
154- new CsvInputFormat (Collections .singletonList ("a\t " ), "," , null , false , 0 , null );
149+ IllegalArgumentException e = Assertions .assertThrows (
150+ IllegalArgumentException .class ,
151+ () -> new CsvInputFormat (Collections .singletonList ("a\t " ), "," , null , false , 0 , null )
152+ );
153+ Assertions .assertTrue (e .getMessage ().contains ("Cannot have same delimiter and list delimiter of [,]" ));
155154 }
156155
157156 @ Test
158157 public void testFindColumnsFromHeaderWithColumnsReturningItsValue ()
159158 {
160159 final CsvInputFormat format = new CsvInputFormat (Collections .singletonList ("a" ), null , null , true , 0 , null );
161- Assert .assertTrue (format .isFindColumnsFromHeader ());
160+ Assertions .assertTrue (format .isFindColumnsFromHeader ());
162161 }
163162
164163 @ Test
165164 public void testFindColumnsFromHeaderWithMissingColumnsReturningItsValue ()
166165 {
167166 final CsvInputFormat format = new CsvInputFormat (null , null , null , true , 0 , null );
168- Assert .assertTrue (format .isFindColumnsFromHeader ());
167+ Assertions .assertTrue (format .isFindColumnsFromHeader ());
169168 }
170169
171170 @ Test
172171 public void testMissingFindColumnsFromHeaderWithMissingColumnsThrowingError ()
173172 {
174- expectedException .expect (IllegalArgumentException .class );
175- expectedException .expectMessage ("Either [columns] or [findColumnsFromHeader] must be set" );
176- new CsvInputFormat (null , null , null , null , 0 , null );
173+ IllegalArgumentException e = Assertions .assertThrows (
174+ IllegalArgumentException .class ,
175+ () -> new CsvInputFormat (null , null , null , null , 0 , null )
176+ );
177+ Assertions .assertTrue (e .getMessage ().contains ("Either [columns] or [findColumnsFromHeader] must be set" ));
177178 }
178179
179180 @ Test
180181 public void testMissingFindColumnsFromHeaderWithColumnsReturningFalse ()
181182 {
182183 final CsvInputFormat format = new CsvInputFormat (Collections .singletonList ("a" ), null , null , null , 0 , null );
183- Assert .assertFalse (format .isFindColumnsFromHeader ());
184+ Assertions .assertFalse (format .isFindColumnsFromHeader ());
184185 }
185186
186187 @ Test
187188 public void testHasHeaderRowWithMissingFindColumnsThrowingError ()
188189 {
189- expectedException .expect (IllegalArgumentException .class );
190- expectedException .expectMessage ("Cannot accept both [findColumnsFromHeader] and [hasHeaderRow]" );
191- new CsvInputFormat (null , null , true , false , 0 , null );
190+ IllegalArgumentException e = Assertions .assertThrows (
191+ IllegalArgumentException .class ,
192+ () -> new CsvInputFormat (null , null , true , false , 0 , null )
193+ );
194+ Assertions .assertTrue (e .getMessage ().contains ("Cannot accept both [findColumnsFromHeader] and [hasHeaderRow]" ));
192195 }
193196
194197 @ Test
195198 public void testHasHeaderRowWithMissingColumnsReturningItsValue ()
196199 {
197200 final CsvInputFormat format = new CsvInputFormat (null , null , true , null , 0 , null );
198- Assert .assertTrue (format .isFindColumnsFromHeader ());
201+ Assertions .assertTrue (format .isFindColumnsFromHeader ());
199202 }
200203
201204 @ Test
202205 public void test_getWeightedSize_withoutCompression ()
203206 {
204207 final CsvInputFormat format = new CsvInputFormat (null , null , true , null , 0 , null );
205208 final long unweightedSize = 100L ;
206- Assert .assertEquals (unweightedSize , format .getWeightedSize ("file.csv" , unweightedSize ));
209+ Assertions .assertEquals (unweightedSize , format .getWeightedSize ("file.csv" , unweightedSize ));
207210 }
208211
209212 @ Test
210213 public void test_getWeightedSize_withGzCompression ()
211214 {
212215 final CsvInputFormat format = new CsvInputFormat (null , null , true , null , 0 , null );
213216 final long unweightedSize = 100L ;
214- Assert .assertEquals (
217+ Assertions .assertEquals (
215218 unweightedSize * CompressionUtils .COMPRESSED_TEXT_WEIGHT_FACTOR ,
216219 format .getWeightedSize ("file.csv.gz" , unweightedSize )
217220 );
0 commit comments