Search in sources :

Example 1 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testWrongTypeParameters2.

// ----------------------------------------------------------------
@Test
void testWrongTypeParameters2() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("DeviceClass")
        public void wrongSetter(TestRecord testRecord, Double value) {
            fail("May NEVER call this method");
        }
    }.enrich(record));
    assertTrue(exception.getMessage().contains("the method [wrongSetter] " + "has been annotated with YauaaField but it has the wrong method signature. It must look like " + "[ public void wrongSetter(TestRecord record, String value) ]"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testTooManyParameters.

// ----------------------------------------------------------------
@Test
void testTooManyParameters() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("DeviceClass")
        public void wrongSetter(TestRecord testRecord, String value, String extra) {
            fail("May NEVER call this method");
        }
    }.enrich(record));
    assertTrue(exception.getMessage().contains("the method [wrongSetter] " + "has been annotated with YauaaField but it has the wrong method signature. It must look like " + "[ public void wrongSetter(TestRecord record, String value) ]"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 3 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testInaccessibleSetter.

// ----------------------------------------------------------------
@Test
void testInaccessibleSetter() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("DeviceClass")
        private void inaccessibleSetter(TestRecord testRecord, String value) {
            fail("May NEVER call this method");
        }
    }.enrich(record));
    assertEquals("Method annotated with YauaaField is not public: inaccessibleSetter", exception.getMessage());
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 4 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testWrongReturnType.

// ----------------------------------------------------------------
@Test
void testWrongReturnType() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings({ "unused", "SameReturnValue" })
        @YauaaField("DeviceClass")
        public boolean wrongSetter(TestRecord testRecord, Double value) {
            fail("May NEVER call this method");
            return false;
        }
    }.enrich(record));
    assertTrue(exception.getMessage().contains("the method [wrongSetter] " + "has been annotated with YauaaField but it has the wrong method signature. It must look like " + "[ public void wrongSetter(TestRecord record, String value) ]"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Example 5 with InvalidParserConfigurationException

use of nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException in project yauaa by nielsbasjes.

the class TestAnnotationSystemAnonymous method testWrongTypeParameters1.

// ----------------------------------------------------------------
@Test
void testWrongTypeParameters1() {
    InvalidParserConfigurationException exception = assertThrows(InvalidParserConfigurationException.class, () -> record = new MyErrorMapper() {

        // Called via the annotation
        @SuppressWarnings("unused")
        @YauaaField("DeviceClass")
        public void wrongSetter(String string, String value) {
            fail("May NEVER call this method");
        }
    }.enrich(record));
    assertTrue(exception.getMessage().contains("the method [wrongSetter] " + "has been annotated with YauaaField but it has the wrong method signature. It must look like " + "[ public void wrongSetter(TestRecord record, String value) ]"));
}
Also used : InvalidParserConfigurationException(nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidParserConfigurationException (nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException)35 Test (org.junit.jupiter.api.Test)24 YamlUtils.getKeyAsString (nl.basjes.parse.useragent.utils.YamlUtils.getKeyAsString)5 YamlUtils.getValueAsString (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsString)5 YamlUtils.getExactlyOneNodeTuple (nl.basjes.parse.useragent.utils.YamlUtils.getExactlyOneNodeTuple)4 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Matcher (nl.basjes.parse.useragent.analyze.Matcher)2 ConfigLine (nl.basjes.parse.useragent.config.MatcherConfig.ConfigLine)2 YamlUtils.getValueAsMappingNode (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsMappingNode)2 YamlUtils.getValueAsSequenceNode (nl.basjes.parse.useragent.utils.YamlUtils.getValueAsSequenceNode)2 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 Node (org.yaml.snakeyaml.nodes.Node)2 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)2