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);
}
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;
}
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);
}
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());
}
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());
}
}
Aggregations