Search in sources :

Example 1 with ConcatNONDuplicatedCalculator

use of nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator in project yauaa by nielsbasjes.

the class TestConcatenation method testFieldConcatenation.

@Test
void testFieldConcatenation() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined1", "One", "Two");
    fc.calculate(userAgent);
    assertEquals("One Two", userAgent.getValue("Combined1"));
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "One");
    fc.calculate(userAgent);
    assertEquals("One", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "MinusOne", "One");
    fc.calculate(userAgent);
    assertEquals("MinusOne One", userAgent.getValue("Combined3"));
    fc = new ConcatNONDuplicatedCalculator("Combined4", "One", "MinusOne");
    fc.calculate(userAgent);
    assertEquals("One MinusOne", userAgent.getValue("Combined4"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 2 with ConcatNONDuplicatedCalculator

use of nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator in project yauaa by nielsbasjes.

the class TestConcatenation method testFieldConcatenationNoConfidence.

@Test
void testFieldConcatenationNoConfidence() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "MinusOne");
    fc.calculate(userAgent);
    assertEquals("One MinusOne", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "MinusOne", "Two");
    fc.calculate(userAgent);
    assertEquals("MinusOne Two", userAgent.getValue("Combined3"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 3 with ConcatNONDuplicatedCalculator

use of nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator in project yauaa by nielsbasjes.

the class TestConcatenation method testFieldConcatenationSamePrefix.

@Test
void testFieldConcatenationSamePrefix() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined1", "One", "Two");
    fc.calculate(userAgent);
    assertEquals("One Two", userAgent.getValue("Combined1"));
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "One");
    fc.calculate(userAgent);
    assertEquals("One", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "One", "One Two");
    fc.calculate(userAgent);
    assertEquals("One Two", userAgent.getValue("Combined3"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 4 with ConcatNONDuplicatedCalculator

use of nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator in project yauaa by nielsbasjes.

the class TestConcatenation method testFieldConcatenationAllDefaults.

@Test
void testFieldConcatenationAllDefaults() {
    FieldCalculator fc;
    MutableUserAgent userAgent = new MutableUserAgent();
    userAgent.set("FooBarName", "Dummy", 1);
    userAgent.set("FooBarVersion", "Dummy", 1);
    userAgent.reset();
    fc = new ConcatNONDuplicatedCalculator("FooBarNameVersion", "FooBarName", "FooBarVersion");
    fc.calculate(userAgent);
    assertEquals("Unknown", userAgent.getValue("FooBarName"));
    assertEquals("??", userAgent.getValue("FooBarVersion"));
    assertEquals("Unknown ??", userAgent.getValue("FooBarNameVersion"));
    assertTrue(userAgent.get("FooBarName").isDefaultValue());
    assertTrue(userAgent.get("FooBarVersion").isDefaultValue());
    assertTrue(userAgent.get("FooBarNameVersion").isDefaultValue());
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Example 5 with ConcatNONDuplicatedCalculator

use of nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator in project yauaa by nielsbasjes.

the class TestConcatenation method testFieldConcatenationNonExistent.

@Test
void testFieldConcatenationNonExistent() {
    FieldCalculator fc;
    MutableUserAgent userAgent = createUserAgent();
    fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "NonExistent");
    fc.calculate(userAgent);
    assertEquals("One Unknown", userAgent.getValue("Combined2"));
    fc = new ConcatNONDuplicatedCalculator("Combined3", "NonExistent", "Two");
    fc.calculate(userAgent);
    assertEquals("Unknown Two", userAgent.getValue("Combined3"));
    fc = new ConcatNONDuplicatedCalculator("Combined4", "NonExistent1", "NonExistent2");
    fc.calculate(userAgent);
    assertEquals("Unknown", userAgent.getValue("Combined4"));
}
Also used : MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent) FieldCalculator(nl.basjes.parse.useragent.calculate.FieldCalculator) ConcatNONDuplicatedCalculator(nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator) Test(org.junit.jupiter.api.Test)

Aggregations

MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)6 ConcatNONDuplicatedCalculator (nl.basjes.parse.useragent.calculate.ConcatNONDuplicatedCalculator)6 Test (org.junit.jupiter.api.Test)6 FieldCalculator (nl.basjes.parse.useragent.calculate.FieldCalculator)5 CalculateAgentName (nl.basjes.parse.useragent.calculate.CalculateAgentName)1 CalculateDeviceBrand (nl.basjes.parse.useragent.calculate.CalculateDeviceBrand)1 MajorVersionCalculator (nl.basjes.parse.useragent.calculate.MajorVersionCalculator)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1