• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.util;
2 
3 import java.util.Arrays;
4 import java.util.HashSet;
5 
6 import org.junit.Assert;
7 
8 import com.fasterxml.jackson.databind.BaseMapTest;
9 import com.fasterxml.jackson.databind.util.ArrayBuilders.BooleanBuilder;
10 import com.fasterxml.jackson.databind.util.ArrayBuilders.ByteBuilder;
11 import com.fasterxml.jackson.databind.util.ArrayBuilders.DoubleBuilder;
12 import com.fasterxml.jackson.databind.util.ArrayBuilders.FloatBuilder;
13 import com.fasterxml.jackson.databind.util.ArrayBuilders.IntBuilder;
14 import com.fasterxml.jackson.databind.util.ArrayBuilders.LongBuilder;
15 import com.fasterxml.jackson.databind.util.ArrayBuilders.ShortBuilder;
16 
17 public class ArrayBuildersTest extends BaseMapTest
18 {
19 	// [databind#157]
testInsertInListNoDup()20 	public void testInsertInListNoDup()
21 	{
22         String [] arr = new String[]{"me", "you", "him"};
23         String [] newarr;
24 
25         newarr = ArrayBuilders.insertInListNoDup(arr, "you");
26         Assert.assertArrayEquals(new String[]{"you", "me", "him"}, newarr);
27 
28         newarr = ArrayBuilders.insertInListNoDup(arr, "me");
29         Assert.assertArrayEquals(new String[]{"me", "you","him"}, newarr);
30 
31         newarr = ArrayBuilders.insertInListNoDup(arr, "him");
32         Assert.assertArrayEquals(new String[]{"him", "me", "you"}, newarr);
33 
34         newarr = ArrayBuilders.insertInListNoDup(arr, "foobar");
35         Assert.assertArrayEquals(new String[]{"foobar", "me", "you", "him"}, newarr);
36 	}
37 
testBuilderAccess()38      public void testBuilderAccess()
39      {
40          ArrayBuilders builders = new ArrayBuilders();
41 
42          BooleanBuilder bb = builders.getBooleanBuilder();
43          assertNotNull(bb);
44          assertSame(bb, builders.getBooleanBuilder());
45 
46          ByteBuilder b2 = builders.getByteBuilder();
47          assertNotNull(b2);
48          assertSame(b2, builders.getByteBuilder());
49 
50          ShortBuilder sb = builders.getShortBuilder();
51          assertNotNull(sb);
52          assertSame(sb, builders.getShortBuilder());
53 
54          IntBuilder ib = builders.getIntBuilder();
55          assertNotNull(ib);
56          assertSame(ib, builders.getIntBuilder());
57 
58          LongBuilder lb = builders.getLongBuilder();
59          assertNotNull(lb);
60          assertSame(lb, builders.getLongBuilder());
61 
62          FloatBuilder fb = builders.getFloatBuilder();
63          assertNotNull(fb);
64          assertSame(fb, builders.getFloatBuilder());
65 
66          DoubleBuilder db = builders.getDoubleBuilder();
67          assertNotNull(db);
68          assertSame(db, builders.getDoubleBuilder());
69      }
70 
testArrayComparator()71      public void testArrayComparator()
72      {
73          final int[] INT3 = new int[] { 3, 4, 5 };
74          Object comp = ArrayBuilders.getArrayComparator(INT3);
75          assertFalse(comp.equals(null));
76          assertTrue(comp.equals(INT3));
77          assertTrue(comp.equals(new int[] { 3, 4, 5 }));
78          assertFalse(comp.equals(new int[] { 5 }));
79          assertFalse(comp.equals(new int[] { 3, 4 }));
80          assertFalse(comp.equals(new int[] { 3, 5, 4 }));
81          assertFalse(comp.equals(new int[] { 3, 4, 5, 6 }));
82      }
83 
testArraySet()84      public void testArraySet()
85      {
86          HashSet<String> set = ArrayBuilders.arrayToSet(new String[] { "foo", "bar" });
87          assertEquals(2, set.size());
88          assertEquals(new HashSet<String>(Arrays.asList("bar", "foo")), set);
89      }
90 }
91