diff --git a/.gitignore b/.gitignore
index efdbd2c..7dd1be9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ target
.settings
.project
.DS_Store
+.gradle
+build
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..7c89540
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,42 @@
+apply plugin: 'java'
+apply plugin: "jacoco"
+
+version = '1.0.0'
+
+description = """Weather"""
+
+sourceCompatibility = 1.7
+targetCompatibility = 1.7
+
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile fileTree(dir: 'lib', include: ['weather.jar', 'ApeForecasts.jar'])
+ testCompile group: 'junit', name: 'junit', version:'4.12'
+ testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
+ testCompile "org.mockito:mockito-core:2.+"
+}
+
+jacoco {
+ toolVersion = "0.7.6.201602180812"
+}
+jacocoTestReport {
+ reports {
+ xml.enabled false
+ csv.enabled false
+ html.destination "${buildDir}/jacocoHtml"
+ }
+}
+test {
+ jacoco {
+ append = false
+ destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
+ classDumpFile = file("$buildDir/jacoco/classpathdumps")
+ }
+}
\ No newline at end of file
diff --git a/build.sh b/build.sh
index 685e25f..6e92097 100755
--- a/build.sh
+++ b/build.sh
@@ -1,2 +1,5 @@
-mvn install:install-file -Dfile=lib/weather.jar -DgroupId=com.weather -DartifactId=weather -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
-mvn clean test cobertura:cobertura cobertura:check
+#!/usr/bin/env bash
+set -e
+./gradlew clean test jacocoTestReport
+open build/jacocoHtml/index.html
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..51288f9
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..2048ff7
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Jan 02 16:32:48 GMT 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..4453cce
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save ( ) {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..f955316
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 66b8b92..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
- 4.0.0
- com.develogical
- Weather
- 1.0.0
- jar
- Weather
- System Integration Exercise
-
-
- 1.7
- UTF-8
-
-
-
-
- junit
- junit
- 4.12
- test
-
-
- org.jmock
- jmock-junit4
- 2.8.1
- test
-
-
- org.hamcrest
- hamcrest-all
- 1.3
- test
-
-
-
- com.weather
- weather
- 1.0
-
-
-
-
- ${project.artifactId}
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.1
-
- ${java.version}
- ${java.version}
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
-
-
- 80
- 80
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..17f9445
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'Weather'
diff --git a/src/main/java/com/develogical/APEForecaster.java b/src/main/java/com/develogical/APEForecaster.java
new file mode 100644
index 0000000..daf471f
--- /dev/null
+++ b/src/main/java/com/develogical/APEForecaster.java
@@ -0,0 +1,70 @@
+package com.develogical;
+
+import com.oocode.weather.DayForecaster;
+import com.oocode.weather.Forecaster;
+import com.weather.Day;
+import com.weather.Forecast;
+import com.weather.Region;
+
+public class APEForecaster implements Forecasters {
+
+ protected double getTemperature(Forecaster.Regions baseRegion, int day) {
+ return this.getForecaster().forecast(baseRegion, day);
+ }
+
+ private DayForecaster getForecaster() {
+ return new DayForecaster();
+ }
+
+
+ private Forecaster.Regions mapAPERegions(Region baseRegion) {
+ /*
+ NE_SCOTLAND,
+ NW_SCOTLAND,
+ SE_SCOTLAND,
+ SW_SCOTLAND,
+ MID_SCOTLAND,
+ NE_ENGLAND,
+ NW_ENGLAND,
+ MID_ENGLAND,
+ S_WALES;
+
+
+ BIRMINGHAM,
+ EDINBURGH,
+ GLASGOW,
+ LONDON,
+ MANCHESTER,
+ NORTH_ENGLAND,
+ SOUTH_EAST_ENGLAND,
+ WALES;
+ */
+
+ switch (baseRegion.toString()) {
+ case "SOUTH_WEST_ENGLAND":
+ return Forecaster.Regions.SW_ENGLAND;
+ case "SOUTH_EAST_ENGLAND":
+ return Forecaster.Regions.SE_ENGLAND;
+ default:
+ return Forecaster.Regions.N_WALES;
+ }
+ }
+
+ private int mapAPEDays(Day day) {
+ switch (day.toString()) {
+ case "MONDAY":
+ return 0;
+ case "TUESDAY":
+ return 1;
+ default:
+ return 6;
+ }
+ }
+
+ @Override
+ public Forecast forecastFor(Region r, Day d) {
+ double temp = this.getForecaster().forecast(mapAPERegions(r), mapAPEDays(d));
+ String summary = this.getForecaster().forecastSummary(mapAPERegions(r), mapAPEDays(d));
+ return new Forecast(summary, (int)temp);
+ }
+}
diff --git a/src/main/java/com/develogical/AvgForecaster.java b/src/main/java/com/develogical/AvgForecaster.java
new file mode 100644
index 0000000..11b2ffd
--- /dev/null
+++ b/src/main/java/com/develogical/AvgForecaster.java
@@ -0,0 +1,49 @@
+package com.develogical;
+
+import com.weather.Day;
+import com.weather.Forecast;
+import com.weather.Region;
+
+import java.util.ArrayList;
+
+public class AvgForecaster implements Forecasters{
+ private ArrayList forecastersArray;
+
+ public AvgForecaster(ArrayList forecastersArray) {
+ this.forecastersArray = forecastersArray;
+
+
+ }
+
+ @Override
+ public Forecast forecastFor(Region r, Day d) {
+ ArrayList forecasts = new ArrayList<>();
+
+ double forecastAvg = 0;
+
+ for(Forecasters f : this.forecastersArray)
+ {
+ Forecast instanceForecast = f.forecastFor(r, d);
+
+ forecastAvg += instanceForecast.temperature();
+
+ forecasts.add(instanceForecast);
+ }
+
+ forecastAvg = forecastAvg / forecasts.size();
+
+ double bestForecastDelta = 0;
+ String bestSummary = null;
+
+ for(Forecast f1 : forecasts){
+ double delta = Math.abs((f1.temperature() - forecastAvg));
+ if(bestSummary == null || delta < bestForecastDelta)
+ {
+ bestSummary = f1.summary();
+ bestForecastDelta = delta;
+ }
+ }
+
+ return new Forecast(bestSummary, (int)Math.round(forecastAvg));
+ }
+}
diff --git a/src/main/java/com/develogical/CachedForecast.java b/src/main/java/com/develogical/CachedForecast.java
new file mode 100644
index 0000000..5f4c907
--- /dev/null
+++ b/src/main/java/com/develogical/CachedForecast.java
@@ -0,0 +1,61 @@
+package com.develogical;
+
+import com.weather.Day;
+import com.weather.Forecast;
+import com.weather.Region;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Created by ape09 on 12/07/2017.
+ */
+public class CachedForecast implements Forecasters
+{
+ private Forecasters forecaster;
+ private LinkedHashMap cache;
+ private final int MAX_CAPACITY = 10;
+
+ public CachedForecast(Forecasters f)
+ {
+ this.forecaster = f;
+ this.cache = new LinkedHashMap(MAX_CAPACITY + 1)
+ {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return size() > MAX_CAPACITY;
+ }
+ };
+ }
+
+ public Forecast forecastFor(Region city, Day day)
+ {
+ //If k is not in cache, then fetch and store
+ String k = city.toString() + day.toString();
+ if(!this.cache.containsKey(k))
+ {
+ System.out.println("Key->'" + k + "', is not in cache, retrieving!");
+ //Value is not in cache, fetch and store
+ this.cache.put(k, getFromForecaster(this.forecaster, city, day));
+ }
+ else
+ {
+ System.out.println("Key->'" + k + "', is in cache!");
+ }
+ return (Forecast) this.cache.get(k);
+ }
+
+ protected Forecast getFromForecaster(Forecasters forecaster, Region city, Day day)
+ {
+ return forecaster.forecastFor(city,day);
+ }
+
+ public static void main(String[] args) {
+ CachedForecast cf = new CachedForecast(new ForecasterAdapter());
+
+ cf.forecastFor(Region.LONDON, Day.MONDAY);
+ cf.forecastFor(Region.LONDON, Day.MONDAY);
+ cf.forecastFor(Region.LONDON, Day.MONDAY);
+ cf.forecastFor(Region.LONDON, Day.MONDAY);
+ }
+}
+
diff --git a/src/main/java/com/develogical/Example.java b/src/main/java/com/develogical/Example.java
index d141f78..326b7bf 100644
--- a/src/main/java/com/develogical/Example.java
+++ b/src/main/java/com/develogical/Example.java
@@ -1,17 +1,15 @@
package com.develogical;
+import com.oocode.weather.DayForecaster;
import com.weather.Day;
import com.weather.Forecast;
import com.weather.Forecaster;
import com.weather.Region;
public class Example {
-
public static void main(String[] args) {
-
// This is just an example of using the 3rd party API - delete this class before submission.
-
- Forecaster forecaster = new Forecaster();
+ /*Forecaster forecaster = new Forecaster();
Forecast londonForecast = forecaster.forecastFor(Region.LONDON, Day.MONDAY);
@@ -22,5 +20,24 @@ public static void main(String[] args) {
System.out.println("Edinburgh outlook: " + edinburghForecast.summary());
System.out.println("Edinburgh temperature: " + edinburghForecast.temperature());
+*/
+ lib2();
}
+
+ private static void lib2() {
+ Double londonForecastTemp = DayForecaster.forecast(com.oocode.weather.Forecaster.Regions.SE_ENGLAND, 0);
+ String londonForecastSummary = DayForecaster.forecastSummary(com.oocode.weather.Forecaster.Regions.SE_ENGLAND, 0);
+
+ System.out.println("London outlook: " + londonForecastSummary);
+ System.out.println("London temperature: " + londonForecastTemp);
+
+ Double edinburghForecastTemp = DayForecaster.forecast(com.oocode.weather.Forecaster.Regions.SE_SCOTLAND, 0);
+ String edinburghForecastSummary = DayForecaster.forecastSummary(com.oocode.weather.Forecaster.Regions.SE_SCOTLAND, 0);
+
+ System.out.println("Edinburgh outlook: " + edinburghForecastSummary);
+ System.out.println("Edinburgh temperature: " + edinburghForecastTemp);
+ }
+
}
+
+
diff --git a/src/main/java/com/develogical/ForecasterAdapter.java b/src/main/java/com/develogical/ForecasterAdapter.java
new file mode 100644
index 0000000..634307d
--- /dev/null
+++ b/src/main/java/com/develogical/ForecasterAdapter.java
@@ -0,0 +1,17 @@
+package com.develogical;
+
+import com.weather.Day;
+import com.weather.Forecast;
+import com.weather.Region;
+import com.weather.Forecaster;
+
+/**
+ * Created by ape09 on 12/07/2017.
+ */
+public class ForecasterAdapter implements Forecasters{
+
+ @Override
+ public Forecast forecastFor(Region r, Day d) {
+ return new Forecaster().forecastFor(r, d);
+ }
+}
diff --git a/src/main/java/com/develogical/README.txt b/src/main/java/com/develogical/README.txt
deleted file mode 100644
index 35de064..0000000
--- a/src/main/java/com/develogical/README.txt
+++ /dev/null
@@ -1 +0,0 @@
-Put your implementation code in this directory.
diff --git a/src/test/java/com/develogical/PutYourTestCodeInThisDirectoryTest.java b/src/test/java/com/develogical/PutYourTestCodeInThisDirectoryTest.java
new file mode 100644
index 0000000..1035f7d
--- /dev/null
+++ b/src/test/java/com/develogical/PutYourTestCodeInThisDirectoryTest.java
@@ -0,0 +1,13 @@
+package com.develogical;
+
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+public class PutYourTestCodeInThisDirectoryTest {
+ @Test
+ public void placeholder() throws Exception {
+ assertThat(2, equalTo(2));
+ }
+}
diff --git a/src/test/java/com/develogical/README.txt b/src/test/java/com/develogical/README.txt
deleted file mode 100644
index 0870ceb..0000000
--- a/src/test/java/com/develogical/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Put your test code in this directory.
-
diff --git a/src/test/java/com/develogical/WeatherTests.java b/src/test/java/com/develogical/WeatherTests.java
new file mode 100644
index 0000000..565c612
--- /dev/null
+++ b/src/test/java/com/develogical/WeatherTests.java
@@ -0,0 +1,107 @@
+package com.develogical;
+
+import com.oocode.weather.DayForecaster;
+import com.oocode.weather.Forecaster;
+import com.weather.Day;
+import com.weather.Forecast;
+import com.weather.Region;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.junit.Assert.assertEquals;
+
+public class WeatherTests {
+
+ @Test
+ public void checkCFAdapter(){
+ Forecasters f = mock(Forecasters.class);
+ when(f.forecastFor(Region.LONDON, Day.MONDAY)).thenReturn(new Forecast("Sunny'ish", 500));
+ CachedForecast cf = new CachedForecast(f);
+
+ Forecast londonForecast = cf.getFromForecaster(f, Region.LONDON, Day.MONDAY);
+
+ assertEquals(londonForecast.summary(), "Sunny'ish");
+ assertEquals(londonForecast.temperature(), 500);
+ }
+
+ @Test
+ public void checkCFAPI(){
+
+ CachedForecast cf = new CachedForecast(mock(Forecasters.class))
+ {
+ protected Forecast getFromForecaster(Forecasters forecaster, Region city, Day day)
+ {
+ return new Forecast("Rainny", 501);
+ }
+ };
+
+ Forecast londonForecast = cf.forecastFor(Region.LONDON, Day.MONDAY);
+
+ assertEquals(londonForecast.summary(), "Rainny");
+ assertEquals(londonForecast.temperature(), 501);
+ }
+
+
+ @Test
+ public void checkAPEAPI(){
+ APEForecaster apeForecaster = new APEForecaster();
+
+
+ }
+
+ /*
+ @Test
+ public void checkAPETemperatures(){
+ APEForecaster apeForecaster = new APEForecaster()
+ {
+ private DayForecaster getForecaster()
+ {
+ DayForecaster df = mock(DayForecaster.class);
+ when(df.forecast(com.oocode.weather.Forecaster.Regions.SE_ENGLAND, 0)).thenReturn(20.0);
+ return df;
+ }
+ };
+
+ assertEquals(apeForecaster.getTemperature(com.oocode.weather.Forecaster.Regions.SE_ENGLAND, 0), 20.0, 0.1);
+ }*/
+
+
+ @Test
+ public void checkAveragingAPI()
+ {
+ AvgForecaster avgF = new AvgForecaster(new ArrayList());
+ }
+
+
+ @Test
+ public void assertAverages()
+ {
+ ArrayList forecasters = new ArrayList<>();
+
+ APEForecaster apeForecaster = mock(APEForecaster.class);
+ when(apeForecaster.forecastFor(Region.SOUTH_EAST_ENGLAND, Day.SATURDAY)).thenReturn(new Forecast("Sunny", 32));
+
+ CachedForecast cachedForecast = mock(CachedForecast.class);
+ when(cachedForecast.forecastFor(Region.SOUTH_EAST_ENGLAND, Day.SATURDAY)).thenReturn(new Forecast("Rain", 20));
+
+ ForecasterAdapter simpleForecast = mock(ForecasterAdapter.class);
+ when(simpleForecast.forecastFor(Region.SOUTH_EAST_ENGLAND, Day.SATURDAY)).thenReturn(new Forecast("Indecisive", 34));
+
+ forecasters.add(apeForecaster);
+ forecasters.add(cachedForecast);
+ forecasters.add(simpleForecast);
+
+ AvgForecaster avgF = new AvgForecaster(forecasters);
+
+ Forecast result = avgF.forecastFor(Region.SOUTH_EAST_ENGLAND, Day.SATURDAY);
+
+ assertEquals(result.temperature(), 29);
+ assertEquals(result.summary(), "Sunny");
+
+
+ }
+
+}