OSDN Git Service

Zeroで動作させるとタイトル読み込みがうまくいかないバグのテストケース作成
[coroid/NicoBrowser.git] / test / nicobrowser / NicoHttpClientTest.java
index 0bf1a05..6ff3a54 100644 (file)
@@ -2,30 +2,34 @@
 package nicobrowser;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import nicobrowser.entity.NicoContent;
-import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 import javax.persistence.Persistence;
+import nicobrowser.entity.NicoContent;
 import nicobrowser.entity.NicoContent.Status;
 import nicobrowser.search.SearchKind;
+import nicobrowser.search.SearchResult;
 import nicobrowser.search.SortKind;
 import nicobrowser.search.SortOrder;
-import nicobrowser.search.SearchResult;
 import org.apache.http.HttpException;
 import org.junit.After;
 import org.junit.AfterClass;
+import static org.junit.Assert.*;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.*;
 
 /**
  *
@@ -306,4 +310,25 @@ public class NicoHttpClientTest {
         assertTrue(commFile.exists());
         assertTrue(tcommFile.exists());
     }
+
+    /**
+     *
+     */
+    @Test
+    public void testGetTitleInWatchPageZero() throws NoSuchMethodException, IOException, IllegalAccessException,
+            IllegalArgumentException, InvocationTargetException {
+        final String title = "【MMD】 WAVEFILE fullver. 【モーション完成】";
+        final Method m = NicoHttpClient.class.getDeclaredMethod("getTitleInWatchPage", InputStream.class);
+        m.setAccessible(true);
+
+        final FileInputStream fisHarajuku = new FileInputStream(new File("testdata/hara_watch.html"));
+        final String titleHarajuku = (String) m.invoke(instance, fisHarajuku);
+        fisHarajuku.close();
+        assertEquals(title, titleHarajuku);
+
+        final FileInputStream fisZero = new FileInputStream(new File("testdata/zero_watch.html"));
+        final String titleZero = (String) m.invoke(instance, fisZero);
+        fisZero.close();
+        assertEquals(title, titleZero);
+    }
 }