Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

60 is always set as a confidence value for MacOSXMozillaSubBuilder. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -62,8 +62,6 @@ public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
}
}

model.setConfidence(confidence);

return model;
}
}
Original file line number Diff line number Diff line change
@@ -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());

}
}