OSDN Git Service

ci: add tests
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Wed, 4 May 2022 06:54:40 +0000 (15:54 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Wed, 4 May 2022 06:54:40 +0000 (15:54 +0900)
generated/database.json
src/com/ranfa/lib/JST.java
src/test/JSTTest.java

index ca62c1c..6f788bf 100644 (file)
   }, {
     "attribute" : "全タイプ",
     "name" : "ココカラミライヘ!",
-    "difficulty" : "MASTER+",
+    "difficulty" : "MASTER+",
     "level" : 30,
     "notes" : 843,
-    "albumType" : "Not-implemented"
+    "albumType" : "ALBUM A"
   }, {
     "attribute" : "全タイプ",
     "name" : "ココカラミライヘ!",
     "level" : 30,
     "notes" : 996,
     "albumType" : "ALBUM C"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ココカラミライヘ!",
+    "difficulty" : "MASTER+",
+    "level" : 30,
+    "notes" : 844,
+    "albumType" : "ALBUM A"
+  }, {
+    "attribute" : "キュート",
+    "name" : "まほうのまくら",
+    "difficulty" : "DEBUT",
+    "level" : 7,
+    "notes" : 85,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "まほうのまくら",
+    "difficulty" : "REGULAR",
+    "level" : 12,
+    "notes" : 144,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "まほうのまくら",
+    "difficulty" : "PRO",
+    "level" : 17,
+    "notes" : 299,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "まほうのまくら",
+    "difficulty" : "MASTER",
+    "level" : 26,
+    "notes" : 496,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "まほうのまくら",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 803,
+    "albumType" : "Not-implemented"
+  }, {
+    "attribute" : "パッション",
+    "name" : "14平米にスーベニア",
+    "difficulty" : "LIGHT",
+    "level" : 5,
+    "notes" : 108,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "パッション",
+    "name" : "14平米にスーベニア",
+    "difficulty" : "TRICK",
+    "level" : 16,
+    "notes" : 372,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "キラッ!満開スマイル",
+    "difficulty" : "LIGHT",
+    "level" : 7,
+    "notes" : 161,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "キラッ!満開スマイル",
+    "difficulty" : "TRICK",
+    "level" : 17,
+    "notes" : 409,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "クール",
+    "name" : "Packing Her Favorite",
+    "difficulty" : "DEBUT",
+    "level" : 8,
+    "notes" : 135,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "クール",
+    "name" : "Packing Her Favorite",
+    "difficulty" : "REGULAR",
+    "level" : 13,
+    "notes" : 231,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "クール",
+    "name" : "Packing Her Favorite",
+    "difficulty" : "PRO",
+    "level" : 17,
+    "notes" : 361,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "クール",
+    "name" : "Packing Her Favorite",
+    "difficulty" : "MASTER",
+    "level" : 25,
+    "notes" : 598,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "メモリーブロッサム",
+    "difficulty" : "DEBUT",
+    "level" : 6,
+    "notes" : 93,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "メモリーブロッサム",
+    "difficulty" : "REGULAR",
+    "level" : 12,
+    "notes" : 183,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "メモリーブロッサム",
+    "difficulty" : "PRO",
+    "level" : 16,
+    "notes" : 323,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "メモリーブロッサム",
+    "difficulty" : "MASTER",
+    "level" : 25,
+    "notes" : 491,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "キュート",
+    "name" : "メモリーブロッサム",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 730,
+    "albumType" : "Not-implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "サラバ、愛しき悲しみたちよ",
+    "difficulty" : "DEBUT",
+    "level" : 7,
+    "notes" : 96,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "サラバ、愛しき悲しみたちよ",
+    "difficulty" : "REGULAR",
+    "level" : 13,
+    "notes" : 179,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "サラバ、愛しき悲しみたちよ",
+    "difficulty" : "PRO",
+    "level" : 16,
+    "notes" : 402,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "サラバ、愛しき悲しみたちよ",
+    "difficulty" : "MASTER",
+    "level" : 25,
+    "notes" : 628,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "サラバ、愛しき悲しみたちよ",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 992,
+    "albumType" : "Always"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ピンキージョーンズ",
+    "difficulty" : "DEBUT",
+    "level" : 8,
+    "notes" : 124,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ピンキージョーンズ",
+    "difficulty" : "REGULAR",
+    "level" : 13,
+    "notes" : 191,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ピンキージョーンズ",
+    "difficulty" : "PRO",
+    "level" : 18,
+    "notes" : 406,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ピンキージョーンズ",
+    "difficulty" : "MASTER",
+    "level" : 25,
+    "notes" : 605,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "ピンキージョーンズ",
+    "difficulty" : "MASTER+",
+    "level" : 28,
+    "notes" : 946,
+    "albumType" : "Always"
   } ]
 }
\ No newline at end of file
index cd6f348..3affc5e 100644 (file)
@@ -2,8 +2,6 @@ package com.ranfa.lib;
 
 import java.io.IOException;
 import java.net.InetAddress;
-import java.net.SocketException;
-import java.net.UnknownHostException;
 import java.util.Date;
 import java.util.Objects;
 
@@ -13,6 +11,13 @@ import org.apache.commons.net.ntp.TimeInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * JST(日本標準時)を <a href="https://www.nict.go.jp/">情報通信研究機構</a> から取得するユーティリティクラスです
+ * <p>
+ * @author hizum
+ *
+ * @version 4.0.0
+ */
 public class JST {
        
        // Logger
@@ -22,33 +27,34 @@ public class JST {
        // private constructor
        private JST() { /* do nothing */ }
        
-       public static Date JSTNow() {
+       /**
+        * フィールド {@link #SERVER_NAME} で指定されているサーバーから時刻を取得し、そのまま {@link Date} 型に変換して返却します。
+        * <p>
+        * @return 日本標準時
+        * @throws IOException 日本標準時取得時に入出力エラーが起こった場合
+        */
+       public static Date JSTNow() throws IOException {
                NTPUDPClient client = new NTPUDPClient();
-               InetAddress address = null;
-               try {
-                       address = InetAddress.getByName(SERVER_NAME);
-               } catch (UnknownHostException e) {
-                       // TODO 自動生成された catch ブロック
-                       e.printStackTrace();
-               }
-               try {
-                       client.open();
-               } catch (SocketException e) {
-                       // TODO 自動生成された catch ブロック
-                       e.printStackTrace();
-               }
-               TimeInfo info = null;
-               try {
-                       info = client.getTime(Objects.requireNonNull(address));
-               } catch (IOException e) {
-                       // TODO 自動生成された catch ブロック
-                       e.printStackTrace();
-               }
-               NtpV3Packet packet = Objects.requireNonNull(info).getMessage();
+               InetAddress address = InetAddress.getByName(SERVER_NAME);
+               client.open();
+               TimeInfo info = client.getTime(Objects.requireNonNull(address));
                info.computeDetails();
                LOG.debug("NTPClient: {}", client);
                LOG.debug("NetAddress: {}", address);
                LOG.debug("Time info: {}", info);
+               return validate(info);
+       }
+
+       /**
+        * 渡された引数から独自にオフセットを計算し、取得した情報との加重平均を取って返します。
+        * <p>
+        * 基本は取得オフセットと同じ値になることが予想されます。
+        * @param info サーバーから取得した情報
+        * @param packet サーバーから取得した情報のパケット
+        * @return
+        */
+       private static Date validate(TimeInfo info) {
+               final NtpV3Packet packet = info.getMessage();
                long t1 = packet.getOriginateTimeStamp().getTime();
                long t2 = packet.getReceiveTimeStamp().getTime();
                long t3 = packet.getTransmitTimeStamp().getTime();
index 05edfd5..367d0ad 100644 (file)
@@ -2,6 +2,8 @@ package test;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+
 import org.junit.Test;
 
 import com.ranfa.lib.JST;
@@ -10,6 +12,10 @@ public class JSTTest {
 
        @Test
        public void JSTNonNullTest() {
-               assertNotNull(JST.JSTNow());
+               try {
+                       assertNotNull(JST.JSTNow());
+               } catch (IOException e) {
+                       fail(e.getMessage());
+               }
        }
 }