1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.util; 17 18 import junit.framework.TestCase; 19 20 import java.util.Arrays; 21 import java.util.List; 22 23 /** 24 * Unit tests for {@link ArrayUtil} 25 */ 26 public class ArrayUtilTest extends TestCase { 27 28 /** 29 * Simple test for {@link ArrayUtil#buildArray(String[][])} 30 */ 31 public void testBuildArray_arrays() { 32 String[] newArray = ArrayUtil.buildArray(new String[] {"1", "2"}, new String[] {"3"}, 33 new String[] {"4"}); 34 assertEquals(4, newArray.length); 35 for (int i = 0; i < 4; i++) { 36 assertEquals(Integer.toString(i+1), newArray[i]); 37 } 38 } 39 40 /** 41 * Make sure that Collections aren't double-wrapped 42 */ 43 public void testJoinCollection() { 44 List<String> list = Arrays.asList("alpha", "beta", "gamma"); 45 final String expected = "alpha, beta, gamma"; 46 String str = ArrayUtil.join(", ", list); 47 assertEquals(expected, str); 48 } 49 50 /** 51 * Make sure that Arrays aren't double-wrapped 52 */ 53 public void testJoinArray() { 54 String[] ary = new String[] {"alpha", "beta", "gamma"}; 55 final String expected = "alpha, beta, gamma"; 56 String str = ArrayUtil.join(", ", (Object[]) ary); 57 assertEquals(expected, str); 58 } 59 60 /** 61 * Make sure that join on varargs arrays work as expected 62 */ 63 public void testJoinNormal() { 64 final String expected = "alpha, beta, gamma"; 65 String str = ArrayUtil.join(", ", "alpha", "beta", "gamma"); 66 assertEquals(expected, str); 67 } 68 } 69