diff --git a/src/main/java/io/github/mivek/model/WeatherCondition.java b/src/main/java/io/github/mivek/model/WeatherCondition.java index 355d5083..2e2c8e62 100644 --- a/src/main/java/io/github/mivek/model/WeatherCondition.java +++ b/src/main/java/io/github/mivek/model/WeatherCondition.java @@ -15,11 +15,17 @@ * @author mivek */ public class WeatherCondition { - /** Intensity of the condition (optional). */ + /** + * Intensity of the condition (optional). + */ private Intensity intensity; - /** Descriptive of the condition (optional). */ + /** + * Descriptive of the condition (optional). + */ private Descriptive descriptive; - /** List of phenomenons of the condition. */ + /** + * List of phenomenons of the condition. + */ private List phenomenons; /** @@ -89,10 +95,11 @@ public void addPhenomenon(final Phenomenon pPhenomenon) { * @return true if there is at least phenomenon. */ public boolean isValid() { - return !phenomenons.isEmpty() || (intensity != null && descriptive != null); + return !phenomenons.isEmpty() || Descriptive.THUNDERSTORM == descriptive; } - @Override public final String toString() { + @Override + public final String toString() { return new ToStringBuilder(this). append(Messages.getInstance().getString("ToString.intensity"), intensity). append(Messages.getInstance().getString("ToString.descriptive"), descriptive). diff --git a/src/test/java/io/github/mivek/parser/AbstractParserTest.java b/src/test/java/io/github/mivek/parser/AbstractParserTest.java index 677a285b..5f6c69ba 100644 --- a/src/test/java/io/github/mivek/parser/AbstractParserTest.java +++ b/src/test/java/io/github/mivek/parser/AbstractParserTest.java @@ -17,12 +17,14 @@ /** * Test class for {@link AbstractParser} + * * @author mivek */ @Ignore public abstract class AbstractParserTest { @Rule public ExpectedException thrown = ExpectedException.none(); + /* * =================== WEATHER CONDITION =================== */ @@ -51,16 +53,17 @@ public void testParseWCMultiplePHE() { assertThat(wc.getPhenomenons(), hasItems(Phenomenon.RAIN, Phenomenon.HAIL)); } - @Test public void testParseWCNotNull() { + @Test + public void testParseWCNull() { String wcPart = "-SH"; WeatherCondition wc = getSut().parseWeatherCondition(wcPart); - assertNotNull(wc); + assertNull(wc); } @Test - public void testParseWCNull() { + public void testParseWCDescriptiveIsNotNullButPhenomenonCanBeEmptyAndIntensityCanBeNull() { String wcPart = "SH"; WeatherCondition wc = getSut().parseWeatherCondition(wcPart); @@ -72,7 +75,7 @@ public void testParseWCNull() { public void testTokenize() { // GIVEN a string with 1 1/2SM String code = "METAR KTTN 051853Z 04011KT 1 1/2SM VCTS SN FZFG BKN003 OVC010 M02/M02 A3006 RMK AO2 TSB40 SLP176 P0002 T10171017="; - String[] tokens = { "METAR", "KTTN", "051853Z", "04011KT", "1 1/2SM", "VCTS", "SN", "FZFG", "BKN003", "OVC010", "M02/M02", "A3006", "RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017" }; + String[] tokens = {"METAR", "KTTN", "051853Z", "04011KT", "1 1/2SM", "VCTS", "SN", "FZFG", "BKN003", "OVC010", "M02/M02", "A3006", "RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017"}; // WHEN tokenizing the string String[] result = getSut().tokenize(code); // THEN the visibility part is 1 1/2SM diff --git a/src/test/java/io/github/mivek/parser/MetarParserTest.java b/src/test/java/io/github/mivek/parser/MetarParserTest.java index eccbfb5d..dbf2419d 100644 --- a/src/test/java/io/github/mivek/parser/MetarParserTest.java +++ b/src/test/java/io/github/mivek/parser/MetarParserTest.java @@ -362,4 +362,14 @@ public void alternativeWindForm() { assertEquals(300, m.getWind().getExtreme2()); } + @Test + public void desriptiveFieldIsPreservedAlsoWithoutWeatherConditions() { + //example form field + String code = "AGGH 140340Z 05010KT 9999 TS FEW020 SCT021CB BKN300 32/26 Q1010"; + Metar m = fSut.parse(code); + assertNotNull(m); + assertEquals(1, m.getWeatherConditions().size()); + assertEquals(Descriptive.THUNDERSTORM, m.getWeatherConditions().get(0).getDescriptive()); + } + }