OSDN Git Service

remove parseInt() from StringUtils.
[jindolf/Jindolf.git] / src / test / java / jp / sfjp / jindolf / data / AnchorTest.java
1 /*
2  */
3
4 package jp.sfjp.jindolf.data;
5
6 import java.util.regex.Matcher;
7 import java.util.regex.Pattern;
8 import org.junit.After;
9 import org.junit.AfterClass;
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 import static org.junit.Assert.*;
15
16 /**
17  *
18  */
19 public class AnchorTest {
20
21     public AnchorTest() {
22     }
23
24     @BeforeClass
25     public static void setUpClass() {
26     }
27
28     @AfterClass
29     public static void tearDownClass() {
30     }
31
32     @Before
33     public void setUp() {
34     }
35
36     @After
37     public void tearDown() {
38     }
39
40     /**
41      * Test of parseInt method, of class Anchor.
42      */
43     @Test
44     public void testParseInt_3args_1() {
45         System.out.println("parseInt");
46
47         int result;
48         Matcher matcher;
49         Pattern pattern;
50         String input = "ABC123PQR456XYZ";
51
52         pattern = Pattern.compile("([0-9]+)[A-Z]*([0-9]+)");
53         matcher = pattern.matcher(input);
54
55         assertTrue(matcher.find());
56
57         result = Anchor.parseInt(input, matcher, 1);
58         assertEquals(123, result);
59
60         result = Anchor.parseInt(input, matcher, 2);
61         assertEquals(456, result);
62
63         try{
64             Anchor.parseInt(null, matcher, 1);
65             fail();
66         }catch(NullPointerException e){
67         }
68
69         try{
70             Anchor.parseInt(input, null, 1);
71             fail();
72         }catch(NullPointerException e){
73         }
74
75         return;
76     }
77
78     /**
79      * Test of parseInt method, of class Anchor.
80      */
81     @Test
82     public void testParseInt_3args_2() {
83         System.out.println("parseInt");
84
85         int result;
86
87         try{
88             Anchor.parseInt(null, 1, 3);
89             fail();
90         }catch(NullPointerException e){
91         }
92
93         result = Anchor.parseInt("1234567", 2, 5);
94         assertEquals(345, result);
95
96         result = Anchor.parseInt("1234567", 2, 3);
97         assertEquals(3, result);
98
99         result = Anchor.parseInt("1234567", 2, 2);
100         assertEquals(0, result);
101
102         result = Anchor.parseInt("1234567", 2, 1);
103         assertEquals(0, result);
104
105         result = Anchor.parseInt("1234567", 0, 0);
106         assertEquals(0, result);
107
108         try{
109             Anchor.parseInt("1234567", 2, 999);
110             fail();
111         }catch(StringIndexOutOfBoundsException e){
112         }
113
114         try{
115             Anchor.parseInt("1234567", -1, 5);
116             fail();
117         }catch(StringIndexOutOfBoundsException e){
118         }
119
120         return;
121     }
122
123 }