You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArrayUtilsTest.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2012 gitblit.com.
  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.gitblit.tests;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertTrue;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.HashSet;
  22. import java.util.List;
  23. import java.util.Set;
  24. import org.junit.Test;
  25. import com.gitblit.utils.ArrayUtils;
  26. public class ArrayUtilsTest {
  27. @Test
  28. public void testArrays() {
  29. Object [] nullArray = null;
  30. assertTrue(ArrayUtils.isEmpty(nullArray));
  31. Object [] emptyArray = new Object[0];
  32. assertTrue(ArrayUtils.isEmpty(emptyArray));
  33. assertFalse(ArrayUtils.isEmpty(new String [] { "" }));
  34. }
  35. @Test
  36. public void testLists() {
  37. List<?> nullList = null;
  38. assertTrue(ArrayUtils.isEmpty(nullList));
  39. List<?> emptyList = new ArrayList<Object>();
  40. assertTrue(ArrayUtils.isEmpty(emptyList));
  41. List<?> list = Arrays.asList("");
  42. assertFalse(ArrayUtils.isEmpty(list));
  43. }
  44. @Test
  45. public void testSets() {
  46. Set<?> nullSet = null;
  47. assertTrue(ArrayUtils.isEmpty(nullSet));
  48. Set<?> emptySet = new HashSet<Object>();
  49. assertTrue(ArrayUtils.isEmpty(emptySet));
  50. Set<?> set = new HashSet<Object>(Arrays.asList(""));
  51. assertFalse(ArrayUtils.isEmpty(set));
  52. }
  53. }