OSDN Git Service

Merge commit 'cb03a1ed529387c1084e04e6f141eb9d35d095b8'
[jindolf/Jindolf.git] / src / test / java / jp / sfjp / jindolf / data / AnchorTest.java
diff --git a/src/test/java/jp/sfjp/jindolf/data/AnchorTest.java b/src/test/java/jp/sfjp/jindolf/data/AnchorTest.java
new file mode 100644 (file)
index 0000000..fc2a22d
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ */
+
+package jp.sfjp.jindolf.data;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class AnchorTest {
+
+    public AnchorTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() {
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of parseInt method, of class Anchor.
+     */
+    @Test
+    public void testParseInt_3args_1() {
+        System.out.println("parseInt");
+
+        int result;
+        Matcher matcher;
+        Pattern pattern;
+        String input = "ABC123PQR456XYZ";
+
+        pattern = Pattern.compile("([0-9]+)[A-Z]*([0-9]+)");
+        matcher = pattern.matcher(input);
+
+        assertTrue(matcher.find());
+
+        result = Anchor.parseInt(input, matcher, 1);
+        assertEquals(123, result);
+
+        result = Anchor.parseInt(input, matcher, 2);
+        assertEquals(456, result);
+
+        try{
+            Anchor.parseInt(null, matcher, 1);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        try{
+            Anchor.parseInt(input, null, 1);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        return;
+    }
+
+    /**
+     * Test of parseInt method, of class Anchor.
+     */
+    @Test
+    public void testParseInt_3args_2() {
+        System.out.println("parseInt");
+
+        int result;
+
+        try{
+            Anchor.parseInt(null, 1, 3);
+            fail();
+        }catch(NullPointerException e){
+        }
+
+        result = Anchor.parseInt("1234567", 2, 5);
+        assertEquals(345, result);
+
+        result = Anchor.parseInt("1234567", 2, 3);
+        assertEquals(3, result);
+
+        result = Anchor.parseInt("1234567", 2, 2);
+        assertEquals(0, result);
+
+        result = Anchor.parseInt("1234567", 2, 1);
+        assertEquals(0, result);
+
+        result = Anchor.parseInt("1234567", 0, 0);
+        assertEquals(0, result);
+
+        try{
+            Anchor.parseInt("1234567", 2, 999);
+            fail();
+        }catch(StringIndexOutOfBoundsException e){
+        }
+
+        try{
+            Anchor.parseInt("1234567", -1, 5);
+            fail();
+        }catch(StringIndexOutOfBoundsException e){
+        }
+
+        return;
+    }
+
+}