Skip to content

Commit

Permalink
Merge pull request #201 from optionfactory/bugfix/do-not-discard-desc…
Browse files Browse the repository at this point in the history
…riptive-field

Fix for issue #200 Descriptive fields enhancements
  • Loading branch information
mivek authored Apr 27, 2020
2 parents dcba9d9 + 0b7602d commit 8f64d5f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/main/java/io/github/mivek/model/WeatherCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Phenomenon> phenomenons;

/**
Expand Down Expand Up @@ -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).
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/io/github/mivek/parser/AbstractParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

/**
* Test class for {@link AbstractParser}
*
* @author mivek
*/
@Ignore
public abstract class AbstractParserTest<T extends AbstractWeatherCode> {
@Rule
public ExpectedException thrown = ExpectedException.none();

/*
* =================== WEATHER CONDITION ===================
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/github/mivek/parser/MetarParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 8f64d5f

Please sign in to comment.