Skip to content

Commit 15e20d7

Browse files
authored
test: convert tests in druid-processing to junit5 pt. 6 (apache#19346)
1 parent 4095bb3 commit 15e20d7

49 files changed

Lines changed: 1128 additions & 1140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

processing/src/test/java/org/apache/druid/common/utils/SerializerUtilsTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
package org.apache.druid.common.utils;
2121

2222
import org.apache.druid.java.util.common.StringUtils;
23-
import org.junit.After;
24-
import org.junit.Assert;
25-
import org.junit.Before;
26-
import org.junit.Test;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
import java.io.ByteArrayInputStream;
2929
import java.io.ByteArrayOutputStream;
@@ -47,7 +47,7 @@ public class SerializerUtilsTest
4747
private byte[] longsByte;
4848
private ByteArrayOutputStream outStream;
4949

50-
@Before
50+
@BeforeEach
5151
public void setUpByteArrays() throws IOException
5252
{
5353
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -97,15 +97,15 @@ public void testWriteInts() throws IOException
9797
{
9898
serializerUtils.writeInts(outStream, ints);
9999
byte[] actuals = outStream.toByteArray();
100-
Assert.assertArrayEquals(intsByte, actuals);
100+
Assertions.assertArrayEquals(intsByte, actuals);
101101
}
102102

103103
@Test
104104
public void testWriteFloats() throws IOException
105105
{
106106
serializerUtils.writeFloats(outStream, floats);
107107
byte[] actuals = outStream.toByteArray();
108-
Assert.assertArrayEquals(floatsByte, actuals);
108+
Assertions.assertArrayEquals(floatsByte, actuals);
109109
}
110110

111111
@Test
@@ -120,15 +120,15 @@ public void testChannelWritefloat() throws IOException
120120
}
121121
float expected = serializerUtils.readFloat(inputstream);
122122
float actuals = floats[index];
123-
Assert.assertEquals(expected, actuals, delta);
123+
Assertions.assertEquals(expected, actuals, delta);
124124
}
125125

126126
@Test
127127
public void testWriteLongs() throws IOException
128128
{
129129
serializerUtils.writeLongs(outStream, longs);
130130
byte[] actuals = outStream.toByteArray();
131-
Assert.assertArrayEquals(longsByte, actuals);
131+
Assertions.assertArrayEquals(longsByte, actuals);
132132
}
133133

134134
@Test
@@ -142,7 +142,7 @@ public void testChannelWritelong() throws IOException
142142
inputstream.close();
143143
long expected = serializerUtils.readLong(inputstream);
144144
long actuals = longs[index];
145-
Assert.assertEquals(expected, actuals);
145+
Assertions.assertEquals(expected, actuals);
146146
}
147147

148148
@Test
@@ -151,7 +151,7 @@ public void testReadInts() throws IOException
151151
ByteArrayInputStream inputstream = new ByteArrayInputStream(intsByte);
152152
int[] actuals = serializerUtils.readInts(inputstream);
153153
inputstream.close();
154-
Assert.assertArrayEquals(ints, actuals);
154+
Assertions.assertArrayEquals(ints, actuals);
155155
}
156156

157157
@Test
@@ -160,7 +160,7 @@ public void testReadFloats() throws IOException
160160
ByteArrayInputStream inputstream = new ByteArrayInputStream(floatsByte);
161161
float[] actuals = serializerUtils.readFloats(inputstream);
162162
inputstream.close();
163-
Assert.assertArrayEquals(floats, actuals, delta);
163+
Assertions.assertArrayEquals(floats, actuals, delta);
164164
}
165165

166166
@Test
@@ -169,7 +169,7 @@ public void testReadLongs() throws IOException
169169
ByteArrayInputStream inputstream = new ByteArrayInputStream(longsByte);
170170
long[] actuals = serializerUtils.readLongs(inputstream);
171171
inputstream.close();
172-
Assert.assertArrayEquals(longs, actuals);
172+
Assertions.assertArrayEquals(longs, actuals);
173173
}
174174

175175
@Test
@@ -178,7 +178,7 @@ public void testReadStrings() throws IOException
178178
ByteArrayInputStream inputstream = new ByteArrayInputStream(stringsByte);
179179
String[] actuals = serializerUtils.readStrings(inputstream);
180180
inputstream.close();
181-
Assert.assertArrayEquals(strings, actuals);
181+
Assertions.assertArrayEquals(strings, actuals);
182182
}
183183

184184
@Test
@@ -192,7 +192,7 @@ public void testChannelWriteString() throws IOException
192192
inputstream.close();
193193
String expected = serializerUtils.readString(inputstream);
194194
String actuals = strings[index];
195-
Assert.assertEquals(expected, actuals);
195+
Assertions.assertEquals(expected, actuals);
196196
}
197197

198198
@Test
@@ -202,10 +202,10 @@ public void testByteBufferReadStrings()
202202
buffer.put(stringsByte);
203203
buffer.flip();
204204
String[] actuals = serializerUtils.readStrings(buffer);
205-
Assert.assertArrayEquals(strings, actuals);
205+
Assertions.assertArrayEquals(strings, actuals);
206206
}
207207

208-
@After
208+
@AfterEach
209209
public void tearDown() throws IOException
210210
{
211211
serializerUtils = null;

processing/src/test/java/org/apache/druid/data/input/impl/CsvInputFormatTest.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,23 @@
2626
import org.apache.druid.utils.CompressionUtils;
2727
import org.hamcrest.CoreMatchers;
2828
import org.hamcrest.MatcherAssert;
29-
import org.junit.Assert;
30-
import org.junit.Rule;
31-
import org.junit.Test;
3229
import 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

3533
import java.io.IOException;
3634
import java.util.Collections;
3735

3836
public 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
);

processing/src/test/java/org/apache/druid/data/input/impl/HttpEntityTest.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
import com.sun.net.httpserver.HttpServer;
2626
import org.apache.commons.io.IOUtils;
2727
import org.apache.druid.java.util.common.StringUtils;
28-
import org.junit.Assert;
29-
import org.junit.Before;
30-
import org.junit.Rule;
31-
import org.junit.Test;
32-
import org.junit.rules.ExpectedException;
28+
import org.junit.jupiter.api.Assertions;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3331
import org.mockito.AdditionalAnswers;
3432
import org.mockito.ArgumentMatchers;
3533
import org.mockito.Mockito;
@@ -54,7 +52,7 @@ public class HttpEntityTest
5452
private URLConnection urlConnection;
5553
private InputStream inputStreamMock;
5654

57-
@Before
55+
@BeforeEach
5856
public void setup() throws IOException
5957
{
6058
uri = Mockito.mock(URI.class);
@@ -67,9 +65,6 @@ public void setup() throws IOException
6765
Mockito.when(inputStreamMock.skip(ArgumentMatchers.anyLong())).then(AdditionalAnswers.returnsFirstArg());
6866
}
6967

70-
@Rule
71-
public ExpectedException expectedException = ExpectedException.none();
72-
7368
@Test
7469
public void testOpenInputStream() throws IOException, URISyntaxException
7570
{
@@ -103,7 +98,7 @@ public void testOpenInputStream() throws IOException, URISyntaxException
10398
inputStream = HttpEntity.openInputStream(url, "", null, 0, Collections.emptyMap());
10499
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5, Collections.emptyMap());
105100
inputStream.skip(5);
106-
Assert.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
101+
Assertions.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
107102
}
108103
finally {
109104
IOUtils.closeQuietly(inputStream);
@@ -136,8 +131,8 @@ public void testRequestHeaders() throws IOException, URISyntaxException
136131
(httpExchange) -> {
137132
Headers headers = httpExchange.getRequestHeaders();
138133
for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
139-
Assert.assertTrue(headers.containsKey(entry.getKey()));
140-
Assert.assertEquals(headers.get(entry.getKey()).get(0), entry.getValue());
134+
Assertions.assertTrue(headers.containsKey(entry.getKey()));
135+
Assertions.assertEquals(headers.get(entry.getKey()).get(0), entry.getValue());
141136
}
142137
String payload = "12345678910";
143138
byte[] outputBytes = payload.getBytes(StandardCharsets.UTF_8);
@@ -156,7 +151,7 @@ public void testRequestHeaders() throws IOException, URISyntaxException
156151
inputStream = HttpEntity.openInputStream(url, "", null, 0, requestHeaders);
157152
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5, requestHeaders);
158153
inputStream.skip(5);
159-
Assert.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
154+
Assertions.assertTrue(IOUtils.contentEquals(inputStream, inputStreamPartial));
160155
}
161156
finally {
162157
IOUtils.closeQuietly(inputStream);

0 commit comments

Comments
 (0)