Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Add unit test for currently and hasXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdme committed Dec 28, 2016
1 parent d4a5104 commit f24a576
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ fabric.properties

target/

test/resources/apikey.txt
src/test/resources/apikey.txt
95 changes: 95 additions & 0 deletions src/test/java/com/github/dvdme/ForecastIOLib/FIOCurrentlyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.github.dvdme.ForecastIOLib;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.Assert.*;

/**
* Created by david on 28/12/2016.
*/
public class FIOCurrentlyTest {

private String fakeApiKey = "00000000000000000000000000000000";
private String basePath = "src/test/resources/";
private FIOCurrently cur;

@Before
public void setUp() throws Exception {
String jsonText = getJsonText(basePath + "response.json");
ForecastIO fio = new ForecastIO(fakeApiKey);
fio.getForecast(jsonText);
cur = new FIOCurrently(fio);
assertNotNull("Got null FIOCurrently object", cur);
assertTrue("Got false hasCurrently()", fio.hasCurrently());
}

@Test
public void test_precipIntensity() throws Exception {
assertEquals(cur.get().precipIntensity(), 0, 0.1);
}

@Test
public void test_precipProbability() throws Exception {
assertEquals(cur.get().precipProbability(), 0, 0.1);
}

@Test
public void test_dewPoint() throws Exception {
assertEquals(cur.get().dewPoint(), 50.3, 0.1);
}

@Test
public void test_humidity() throws Exception {
assertEquals(cur.get().humidity(), 0.44, 0.1);
}

@Test
public void test_windSpeed() throws Exception {
assertEquals(cur.get().windSpeed(), 6.94, 0.1);
}

@Test
public void test_windBearing() throws Exception {
assertEquals(cur.get().windBearing(), 135, 0.1);
}

@Test
public void test_visibility() throws Exception {
assertEquals(cur.get().visibility(), 6.21, 0.1);
}

@Test
public void test_cloudCover() throws Exception {
assertEquals(cur.get().cloudCover(), 0.04, 0.1);
}

@Test
public void test_pressure() throws Exception {
assertEquals(cur.get().pressure(), 1017.6, 0.1);
}

@Test
public void test_ozone() throws Exception {
assertEquals(cur.get().ozone(), 247.7, 0.1);
}

@Test
public void test_apparentTemperature() throws Exception {
assertEquals(cur.get().apparentTemperature(), 73.65, 0.1);
}

@Test
public void get_temperature() throws Exception {
assertEquals(cur.get().temperature(), 73.65, 0.1);
}

private String getJsonText(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(path)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void main(String[] args) {
//Caracas: 10.4880555, -66.8791667

String apikey = null;
String apikeyPath = "test/resources/apikey.txt";
String apikeyPath = "src/test/resources/apikey.txt";
try {
apikey = new String(Files.readAllBytes(Paths.get(apikeyPath)));
} catch (IOException e) {
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/com/github/dvdme/ForecastIOLib/ForecastIOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

Expand All @@ -17,12 +18,13 @@
public class ForecastIOTest {

private String fakeApiKey = "00000000000000000000000000000000";
private String basePath = "src/test/resources/";
private String jsonText;
private ForecastIO fio;

@Before
public void setUp() throws Exception {
jsonText = new String(Files.readAllBytes(Paths.get("src/test/resources/response.json")));
jsonText = new String(Files.readAllBytes(Paths.get(basePath + "response.json")));
fio = new ForecastIO(fakeApiKey);
assertNotNull("ForecastIO object is null at setUp()", fio);
fio.getForecast(jsonText);
Expand Down Expand Up @@ -137,10 +139,30 @@ public void getLang() throws Exception {
@Test
public void getCurrently() throws Exception {
FIOCurrently cur = new FIOCurrently(fio);
assertNotNull("Got null FIOurrently object", cur);
assertNotNull("Got null FIOCurrently object", cur);
assertTrue("Got false hasCurrently()", fio.hasCurrently());
}

@Test
public void getEmptyCurrently() throws Exception {
String jsonText = getJsonText(basePath + "response_empty_currently.json");
ForecastIO fio = new ForecastIO(fakeApiKey);
fio.getForecast(jsonText);
FIOCurrently cur = new FIOCurrently(fio);
assertNotNull("Got null FIOCurrently object", cur);
assertFalse("Got true hasCurrently()", fio.hasCurrently());
}

@Test
public void getNullCurrently() throws Exception {
String jsonText = getJsonText(basePath + "response_null_currently.json");
ForecastIO fio = new ForecastIO(fakeApiKey);
fio.getForecast(jsonText);
FIOCurrently cur = new FIOCurrently(fio);
assertNotNull("Got null FIOCurrently object", cur);
assertFalse("Got true hasCurrently()", fio.hasCurrently());
}

@Test
public void getMinutely() throws Exception {
FIOMinutely min = new FIOMinutely(fio);
Expand Down Expand Up @@ -218,4 +240,8 @@ public void getRawResponse() throws Exception {
assertEquals("Got differet raw string", jsonText, fio.getRawResponse());
}

private String getJsonText(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(path)));
}

}
1 change: 1 addition & 0 deletions src/test/resources/response_empty_currently.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/test/resources/response_null_currently.json

Large diffs are not rendered by default.

0 comments on commit f24a576

Please sign in to comment.