View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 org.kuali.common.util.primitives;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  
21  public class NumbersTest {
22  
23  	@Test
24  	public void test() {
25  		Assert.assertEquals(Byte.class, Numbers.narrow(0).getClass());
26  		Assert.assertEquals(Byte.class, Numbers.narrow(0L).getClass());
27  		Assert.assertEquals(Byte.class, Numbers.narrow(Byte.MAX_VALUE).getClass());
28  		Assert.assertEquals(Byte.class, Numbers.narrow(Byte.MIN_VALUE).getClass());
29  		Assert.assertEquals(Short.class, Numbers.narrow(Short.MAX_VALUE).getClass());
30  		Assert.assertEquals(Short.class, Numbers.narrow(Short.MIN_VALUE).getClass());
31  		Assert.assertEquals(Integer.class, Numbers.narrow(Integer.MAX_VALUE).getClass());
32  		Assert.assertEquals(Integer.class, Numbers.narrow(Integer.MIN_VALUE).getClass());
33  		Assert.assertEquals(Long.class, Numbers.narrow(Long.MAX_VALUE).getClass());
34  		Assert.assertEquals(Long.class, Numbers.narrow(Long.MIN_VALUE).getClass());
35  
36  		Assert.assertEquals((byte) 0, Numbers.narrow(0));
37  		Assert.assertEquals((byte) 0, Numbers.narrow(0L));
38  		Assert.assertEquals(Byte.MAX_VALUE, Numbers.narrow(Byte.MAX_VALUE));
39  		Assert.assertEquals(Byte.MIN_VALUE, Numbers.narrow(Byte.MIN_VALUE));
40  		Assert.assertEquals(Short.MAX_VALUE, Numbers.narrow(Short.MAX_VALUE));
41  		Assert.assertEquals(Short.MIN_VALUE, Numbers.narrow(Short.MIN_VALUE));
42  		Assert.assertEquals(Integer.MAX_VALUE, Numbers.narrow(Integer.MAX_VALUE));
43  		Assert.assertEquals(Integer.MIN_VALUE, Numbers.narrow(Integer.MIN_VALUE));
44  		Assert.assertEquals(Long.MAX_VALUE, Numbers.narrow(Long.MAX_VALUE));
45  		Assert.assertEquals(Long.MIN_VALUE, Numbers.narrow(Long.MIN_VALUE));
46  	}
47  }