Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public final class MinimalVisibilityCommand implements Command {
/** Pattern for the minimum visibility. */
public static final Pattern MIN_VISIBILITY_REGEX = Pattern.compile("^(\\d{4}[NnEeSsWw]{1,2})$");
public static final Pattern MIN_VISIBILITY_REGEX = Pattern.compile("^(\\d{4})(N|NE|E|SE|S|SW|W|NW)$");

/**
* Protected constructor.
Expand All @@ -20,14 +20,14 @@ public final class MinimalVisibilityCommand implements Command {

@Override
public boolean execute(final AbstractWeatherContainer container, final String part) {
String[] matches = Regex.pregMatch(MIN_VISIBILITY_REGEX, part);
container.getVisibility().setMinVisibility(Integer.parseInt(matches[1].substring(0, 4)));
container.getVisibility().setMinDirection(matches[1].substring(4));
String[] matches = Regex.pregMatch(MIN_VISIBILITY_REGEX, part.toUpperCase());
container.getVisibility().setMinVisibility(Integer.parseInt(matches[1]));
container.getVisibility().setMinDirection(matches[2]);
return getReturnValue();
}

@Override
public boolean canParse(final String input) {
return Regex.find(MIN_VISIBILITY_REGEX, input);
return Regex.find(MIN_VISIBILITY_REGEX, input.toUpperCase());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.mivek.command.common;

import io.github.mivek.model.Metar;
import io.github.mivek.model.Visibility;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MinimalVisibilityCommandTest {

@ParameterizedTest
@ValueSource(strings = {"NW", "N","NE","E","SE","S","SW","W"})
void execute(final String direction) {
MinimalVisibilityCommand command = new MinimalVisibilityCommand();
String input = "0600" + direction;
Metar metar = new Metar();
metar.setVisibility(new Visibility());
command.execute(metar, input);
assertEquals(600, metar.getVisibility().getMinVisibility());
assertEquals(direction, metar.getVisibility().getMinDirection());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void testParseWithMinVisibility() throws ParseException {
Visibility v = m.getVisibility();
assertEquals("5000m", v.getMainVisibility());
assertEquals(1100, v.getMinVisibility());
assertEquals("w", v.getMinDirection());
assertEquals("W", v.getMinDirection());
String des = m.toString();

assertThat(des, containsString(Messages.getInstance().getString("ToString.day.month") + "=16"));
Expand Down
Loading