Skip to content

Commit

Permalink
Added country to invalid city ID search.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jul 29, 2019
1 parent 351f117 commit 34c7add
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/thauvin/erik/mobibot/modules/Weather2.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ static List<Message> getWeather(final String query, final String apiKey) throws
}
}

if (cwd.getCityId() != null) {
if (cwd.hasCityId() && cwd.getCityId() != null) {
if (cwd.getCityId() > 0) {
messages.add(new NoticeMessage("https://openweathermap.org/city/" + cwd.getCityId(),
Colors.GREEN));
} else {
final HttpUrl url =
HttpUrl.parse("https://openweathermap.org/find").newBuilder().addQueryParameter(
"q", city).build();
"q", city + ',' + country).build();
messages.add(
new NoticeMessage(url.toString(), Colors.GREEN));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Weather2Test extends LocalProperties {
public void testWeather() throws ModuleException {
List<Message> messages = Weather2.getWeather("98204", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
assertThat(messages.get(0).getMessage()).as("is Everett").contains("Everett");
assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Search").endsWith("98204");
assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Search").endsWith("98204%2CUS");

messages = Weather2.getWeather("London, UK", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
assertThat(messages.get(0).getMessage()).as("is UK").contains("UK");
Expand Down

0 comments on commit 34c7add

Please sign in to comment.