aboutsummaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorCamil Staps2015-06-10 18:15:24 +0200
committerCamil Staps2015-06-10 18:15:24 +0200
commit757aea73c705824acb7dea0e12fa72809098efd7 (patch)
tree5703dbf09a100b2ca8f796d77853e5644b2e2ab1 /app/src/test
parentLicense (diff)
Cleanup; license
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/org/rssin/http/SimpleFetcher.java43
-rw-r--r--app/src/test/java/org/rssin/listener/SimpleFallibleListener.java17
-rw-r--r--app/src/test/java/org/rssin/serialization/JsonSerializationTest.java110
3 files changed, 0 insertions, 170 deletions
diff --git a/app/src/test/java/org/rssin/http/SimpleFetcher.java b/app/src/test/java/org/rssin/http/SimpleFetcher.java
deleted file mode 100644
index b7e9871..0000000
--- a/app/src/test/java/org/rssin/http/SimpleFetcher.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.rssin.http;
-
-import org.rssin.listener.ErrorListener;
-import org.rssin.listener.Listener;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-/**
- * This Fetcher doesn't work on Android, but can be used for automated tests
- * @author Camil Staps
- */
-public class SimpleFetcher implements Fetcher {
-
- @Override
- /**
- * @todo implement when needed.
- */
- public void fetch(Request request) {
- }
-
- @Override
- public void fetch(Request request, Listener listener) {
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(request.getURL().openStream()));
-
- StringBuilder everything = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- everything.append(inputLine);
- in.close();
-
- listener.onReceive(everything.toString());
- } catch (IOException e) {
- if (ErrorListener.class.isAssignableFrom(listener.getClass())) {
- ErrorListener errorListener = (ErrorListener) listener;
- errorListener.onError(e);
- }
- }
- }
-
-}
diff --git a/app/src/test/java/org/rssin/listener/SimpleFallibleListener.java b/app/src/test/java/org/rssin/listener/SimpleFallibleListener.java
deleted file mode 100644
index 8be95b4..0000000
--- a/app/src/test/java/org/rssin/listener/SimpleFallibleListener.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.rssin.listener;
-
-/**
- * Simple FallibleListener for tests
- * @author Camil Staps
- */
-public class SimpleFallibleListener implements FallibleListener<Object, Object> {
- @Override
- public void onError(Object error) {
- System.err.println(error.toString());
- }
-
- @Override
- public void onReceive(Object data) {
- System.out.println(data.toString());
- }
-}
diff --git a/app/src/test/java/org/rssin/serialization/JsonSerializationTest.java b/app/src/test/java/org/rssin/serialization/JsonSerializationTest.java
deleted file mode 100644
index c8cda01..0000000
--- a/app/src/test/java/org/rssin/serialization/JsonSerializationTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package org.rssin.serialization;
-
-import junit.framework.TestCase;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * Automated tests for the JsonSerializer
- * @author Camil Staps
- */
-public class JsonSerializationTest extends TestCase {
-
- Random r;
-
- public JsonSerializationTest() {
- r = new Random(System.currentTimeMillis());
- }
-
- /**
- * Test that the readObject and writeObject of the inner class SimpleJsonableExample are setup
- * correctly; otherwise the tests fail because of that.
- */
- public void testSimpleJsonableExample() {
- for (int i = 0; i < 10; i++) {
- SimpleJsonableExample ex = randomSimpleJsonableExample();
- SimpleJsonableExample test = new SimpleJsonableExample();
- try {
- test.fromJson(ex.toJson());
- } catch (JSONException e) {
- fail("JSONException: " + e.getMessage());
- }
- assertEquals(ex, test);
- }
- }
-
- /**
- * Test {@link JsonSerializer#listToJson(List)} and {@link JsonSerializer#listFromJson(JSONArray, List)}
- * @throws JSONException
- */
- public void testLists() throws JSONException {
- List<SimpleJsonableExample> list = new ArrayList<>();
- List<SimpleJsonableExample> second_list = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- list.add(randomSimpleJsonableExample());
- second_list.add(new SimpleJsonableExample());
- }
- JsonSerializer.listFromJson(JsonSerializer.listToJson(list), second_list);
- for (int i = 0; i < 10; i++) {
- assertEquals(list.get(i), second_list.get(i));
- }
- }
-
- /**
- * Get a random SimpleJsonableExample
- * @return
- */
- private SimpleJsonableExample randomSimpleJsonableExample() {
- return new SimpleJsonableExample(UUID.randomUUID().toString(), r.nextInt());
- }
-
- /**
- * A simple Jsonable object with a String and an int.
- */
- private static class SimpleJsonableExample implements Jsonable {
-
- private String myString;
- private int myInt;
-
- public SimpleJsonableExample() {
- }
-
- public SimpleJsonableExample(String s, int i) {
- myString = s;
- myInt = i;
- }
-
- @Override
- public JSONObject toJson() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("myString", myString);
- json.put("myInt", myInt);
- return json;
- }
-
- @Override
- public void fromJson(JSONObject json) throws JSONException {
- myString = json.getString("myString");
- myInt = json.getInt("myInt");
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == null || o.getClass() != SimpleJsonableExample.class)
- return false;
-
- SimpleJsonableExample another = (SimpleJsonableExample) o;
-
- return another.myString == myString &&
- another.myInt == myInt;
- }
- }
-
-}