mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 22:43:57 +00:00
started a fix for insufficient superclass checking in NMEA AbstractSentenceListener
Change-Id: Ic4818022cda4b2ec115076b3ed922e2528049eb7
This commit is contained in:
1 parent
28ea6be7e8
commit
732f30f14b
2 files changed
+31
-4
No files matched your search
+31
-1
@@ -1,6 +1,7 @@
|
||||
package com.sap.sailing.nmeaconnector.test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -19,6 +20,7 @@ import net.sf.marineapi.nmea.event.SentenceListener;
|
||||
import net.sf.marineapi.nmea.io.SentenceReader;
|
||||
import net.sf.marineapi.nmea.parser.DataNotAvailableException;
|
||||
import net.sf.marineapi.nmea.sentence.PositionSentence;
|
||||
import net.sf.marineapi.nmea.sentence.Sentence;
|
||||
import net.sf.marineapi.nmea.sentence.TimeSentence;
|
||||
import net.sf.marineapi.nmea.util.Position;
|
||||
import net.sf.marineapi.nmea.util.Time;
|
||||
@@ -80,4 +82,32 @@ public class GeneralizedSentenceListenerTest {
|
||||
final Iterable<Wind> wind = NmeaFactory.INSTANCE.readWind(new FileInputStream("resources/LogSS.txt"));
|
||||
assertFalse(Util.isEmpty(wind));
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyGenericSentenceListener<A, B extends Sentence> extends AbstractSentenceListener<B> {
|
||||
private B lastSentence;
|
||||
|
||||
@Override
|
||||
public void sentenceRead(B sentence) {
|
||||
lastSentence = sentence;
|
||||
}
|
||||
|
||||
public B getLastSentence() {
|
||||
return lastSentence;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyOtherGenericSentenceListener<A> extends MyGenericSentenceListener<A, TimeSentence> {}
|
||||
|
||||
private static class MyConcreteSentenceListener extends MyOtherGenericSentenceListener<String> {}
|
||||
|
||||
private static class MyConcreteSentenceListenerSubclass extends MyConcreteSentenceListener {}
|
||||
|
||||
@Test
|
||||
public void testComplicatedGenericSentenceListenerSubclass() throws InterruptedException {
|
||||
MyConcreteSentenceListenerSubclass listener = new MyConcreteSentenceListenerSubclass();
|
||||
sentenceReader.addSentenceListener(listener);
|
||||
readerSupport.startReading();
|
||||
readerSupport.waitUntilAllMessagesHaveBeenRead();
|
||||
assertNotNull(listener.getLastSentence());
|
||||
}
|
||||
}
|
||||
@@ -48,12 +48,9 @@ public abstract class AbstractSentenceListener<T extends Sentence>
|
||||
private final Type expectedType;
|
||||
|
||||
public AbstractSentenceListener() {
|
||||
|
||||
ParameterizedType superClass =
|
||||
(ParameterizedType) getClass().getGenericSuperclass();
|
||||
|
||||
Type[] superClassTypeArgs = superClass.getActualTypeArguments();
|
||||
|
||||
this.expectedType = superClassTypeArgs[0];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user