Skip to content

Commit

Permalink
apacheGH-42002: [Java] Update Unit Tests for Vector Module (apache#42019
Browse files Browse the repository at this point in the history
)

### Rationale for this change

Update package from JUnit 4(`org.junit`) to JUnit 5(`org.junit.jupiter`).

### What changes are included in this PR?

- [x] Replacing `org.junit` with `org.junit.jupiter.api`.
- [x] Updating `Assertions.assertXXX` to `assertXXX` using static imports.
- [x] Updating annotations such as `@ Before`, `@ BeforeClass`, `@ After`, `@ AfterClass`.
  - `@ Before` -> `@ BeforeEach`
  - `@ BeforeClass` -> `@ BeforeAll`
  - `@ After` -> `@ AfterEach`
  - `@ AfterClass` -> `@ AfterAll`
  - `@ Test` -> `@ Test` with `org.junit.jupiter`
- [x] Removing unused `@ Rule` Annotation
- [x] Updating `Parameterized` test
- [x] Doing self review

### Are these changes tested?

Yes, existing tests have passed.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#42002

Authored-by: Hyunseok Seo <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
llama90 authored Jun 7, 2024
1 parent a045770 commit fe4d04f
Show file tree
Hide file tree
Showing 69 changed files with 1,191 additions and 1,144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.apache.arrow.vector;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
Expand All @@ -28,7 +28,7 @@
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.holders.NullableDecimalHolder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.arrow.vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.stream.IntStream;

Expand All @@ -29,22 +29,21 @@
import org.apache.arrow.memory.util.hash.MurmurHasher;
import org.apache.arrow.vector.testing.ValueVectorDataPopulator;
import org.apache.arrow.vector.util.TransferPair;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestBitVector {
private static final String EMPTY_SCHEMA_PATH = "";

private BufferAllocator allocator;

@Before
@BeforeEach
public void init() {
allocator = new RootAllocator(Long.MAX_VALUE);
}

@After
@AfterEach
public void terminate() throws Exception {
allocator.close();
}
Expand Down Expand Up @@ -124,8 +123,8 @@ public void testSplitAndTransfer() throws Exception {
for (int i = 0; i < length; i++) {
int actual = toVector.get(i);
int expected = sourceVector.get(start + i);
assertEquals("different data values not expected --> sourceVector index: " + (start + i) +
" toVector index: " + i, expected, actual);
assertEquals(expected, actual,
"different data values not expected --> sourceVector index: " + (start + i) + " toVector index: " + i);
}
}
}
Expand Down Expand Up @@ -167,8 +166,8 @@ public void testSplitAndTransfer1() throws Exception {
for (int i = 0; i < length; i++) {
int actual = toVector.get(i);
int expected = sourceVector.get(start + i);
assertEquals("different data values not expected --> sourceVector index: " + (start + i) +
" toVector index: " + i, expected, actual);
assertEquals(expected, actual,
"different data values not expected --> sourceVector index: " + (start + i) + " toVector index: " + i);
}
}
}
Expand Down Expand Up @@ -218,8 +217,8 @@ public void testSplitAndTransfer2() throws Exception {
for (int i = 0; i < length; i++) {
int actual = toVector.get(i);
int expected = sourceVector.get(start + i);
assertEquals("different data values not expected --> sourceVector index: " + (start + i) +
" toVector index: " + i, expected, actual);
assertEquals(expected, actual,
"different data values not expected --> sourceVector index: " + (start + i) + " toVector index: " + i);
}
}
}
Expand All @@ -241,9 +240,9 @@ public void testReallocAfterVectorTransfer1() {

for (int i = 0; i < valueCapacity; i++) {
if ((i & 1) == 1) {
assertEquals("unexpected cleared bit at index: " + i, 1, vector.get(i));
assertEquals(1, vector.get(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -259,9 +258,9 @@ public void testReallocAfterVectorTransfer1() {

for (int i = 0; i < valueCapacity * 2; i++) {
if (((i & 1) == 1) || (i == valueCapacity)) {
assertEquals("unexpected cleared bit at index: " + i, 1, vector.get(i));
assertEquals(1, vector.get(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -277,9 +276,9 @@ public void testReallocAfterVectorTransfer1() {

for (int i = 0; i < valueCapacity * 4; i++) {
if (((i & 1) == 1) || (i == valueCapacity) || (i == valueCapacity * 2)) {
assertEquals("unexpected cleared bit at index: " + i, 1, vector.get(i));
assertEquals(1, vector.get(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -297,12 +296,12 @@ public void testReallocAfterVectorTransfer1() {
if (i <= valueCapacity * 4) {
if (((i & 1) == 1) || (i == valueCapacity) ||
(i == valueCapacity * 2) || (i == valueCapacity * 4)) {
assertEquals("unexpected cleared bit at index: " + i, 1, toVector.get(i));
assertEquals(1, toVector.get(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, toVector.isNull(i));
assertTrue(toVector.isNull(i), "unexpected set bit at index: " + i);
}
} else {
assertTrue("unexpected set bit at index: " + i, toVector.isNull(i));
assertTrue(toVector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -325,9 +324,9 @@ public void testReallocAfterVectorTransfer2() {

for (int i = 0; i < valueCapacity; i++) {
if ((i & 1) == 1) {
assertFalse("unexpected cleared bit at index: " + i, vector.isNull(i));
assertFalse(vector.isNull(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -343,9 +342,9 @@ public void testReallocAfterVectorTransfer2() {

for (int i = 0; i < valueCapacity * 2; i++) {
if (((i & 1) == 1) || (i == valueCapacity)) {
assertFalse("unexpected cleared bit at index: " + i, vector.isNull(i));
assertFalse(vector.isNull(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -361,9 +360,9 @@ public void testReallocAfterVectorTransfer2() {

for (int i = 0; i < valueCapacity * 4; i++) {
if (((i & 1) == 1) || (i == valueCapacity) || (i == valueCapacity * 2)) {
assertFalse("unexpected cleared bit at index: " + i, vector.isNull(i));
assertFalse(vector.isNull(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, vector.isNull(i));
assertTrue(vector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand All @@ -381,12 +380,12 @@ public void testReallocAfterVectorTransfer2() {
if (i <= valueCapacity * 4) {
if (((i & 1) == 1) || (i == valueCapacity) ||
(i == valueCapacity * 2) || (i == valueCapacity * 4)) {
assertFalse("unexpected cleared bit at index: " + i, toVector.isNull(i));
assertFalse(toVector.isNull(i), "unexpected cleared bit at index: " + i);
} else {
assertTrue("unexpected set bit at index: " + i, toVector.isNull(i));
assertTrue(toVector.isNull(i), "unexpected set bit at index: " + i);
}
} else {
assertTrue("unexpected set bit at index: " + i, toVector.isNull(i));
assertTrue(toVector.isNull(i), "unexpected set bit at index: " + i);
}
}

Expand Down Expand Up @@ -500,13 +499,13 @@ private void validateRange(int length, int start, int count) {
bitVector.allocateNew(length);
bitVector.setRangeToOne(start, count);
for (int i = 0; i < start; i++) {
Assert.assertTrue(desc + i, bitVector.isNull(i));
assertTrue(bitVector.isNull(i), desc + i);
}
for (int i = start; i < start + count; i++) {
Assert.assertEquals(desc + i, 1, bitVector.get(i));
assertEquals(1, bitVector.get(i), desc + i);
}
for (int i = start + count; i < length; i++) {
Assert.assertTrue(desc + i, bitVector.isNull(i));
assertTrue(bitVector.isNull(i), desc + i);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

package org.apache.arrow.vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.memory.util.MemoryUtil;
import org.apache.arrow.vector.ipc.message.ArrowFieldNode;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestBitVectorHelper {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.apache.arrow.vector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.charset.StandardCharsets;

Expand All @@ -30,7 +30,7 @@
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.CallBack;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestBufferOwnershipTransfer {

Expand Down
Loading

0 comments on commit fe4d04f

Please sign in to comment.