Search in sources :

Example 16 with Sentence

use of net.sf.marineapi.nmea.sentence.Sentence in project marine-api by ktuukkan.

the class AbstractSentenceListenerTest method testUnexpectedSentenceRead.

@Test
public void testUnexpectedSentenceRead() {
    Sentence gga = factory.createParser(GGATest.EXAMPLE);
    SentenceEvent evt = new SentenceEvent(this, gga);
    listener.sentenceRead(evt);
    assertNull(result);
}
Also used : BODSentence(net.sf.marineapi.nmea.sentence.BODSentence) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGATest(net.sf.marineapi.nmea.parser.GGATest) Test(org.junit.Test) BODTest(net.sf.marineapi.nmea.parser.BODTest)

Example 17 with Sentence

use of net.sf.marineapi.nmea.sentence.Sentence in project marine-api by ktuukkan.

the class SentenceFactory method createParserImpl.

/**
	 * Creates a new parser instance with specified parameters.
	 *
	 * @param sid Sentence/parser type ID, e.g. "GGA" or "GLL"
	 * @param param Object to pass as parameter to parser constructor
	 * @return Sentence parser
	 */
private Sentence createParserImpl(String sid, Object param) {
    if (!hasParser(sid)) {
        String msg = String.format("Parser for type '%s' not found", sid);
        throw new IllegalArgumentException(msg);
    }
    Sentence parser = null;
    Class<?> klass = param.getClass();
    try {
        Class<? extends SentenceParser> c = parsers.get(sid);
        Constructor<? extends SentenceParser> co = c.getConstructor(klass);
        parser = co.newInstance(param);
    } catch (NoSuchMethodException e) {
        String name = klass.getName();
        String msg = "Constructor with %s parameter not found";
        throw new IllegalStateException(String.format(msg, name), e);
    } catch (InstantiationException e) {
        throw new IllegalStateException("Unable to instantiate parser", e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Unable to access parser", e);
    } catch (InvocationTargetException e) {
        throw new IllegalStateException("Unable to invoke parser constructor", e);
    }
    return parser;
}
Also used : Sentence(net.sf.marineapi.nmea.sentence.Sentence) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with Sentence

use of net.sf.marineapi.nmea.sentence.Sentence in project marine-api by ktuukkan.

the class SentenceReaderTest method testFireSentenceEventWithUnexpectedType.

@Test
public void testFireSentenceEventWithUnexpectedType() {
    assertNull(sentence);
    SentenceFactory sf = SentenceFactory.getInstance();
    Sentence s = sf.createParser(BODTest.EXAMPLE);
    reader.fireSentenceEvent(s);
    assertNull(sentence);
}
Also used : SentenceFactory(net.sf.marineapi.nmea.parser.SentenceFactory) Sentence(net.sf.marineapi.nmea.sentence.Sentence) GGATest(net.sf.marineapi.nmea.parser.GGATest) Test(org.junit.Test) BODTest(net.sf.marineapi.nmea.parser.BODTest)

Example 19 with Sentence

use of net.sf.marineapi.nmea.sentence.Sentence in project marine-api by ktuukkan.

the class HeadingProviderTest method testHDGSentenceRead.

/**
	 * Test method for
	 * {@link net.sf.marineapi.provider.AbstractProvider#sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent)}
	 * .
	 */
@Test
public void testHDGSentenceRead() {
    Sentence s = factory.createParser(HDGTest.EXAMPLE);
    assertNull(event);
    instance.sentenceRead(new SentenceEvent(this, s));
    assertNotNull(event);
    assertEquals(123.4, event.getHeading(), 0.1);
    assertFalse(event.isTrue());
}
Also used : SentenceEvent(net.sf.marineapi.nmea.event.SentenceEvent) Sentence(net.sf.marineapi.nmea.sentence.Sentence) HDMTest(net.sf.marineapi.nmea.parser.HDMTest) Test(org.junit.Test) HDTTest(net.sf.marineapi.nmea.parser.HDTTest) HDGTest(net.sf.marineapi.nmea.parser.HDGTest)

Example 20 with Sentence

use of net.sf.marineapi.nmea.sentence.Sentence in project marine-api by ktuukkan.

the class SentenceFactoryTest method testCreateEmptyParserWithSentenceId.

/**
	 * Test method for
	 * {@link net.sf.marineapi.nmea.parser.SentenceFactory#createParser(TalkerId, SentenceId)
	 * .
	 */
@Test
public void testCreateEmptyParserWithSentenceId() {
    for (SentenceId id : SentenceId.values()) {
        Sentence s = instance.createParser(TalkerId.II, id);
        assertNotNull(s);
        assertTrue(s instanceof Sentence);
        assertTrue(s instanceof SentenceParser);
        assertEquals(TalkerId.II, s.getTalkerId());
        assertEquals(id.name(), s.getSentenceId());
    }
}
Also used : SentenceId(net.sf.marineapi.nmea.sentence.SentenceId) 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)

Aggregations

Sentence (net.sf.marineapi.nmea.sentence.Sentence)27 Test (org.junit.Test)20 FOOSentence (net.sf.marineapi.test.util.FOOSentence)10 BODSentence (net.sf.marineapi.nmea.sentence.BODSentence)8 GGATest (net.sf.marineapi.nmea.parser.GGATest)7 SentenceEvent (net.sf.marineapi.nmea.event.SentenceEvent)6 SentenceFactory (net.sf.marineapi.nmea.parser.SentenceFactory)6 BODTest (net.sf.marineapi.nmea.parser.BODTest)4 GLLTest (net.sf.marineapi.nmea.parser.GLLTest)3 HDGTest (net.sf.marineapi.nmea.parser.HDGTest)3 HDMTest (net.sf.marineapi.nmea.parser.HDMTest)3 HDTTest (net.sf.marineapi.nmea.parser.HDTTest)3 RMCTest (net.sf.marineapi.nmea.parser.RMCTest)3 FOOParser (net.sf.marineapi.test.util.FOOParser)3 GGASentence (net.sf.marineapi.nmea.sentence.GGASentence)2 GLLSentence (net.sf.marineapi.nmea.sentence.GLLSentence)2 GSASentence (net.sf.marineapi.nmea.sentence.GSASentence)2 GSVSentence (net.sf.marineapi.nmea.sentence.GSVSentence)2 RMCSentence (net.sf.marineapi.nmea.sentence.RMCSentence)2 SentenceId (net.sf.marineapi.nmea.sentence.SentenceId)2