diff options
author | Camil Staps | 2015-06-10 18:15:24 +0200 |
---|---|---|
committer | Camil Staps | 2015-06-10 18:15:24 +0200 |
commit | 757aea73c705824acb7dea0e12fa72809098efd7 (patch) | |
tree | 5703dbf09a100b2ca8f796d77853e5644b2e2ab1 | |
parent | License (diff) |
Cleanup; license
-rw-r--r--[-rwxr-xr-x] | app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java | 33 | ||||
-rw-r--r--[-rwxr-xr-x] | app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java | 18 | ||||
-rw-r--r-- | app/src/androidTest/java/org/rssin/rss/FeedLoaderTest.java | 26 | ||||
-rw-r--r-- | app/src/androidTest/java/org/rssin/rssin/ApplicationTest.java | 13 | ||||
-rw-r--r-- | app/src/test/java/org/rssin/http/SimpleFetcher.java | 43 | ||||
-rw-r--r-- | app/src/test/java/org/rssin/listener/SimpleFallibleListener.java | 17 | ||||
-rw-r--r-- | app/src/test/java/org/rssin/serialization/JsonSerializationTest.java | 110 |
7 files changed, 45 insertions, 215 deletions
diff --git a/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java index a6e3581..ba76dea 100755..100644 --- a/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java +++ b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java @@ -1,3 +1,21 @@ +/**
+ * RSSin - Clever RSS reader for Android
+ * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
package org.rssin.neurons;
import android.util.Log;
@@ -6,6 +24,7 @@ import junit.framework.Assert; import junit.framework.TestCase;
import org.rssin.rss.FeedItem;
+import org.rssin.rssin.SortedFeedItemContainer;
import java.net.URL;
import java.util.ArrayList;
@@ -105,13 +124,15 @@ public class FeedSorterTest extends TestCase { }
private void testSortingOrder(FeedSorter s, FeedItem dislikedItem, FeedItem likedItem) {
- List<FeedItem> testItems = new LinkedList<>();
- testItems.add(dislikedItem);
- testItems.add(likedItem);
+ List<SortedFeedItemContainer> testItems = new LinkedList<>();
- List<FeedItem> sortedItems = s.sortItems(testItems);
- Assert.assertEquals(sortedItems.get(0), likedItem);
- Assert.assertEquals(sortedItems.get(1), dislikedItem);
+ testItems.add(new SortedFeedItemContainer(dislikedItem));
+ testItems.add(new SortedFeedItemContainer(likedItem));
+
+ s.sortItems(testItems);
+
+ Assert.assertEquals(testItems.get(0), likedItem);
+ Assert.assertEquals(testItems.get(1), dislikedItem);
}
private void trainNetwork(FeedItem[] likedItems, FeedItem[] dislikedItems, FeedSorter s) {
diff --git a/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java b/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java index 57776f3..2c05e8a 100755..100644 --- a/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java +++ b/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java @@ -1,3 +1,21 @@ +/** + * RSSin - Clever RSS reader for Android + * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Joep Bernards, Camil Staps + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ package org.rssin.neurons;
import junit.framework.Assert;
diff --git a/app/src/androidTest/java/org/rssin/rss/FeedLoaderTest.java b/app/src/androidTest/java/org/rssin/rss/FeedLoaderTest.java deleted file mode 100644 index 58e9467..0000000 --- a/app/src/androidTest/java/org/rssin/rss/FeedLoaderTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.rssin.rss; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.rssin.http.SimpleFetcher; -import org.rssin.listener.SimpleFallibleListener; - -import java.net.URL; - -/** - * Created by Randy on 21-5-2015. - */ -public class FeedLoaderTest extends TestCase { - - - public void testFetchXML() throws Exception { - String urlstring = "http://www.pcworld.com/index.rss"; - URL url = new URL(urlstring); - FeedLoader loader = new FeedLoader(url); - loader.fetchXML(new SimpleFetcher(), new SimpleFallibleListener()); - FeedItem f = loader.getFeed().getPosts().get(0); - Assert.assertEquals(f.getTitle(), "Amazon adds local groceries and meals to one-hour Prime Now delivery service"); - } - -}
\ No newline at end of file diff --git a/app/src/androidTest/java/org/rssin/rssin/ApplicationTest.java b/app/src/androidTest/java/org/rssin/rssin/ApplicationTest.java deleted file mode 100644 index 0c5e470..0000000 --- a/app/src/androidTest/java/org/rssin/rssin/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.rssin.rssin; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> - */ -public class ApplicationTest extends ApplicationTestCase<Application> { - public ApplicationTest() { - super(Application.class); - } -}
\ No newline at end of file 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; - } - } - -} |