View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  
11  import java.util.Calendar;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.fail;
17  
18  public class NumberUtilsTestCase extends AbstractMuleTestCase
19  {
20      static final long l = 1000000000;
21  
22      @Test
23      public void testStringToLong()
24      {
25          assertEquals(l, NumberUtils.toLong("1000000000"));
26      }
27  
28      @Test
29      public void testLongToLong()
30      {
31          assertEquals(l, NumberUtils.toLong(new Long(l)));
32      }
33  
34      @Test
35      public void testIntegerToLong()
36      {
37          assertEquals(l, NumberUtils.toLong(new Integer(1000000000)));
38      }
39  
40      @Test
41      public void testIncompatible()
42      {
43          try
44          {
45              NumberUtils.toLong(Calendar.getInstance().getTime());
46              fail();
47          }
48          catch (IllegalArgumentException e)
49          {
50              // expected
51          }
52      }
53  
54      @Test
55      public void testNull()
56      {
57          try
58          {
59              // need to cast to Object, otherwise compiler would resolve method to
60              // superclass' implementation
61              NumberUtils.toLong((Object)null);
62              fail();
63          }
64          catch (IllegalArgumentException e)
65          {
66              // expected
67          }
68      }
69  
70  }