001/*
002 * Copyright The Apache Software Foundation
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020package org.apache.hadoop.hbase.util;
021
022import static org.junit.Assert.assertEquals;
023
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.testclassification.SmallTests;
026import org.junit.ClassRule;
027import org.junit.Rule;
028import org.junit.Test;
029import org.junit.experimental.categories.Category;
030import org.junit.rules.ExpectedException;
031
032@Category({SmallTests.class})
033public class TestClasses {
034
035  @Rule
036  public final ExpectedException thrown = ExpectedException.none();
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040          HBaseClassTestRule.forClass(TestClasses.class);
041
042  @Test
043  public void testExtendedForName() throws ClassNotFoundException {
044    assertEquals(int.class, Classes.extendedForName("int"));
045    assertEquals(long.class, Classes.extendedForName("long"));
046    assertEquals(char.class, Classes.extendedForName("char"));
047    assertEquals(byte.class, Classes.extendedForName("byte"));
048    assertEquals(short.class, Classes.extendedForName("short"));
049    assertEquals(float.class, Classes.extendedForName("float"));
050    assertEquals(double.class, Classes.extendedForName("double"));
051    assertEquals(boolean.class, Classes.extendedForName("boolean"));
052
053    thrown.expect(ClassNotFoundException.class);
054    Classes.extendedForName("foo");
055  }
056
057  @Test
058  public void testStringify() {
059    assertEquals("", Classes.stringify(new Class[0]));
060    assertEquals("NULL", Classes.stringify(null));
061    assertEquals("java.lang.String,java.lang.Integer",
062            Classes.stringify(new Class[]{String.class, Integer.class}));
063  }
064}