Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
179 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/net/birelian/forecast/config/GuiceConfigurationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.birelian.forecast.config; | ||
|
||
import com.google.inject.AbstractModule; | ||
import net.birelian.forecast.service.CityService; | ||
import net.birelian.forecast.service.HttpService; | ||
import net.birelian.forecast.service.WeatherService; | ||
import net.birelian.forecast.service.impl.CityServiceImpl; | ||
import net.birelian.forecast.service.impl.HttpServiceImpl; | ||
import net.birelian.forecast.service.impl.WeatherServiceImpl; | ||
|
||
/** | ||
* Guice dependency injection configuration module | ||
*/ | ||
public class GuiceConfigurationModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
|
||
// Bindings | ||
bind(HttpService.class).to(HttpServiceImpl.class); | ||
bind(CityService.class).to(CityServiceImpl.class); | ||
bind(WeatherService.class).to(WeatherServiceImpl.class); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package net.birelian.forecast; | ||
|
||
import static junit.framework.TestCase.assertTrue; | ||
import static net.birelian.forecast.service.impl.WeatherServiceImpl.MAX_FUTURE_DAYS; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import com.google.inject.Guice; | ||
import java.time.LocalDate; | ||
import net.birelian.forecast.config.GuiceConfigurationModule; | ||
import net.birelian.forecast.service.exception.ServiceException; | ||
import org.apache.commons.lang3.math.NumberUtils; | ||
import org.junit.Test; | ||
import org.junit.platform.commons.util.StringUtils; | ||
|
||
// https://www.metaweather.com/api/location/766273/ | ||
public class ForecastTest { | ||
|
||
private static final String CITY_NAME = "Madrid"; | ||
|
||
private static final boolean NO_WIND = false; | ||
private static final boolean WIND = true; | ||
|
||
private static final LocalDate YESTERDAY = LocalDate.now().minusDays(1); | ||
private static final LocalDate NON_VALID_FUTURE_DATE = LocalDate.now().plusDays(MAX_FUTURE_DAYS + 1); | ||
private static final LocalDate VALID_FUTURE_DATE = LocalDate.now().plusDays(MAX_FUTURE_DAYS); | ||
|
||
@Test(expected = AssertionError.class) | ||
public void findTheWeatherWithANullDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, null, NO_WIND); | ||
} | ||
|
||
@Test(expected = AssertionError.class) | ||
public void findTheWindWithANullDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, null, WIND); | ||
} | ||
|
||
@Test | ||
public void findTheWeatherOfTodayShouldWork() { | ||
|
||
String prediction = getForecastInstance().predict(CITY_NAME, NO_WIND); | ||
|
||
assertTrue("Forecast should return a String when it works. Exception otherwise", StringUtils.isNotBlank(prediction)); | ||
assertFalse("Forecast should not be a number when wind parameter is false", NumberUtils.isParsable(prediction)); | ||
} | ||
|
||
@Test | ||
public void findTheWindOfTodayShouldWork() { | ||
|
||
String prediction = getForecastInstance().predict(CITY_NAME, WIND); | ||
|
||
assertTrue("Forecast should return a String when it works. Exception otherwise", StringUtils.isNotBlank(prediction)); | ||
assertTrue("Forecast wind should be parsable as Double", NumberUtils.isParsable(prediction)); | ||
} | ||
|
||
@Test(expected = ServiceException.class) | ||
public void findTheWeatherForAPastDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, YESTERDAY, NO_WIND); | ||
} | ||
|
||
@Test(expected = ServiceException.class) | ||
public void findTheWindForAPastDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, YESTERDAY, WIND); | ||
} | ||
|
||
@Test | ||
public void findTheWeatherForAValidFutureDateShouldReturnTheWeather() { | ||
|
||
String prediction = getForecastInstance().predict(CITY_NAME, VALID_FUTURE_DATE, NO_WIND); | ||
|
||
assertTrue("Forecast should return a String when it works. Exception otherwise", StringUtils.isNotBlank(prediction)); | ||
assertFalse("Forecast should not be a number when wind parameter is false", NumberUtils.isParsable(prediction)); | ||
} | ||
|
||
@Test | ||
public void findTheWindForAValidFutureDateShouldReturnTheWeather() { | ||
|
||
String prediction = getForecastInstance().predict(CITY_NAME, VALID_FUTURE_DATE, WIND); | ||
|
||
assertTrue("Forecast should return a String when it works. Exception otherwise", StringUtils.isNotBlank(prediction)); | ||
assertTrue("Forecast wind should be parsable as Double", NumberUtils.isParsable(prediction)); | ||
} | ||
|
||
@Test(expected = ServiceException.class) | ||
public void findTheWeatherForANonValidFutureDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, NON_VALID_FUTURE_DATE, NO_WIND); | ||
} | ||
|
||
@Test(expected = ServiceException.class) | ||
public void findTheWindForANonValidFutureDateShouldThrowException() { | ||
|
||
getForecastInstance().predict(CITY_NAME, NON_VALID_FUTURE_DATE, WIND); | ||
} | ||
|
||
private Forecast getForecastInstance() { | ||
|
||
return Guice.createInjector(new GuiceConfigurationModule()).getInstance(Forecast.class); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.