Skip to content

Commit

Permalink
Add unit testing and fix negative coat response display
Browse files Browse the repository at this point in the history
  • Loading branch information
xlpnic committed Apr 18, 2018
1 parent 4548848 commit 7899949
Show file tree
Hide file tree
Showing 10 changed files with 8,162 additions and 4,073 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "coatapp.coat"
minSdkVersion 21
targetSdkVersion 25
versionCode 6
versionName "1.0"
versionCode 7
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -29,4 +29,9 @@ dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:11.0.0'
// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.json:json:20140107'
}
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":6},"path":"app-release.apk","properties":{"packageId":"coatapp.coat","split":"","minSdkVersion":"21"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":7},"path":"app-release.apk","properties":{"packageId":"coatapp.coat","split":"","minSdkVersion":"21"}}]
4 changes: 3 additions & 1 deletion app/src/main/java/coatapp/coat/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ private void setCoatResult(boolean wearCoat) {
if(wearCoat){
TextView textResult = (TextView) findViewById(R.id.textResult);
textResult.setText(R.string.affirmativeResult);
textResult.setTextSize(64);
}
else{
TextView textResult = (TextView) findViewById(R.id.textResult);
textResult.setText(R.string.negativeResult);
textResult.setTextSize(36);
}

setResultTextVisible(true);
Expand Down Expand Up @@ -180,7 +182,7 @@ private void getForecast(Location currentLocation) {
}
}

private boolean ShouldWearACoat(JSONObject weatherForecast) {
public boolean ShouldWearACoat(JSONObject weatherForecast) {

WeatherConverter.WeatherType currentWeatherType = JsonHelper.GetCurrentWeatherType(weatherForecast);
double currentTemperature = JsonHelper.GetCurrentTemperature(weatherForecast);
Expand Down
35 changes: 35 additions & 0 deletions app/src/test/java/coatapp/coat/CoatUnitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package coatapp.coat;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class CoatUnitTests {

@Test
public void coatCheck() throws JSONException {
Home h = new Home();
JSONObject ForecastHotClearDay = new JSONObject(TestData.ForecastHotClearDay);
boolean ForecastHotClearDayResult = h.ShouldWearACoat(ForecastHotClearDay);
assertEquals(false, ForecastHotClearDayResult);

JSONObject ForecastHotRain = new JSONObject(TestData.ForecastHotRain);
boolean ForecastHotRainResult = h.ShouldWearACoat(ForecastHotRain);
assertEquals(true, ForecastHotRainResult);

JSONObject ForecastColdRain = new JSONObject(TestData.ForecastColdRain);
boolean ForecastColdRainResult = h.ShouldWearACoat(ForecastColdRain);
assertEquals(true, ForecastColdRainResult);

JSONObject ForecastColdClearDay = new JSONObject(TestData.ForecastColdClearDay);
boolean ForecastColdClearDayResult = h.ShouldWearACoat(ForecastColdClearDay);
assertEquals(true, ForecastColdClearDayResult);
}
}
17 changes: 0 additions & 17 deletions app/src/test/java/coatapp/coat/ExampleUnitTest.java

This file was deleted.

Loading

0 comments on commit 7899949

Please sign in to comment.