1 /* 2 * Copyright (C) 2007 The Guava Authors 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 17 package com.google.common.primitives; 18 19 import com.google.common.collect.ImmutableSet; 20 import com.google.common.testing.NullPointerTester; 21 import java.util.Set; 22 import junit.framework.TestCase; 23 24 /** 25 * Unit test for {@link Primitives}. 26 * 27 * @author Kevin Bourrillion 28 */ 29 public class PrimitivesTest extends TestCase { testIsWrapperType()30 public void testIsWrapperType() { 31 assertTrue(Primitives.isWrapperType(Void.class)); 32 assertFalse(Primitives.isWrapperType(void.class)); 33 } 34 testWrap()35 public void testWrap() { 36 assertSame(Integer.class, Primitives.wrap(int.class)); 37 assertSame(Integer.class, Primitives.wrap(Integer.class)); 38 assertSame(String.class, Primitives.wrap(String.class)); 39 } 40 testUnwrap()41 public void testUnwrap() { 42 assertSame(int.class, Primitives.unwrap(Integer.class)); 43 assertSame(int.class, Primitives.unwrap(int.class)); 44 assertSame(String.class, Primitives.unwrap(String.class)); 45 } 46 testAllPrimitiveTypes()47 public void testAllPrimitiveTypes() { 48 Set<Class<?>> primitives = Primitives.allPrimitiveTypes(); 49 assertEquals( 50 ImmutableSet.<Object>of( 51 boolean.class, 52 byte.class, 53 char.class, 54 double.class, 55 float.class, 56 int.class, 57 long.class, 58 short.class, 59 void.class), 60 primitives); 61 62 try { 63 primitives.remove(boolean.class); 64 fail(); 65 } catch (UnsupportedOperationException expected) { 66 } 67 } 68 testAllWrapperTypes()69 public void testAllWrapperTypes() { 70 Set<Class<?>> wrappers = Primitives.allWrapperTypes(); 71 assertEquals( 72 ImmutableSet.<Object>of( 73 Boolean.class, 74 Byte.class, 75 Character.class, 76 Double.class, 77 Float.class, 78 Integer.class, 79 Long.class, 80 Short.class, 81 Void.class), 82 wrappers); 83 84 try { 85 wrappers.remove(Boolean.class); 86 fail(); 87 } catch (UnsupportedOperationException expected) { 88 } 89 } 90 testNullPointerExceptions()91 public void testNullPointerExceptions() { 92 NullPointerTester tester = new NullPointerTester(); 93 tester.testAllPublicStaticMethods(Primitives.class); 94 } 95 } 96