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