1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.opencsv.bean.comparator;
17
18 import org.junit.jupiter.api.Test;
19
20 import java.util.Arrays;
21
22 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
23
24 @SuppressWarnings("deprecation")
25 public class ComparatorTest {
26
27 @Test
28 public void testComparatorNull() {
29 String[] array = new String[]{"abc", null, "bcd", "cde", "def", "xyz", "wxy"};
30 Arrays.sort(array, new LiteralComparator<String>(null));
31 assertArrayEquals(new String[]{null, "abc", "bcd", "cde", "def", "wxy", "xyz"}, array);
32 }
33
34
35
36
37
38
39
40 @Test
41 public void testLiteralComparatorInteger() {
42 Integer[] array = new Integer[]{1, 2, 3, 4, 5, 6, null, 12, 10};
43 Arrays.sort(array, new LiteralComparator<>(new Integer[]{2, 4, 6, 8, 1, 3, 5, 7}));
44 assertArrayEquals(new Integer[]{2, 4, 6, 1, 3, 5, null, 10, 12}, array);
45 }
46
47
48
49
50
51
52 @Test
53 public void testLiteralComparatorString() {
54 String[] array = new String[]{"abc", null, "bcd", "cde", "def", "xyz", "wxy"};
55 Arrays.sort(array, new LiteralComparator<>(new String[]{null, "efg", "bcd", "cde", "abc", "def"}));
56 assertArrayEquals(new String[]{null, "bcd", "cde", "abc", "def", "wxy", "xyz"}, array);
57 }
58 }