View Javadoc

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