From 94ff93f4f3f4d1df8c627cd1804650683006acb0 Mon Sep 17 00:00:00 2001 From: Alexey Zotov Date: Mon, 12 Aug 2013 10:53:09 +0400 Subject: [PATCH] 60 is always set as a confidence value for MacOSXMozillaSubBuilder. --- .../os/mozilla/MacOSXMozillaSubBuilder.java | 6 +-- .../mozilla/MacOSXMozillaSubBuilderTest.java | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 test/com/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilderTest.java diff --git a/src/org/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilder.java b/src/org/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilder.java index 8c129b4..cf35d8d 100644 --- a/src/org/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilder.java +++ b/src/org/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilder.java @@ -22,6 +22,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.openddr.simpleapi.oddr.builder.Builder; import org.openddr.simpleapi.oddr.model.BuiltObject; import org.openddr.simpleapi.oddr.model.UserAgent; @@ -41,8 +42,7 @@ public BuiltObject build(UserAgent userAgent, int confidenceTreshold) { model.setMajorRevision("-"); model.setVendor("Apple"); model.setModel("Mac OS X"); - - int confidence = 60; + model.setConfidence(60); Matcher versionMatcher = versionPattern.matcher(userAgent.getPatternElementsInside()); if (versionMatcher.find()) { @@ -62,8 +62,6 @@ public BuiltObject build(UserAgent userAgent, int confidenceTreshold) { } } - model.setConfidence(confidence); - return model; } } diff --git a/test/com/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilderTest.java b/test/com/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilderTest.java new file mode 100644 index 0000000..3e2188d --- /dev/null +++ b/test/com/openddr/simpleapi/oddr/builder/os/mozilla/MacOSXMozillaSubBuilderTest.java @@ -0,0 +1,48 @@ +package com.openddr.simpleapi.oddr.builder.os.mozilla; + +import org.junit.Test; +import org.openddr.simpleapi.oddr.builder.os.mozilla.MacOSXMozillaSubBuilder; +import org.openddr.simpleapi.oddr.model.UserAgent; +import org.openddr.simpleapi.oddr.model.UserAgentFactory; +import org.openddr.simpleapi.oddr.model.os.OperatingSystem; +import org.w3c.ddr.simple.exception.InitializationException; +import org.w3c.ddr.simple.exception.NameException; + +import java.io.IOException; + +import static org.junit.Assert.*; + +public class MacOSXMozillaSubBuilderTest { + + private final MacOSXMozillaSubBuilder macOSXMozillaSubBuilder = new MacOSXMozillaSubBuilder(); + + @Test + public void testCanBuild() throws InitializationException, IOException, NameException { + + final UserAgent wrongUserAgent = UserAgentFactory.newUserAgent("wrong user agent"); + assertFalse(macOSXMozillaSubBuilder.canBuild(wrongUserAgent)); + + final UserAgent realUserAgent = UserAgentFactory.newUserAgent( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:11.0) Gecko/20100101 Firefox/11.0"); + assertTrue(macOSXMozillaSubBuilder.canBuild(realUserAgent)); + } + + @Test + public void testBuild() { + + final UserAgent userAgent = UserAgentFactory.newUserAgent( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:11.0) Gecko/20100101 Firefox/11.0"); + final OperatingSystem os = (OperatingSystem) macOSXMozillaSubBuilder.build(userAgent, 0); + + assertEquals("Apple", os.getVendor()); + assertEquals("Mac OS X", os.getModel()); + assertEquals(80, os.getConfidence()); + assertEquals("10.5", os.getVersion()); + assertEquals("10", os.getMajorRevision()); + assertEquals("5", os.getMinorRevision()); + assertEquals("0", os.getMicroRevision()); + assertEquals("0", os.getNanoRevision()); + assertNull(os.getDescription()); + + } +}