From a403a8cc79479399d29b4619c4f8daa723583855 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 6 Nov 2017 15:20:06 +0900 Subject: [PATCH 1/2] - Add to junit library for testing. - Add to a testcase occurring NullPointerException. --- pom.xml | 10 ++++++++++ .../ua/tooling/UserAgentDetectorTest.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/test/net/pieroxy/ua/tooling/UserAgentDetectorTest.java diff --git a/pom.xml b/pom.xml index 0e79dcd..f3985fc 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ UTF-8 + 4.11 @@ -61,6 +62,15 @@ + + + + junit + junit + ${junit.version} + test + + diff --git a/src/main/test/net/pieroxy/ua/tooling/UserAgentDetectorTest.java b/src/main/test/net/pieroxy/ua/tooling/UserAgentDetectorTest.java new file mode 100644 index 0000000..2860308 --- /dev/null +++ b/src/main/test/net/pieroxy/ua/tooling/UserAgentDetectorTest.java @@ -0,0 +1,16 @@ +package net.pieroxy.ua.tooling; + +import net.pieroxy.ua.detection.UserAgentDetector; +import org.junit.Test; + +/** + * @author sam + */ +public class UserAgentDetectorTest { + @Test(expected = NumberFormatException.class) + public void testInCaseNullPointerException() { + String userAgent = "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MMB29Q; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.106 Mobile Safari/537.36 MobileApp/1.0 (Android; 4.0.3; com.ebay.kr.g9)"; + UserAgentDetector detector = new UserAgentDetector(); + detector.parseUserAgent(userAgent); + } +} From 5c0e33b59b96e094b2ce6f0bbd7eb18c9042ddc4 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 6 Nov 2017 16:27:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Simple=20fix=20-=20Ensure=20not=20occurring?= =?UTF-8?q?=20to=20NullPointerException.=CB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/pieroxy/ua/detection/UserAgentDetectionHelper.java | 5 +++-- .../test/net/pieroxy/ua/tooling/UserAgentDetectorTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pieroxy/ua/detection/UserAgentDetectionHelper.java b/src/main/java/net/pieroxy/ua/detection/UserAgentDetectionHelper.java index 7a69a78..86826ab 100644 --- a/src/main/java/net/pieroxy/ua/detection/UserAgentDetectionHelper.java +++ b/src/main/java/net/pieroxy/ua/detection/UserAgentDetectionHelper.java @@ -1,6 +1,5 @@ package net.pieroxy.ua.detection; -import java.io.*; -import java.util.*; + class UserAgentDetectionHelper { public static void consumeMozilla(UserAgentContext context) { @@ -54,6 +53,8 @@ public static void addExtensionsCommonForLibs(UserAgentContext context, UserAgen } public static boolean greaterThan(String integer, int target) { + if (integer == null || integer.length() == 0) + return false; String beginning = integer; for (int i=0 ; i