Search in sources :

Example 1 with FOOSentence

use of net.sf.marineapi.test.util.FOOSentence in project marine-api by ktuukkan.

the class SentenceFactoryTest method testCreateCustomParser.

/**
	 * Test method for
	 * {@link net.sf.marineapi.nmea.parser.SentenceFactory#createParser(java.lang.String)}
	 * .
	 */
@Test
public void testCreateCustomParser() {
    try {
        instance.registerParser("FOO", FOOParser.class);
        assertTrue(instance.hasParser("FOO"));
    } catch (Exception e) {
        fail("parser registering failed");
    }
    Sentence s = null;
    try {
        s = instance.createParser("$IIFOO,aa,bb,cc");
    } catch (Exception e) {
        fail("sentence parsing failed");
    }
    assertNotNull(s);
    assertTrue(s instanceof Sentence);
    assertTrue(s instanceof SentenceParser);
    assertTrue(s instanceof FOOParser);
    assertEquals(TalkerId.II, s.getTalkerId());
    assertEquals("FOO", s.getSentenceId());
    assertEquals("aa", ((FOOSentence) s).getValueA());
    assertEquals("bb", ((FOOSentence) s).getValueB());
    assertEquals("cc", ((FOOSentence) s).getValueC());
}
Also used : FOOParser(net.sf.marineapi.test.util.FOOParser) FOOSentence(net.sf.marineapi.test.util.FOOSentence) BODSentence(net.sf.marineapi.nmea.sentence.BODSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence) Test(org.junit.Test)

Example 2 with FOOSentence

use of net.sf.marineapi.test.util.FOOSentence in project marine-api by ktuukkan.

the class SentenceParserTest method testConstructorWithCustomParser.

/**
	 * Test method for SentenceParser constructors called from derived custom
	 * parsers.
	 */
@Test
public void testConstructorWithCustomParser() {
    final String foo = "FOO";
    SentenceFactory sf = SentenceFactory.getInstance();
    sf.registerParser(foo, FOOParser.class);
    final String fooSentence = "$GPFOO,B,A,R";
    final FOOSentence fp = new FOOParser(fooSentence);
    final Sentence s = sf.createParser(fooSentence);
    assertTrue(s instanceof SentenceParser);
    assertTrue(s instanceof FOOParser);
    assertEquals(foo, s.getSentenceId());
    assertEquals(TalkerId.GP, s.getTalkerId());
    assertEquals(s, fp);
}
Also used : FOOSentence(net.sf.marineapi.test.util.FOOSentence) FOOParser(net.sf.marineapi.test.util.FOOParser) FOOSentence(net.sf.marineapi.test.util.FOOSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence) Test(org.junit.Test)

Aggregations

Sentence (net.sf.marineapi.nmea.sentence.Sentence)2 FOOParser (net.sf.marineapi.test.util.FOOParser)2 FOOSentence (net.sf.marineapi.test.util.FOOSentence)2 Test (org.junit.Test)2 BODSentence (net.sf.marineapi.nmea.sentence.BODSentence)1