diff --git a/Habitica/build.gradle b/Habitica/build.gradle
index a1e63ba2f..626077210 100644
--- a/Habitica/build.gradle
+++ b/Habitica/build.gradle
@@ -2,19 +2,26 @@ apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
-apply plugin: 'com.chaitanyapramod.findbugs-android'
+apply plugin: 'com.noveogroup.android.check'
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
+ jcenter()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.21.5'
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
+ classpath('com.noveogroup.android:check:1.2.3') {
+ exclude module: 'checkstyle'
+ exclude module: 'pmd-java'
+ }
+ classpath 'com.puppycrawl.tools:checkstyle:7.5'
+ classpath 'net.sourceforge.pmd:pmd-java:5.5.3'
}
}
@@ -62,10 +69,10 @@ dependencies {
compile('com.mikepenz:materialdrawer:5.3.6@aar') {
transitive = true
}
- compile 'com.android.support:appcompat-v7:25.1.0'
- compile 'com.android.support:design:25.1.0'
- compile 'com.android.support:recyclerview-v7:25.1.0'
- compile 'com.android.support:preference-v14:25.1.0'
+ compile 'com.android.support:appcompat-v7:25.1.1'
+ compile 'com.android.support:design:25.1.1'
+ compile 'com.android.support:recyclerview-v7:25.1.1'
+ compile 'com.android.support:preference-v14:25.1.1'
compile 'com.android.support:multidex:1.0.1'
//QR Code
@@ -281,6 +288,8 @@ tasks.whenTaskAdded { task ->
}
}
+check { findbugs { skip true } }
+
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
diff --git a/Habitica/config/checkstyle.xml b/Habitica/config/checkstyle.xml
new file mode 100644
index 000000000..cd58f6806
--- /dev/null
+++ b/Habitica/config/checkstyle.xml
@@ -0,0 +1,268 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Habitica/config/pmd.xml b/Habitica/config/pmd.xml
new file mode 100644
index 000000000..4ec9b7a37
--- /dev/null
+++ b/Habitica/config/pmd.xml
@@ -0,0 +1,138 @@
+
+
+
+
+
+ POM rule set file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Habitica/src/main/java/com/magicmicky/habitrpgwrapper/lib/models/SubscriptionPlan.java b/Habitica/src/main/java/com/magicmicky/habitrpgwrapper/lib/models/SubscriptionPlan.java
index 879ae27ba..d1950d84d 100644
--- a/Habitica/src/main/java/com/magicmicky/habitrpgwrapper/lib/models/SubscriptionPlan.java
+++ b/Habitica/src/main/java/com/magicmicky/habitrpgwrapper/lib/models/SubscriptionPlan.java
@@ -50,7 +50,7 @@ public class SubscriptionPlan extends BaseModel {
public boolean isActive() {
Date today = new Date();
- return (this.dateCreated != null && this.dateCreated.before(today)) && (this.dateTerminated == null || this.dateTerminated.after(today));
+ return planId != null && this.dateTerminated == null || this.dateTerminated.after(today);
}
@Override
diff --git a/build.gradle b/build.gradle
index fcf34d14b..744edbc25 100644
--- a/build.gradle
+++ b/build.gradle
@@ -9,7 +9,6 @@ buildscript {
classpath 'com.android.databinding:dataBinder:1.0-rc4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
- classpath 'com.chaitanyapramod.gradle:findbugs-android:1.0'
}
}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/AdvertisingIdAdapterTest.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/AdvertisingIdAdapterTest.java
deleted file mode 100644
index c4c8a54e9..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/AdvertisingIdAdapterTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.playseeds.android.sdk;
-
-import android.content.Context;
-import android.test.AndroidTestCase;
-
-public class AdvertisingIdAdapterTest extends AndroidTestCase {
- Context context;
-
- public void setUp() throws Exception {
- context = getContext();
- }
-
- public void testIsAdvertisingIdAvailable() throws Exception {
- assertNotNull(AdvertisingIdAdapter.isAdvertisingIdAvailable());
- }
-
- public void testSetAdvertisingId() throws Exception {
- try {
- AdvertisingIdAdapter.setAdvertisingId(context, new CountlyStore(context), new DeviceId(DeviceId.Type.ADVERTISING_ID));
- } catch(Exception e) {
-
- }
- }
-
- public void testSetAdvertisingIdWithNullContext() throws Exception {
- try {
- AdvertisingIdAdapter.setAdvertisingId(null, new CountlyStore(context), new DeviceId(DeviceId.Type.ADVERTISING_ID));
- } catch (Exception e) {
-
- }
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionProcessorTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionProcessorTests.java
deleted file mode 100755
index aef00c148..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionProcessorTests.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.test.AndroidTestCase;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class ConnectionProcessorTests extends AndroidTestCase {
- ConnectionProcessor connectionProcessor;
- CountlyStore mockStore;
- DeviceId mockDeviceId;
- String testDeviceId;
- String eventData;
- HttpURLConnection mockURLConnection;
- CountlyResponseStream testInputStream;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- testDeviceId = "123";
- eventData = "blahblahblah";
- mockStore = mock(CountlyStore.class);
- mockDeviceId = mock(DeviceId.class);
- mockURLConnection = mock(HttpURLConnection.class);
- testInputStream = new CountlyResponseStream("Success");
- connectionProcessor = new ConnectionProcessor("http://devdash.playseeds.com", mockStore, mockDeviceId, null);
- connectionProcessor = spy(connectionProcessor);
- }
-
- public void testConstructorAndGetters() {
- final String serverURL = "https://secureserver";
- final CountlyStore mockStore = mock(CountlyStore.class);
- final DeviceId mockDeviceId = mock(DeviceId.class);
- final ConnectionProcessor connectionProcessor1 = new ConnectionProcessor(serverURL, mockStore, mockDeviceId, null);
- assertEquals(serverURL, connectionProcessor1.getServerURL());
- assertSame(mockStore, connectionProcessor1.getCountlyStore());
- assertSame(mockDeviceId, connectionProcessor1.getDeviceId());
- }
-
- public void testUrlConnectionForEventData() throws IOException {
- final URLConnection urlConnection = connectionProcessor.urlConnectionForEventData(eventData);
- assertEquals(30000, urlConnection.getConnectTimeout());
- assertEquals(30000, urlConnection.getReadTimeout());
- assertFalse(urlConnection.getUseCaches());
- assertTrue(urlConnection.getDoInput());
- assertFalse(urlConnection.getDoOutput());
- assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData), urlConnection.getURL());
- }
-
- public void testRun_storeReturnsNullConnections() throws IOException {
- when(mockStore.connections()).thenReturn(null);
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor, times(0)).urlConnectionForEventData(anyString());
- }
-
- public void testRun_storeReturnsEmptyConnections() throws IOException {
- when(mockStore.connections()).thenReturn(new String[0]);
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor, times(0)).urlConnectionForEventData(anyString());
- }
-
- private static class TestInputStream extends InputStream {
- int readCount = 0;
- boolean fullyRead() { return readCount >= 2; }
- boolean closed = false;
-
- @Override
- public int read() throws IOException {
- return readCount++ < 1 ? 1 : -1;
- }
-
- @Override
- public void close() throws IOException {
- super.close();
- closed = true;
- }
- }
-
- private static class CountlyResponseStream extends ByteArrayInputStream {
- boolean closed = false;
-
- CountlyResponseStream(final String result) throws UnsupportedEncodingException {
- super(("{\"result\":\"" + result + "\"}").getBytes("UTF-8"));
- }
-
- boolean fullyRead() { return pos == buf.length; }
-
- @Override
- public void close() throws IOException {
- super.close();
- closed = true;
- }
- }
-
- public void testRun_storeHasSingleConnection() throws IOException {
- when(mockStore.connections()).thenReturn(new String[]{eventData}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- when(mockURLConnection.getResponseCode()).thenReturn(200);
- when(connectionProcessor.urlConnectionForEventData(eventData + "&device_id=" + testInputStream)).thenReturn(mockURLConnection);
-
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- }
-
- public void testRun_storeHasSingleConnection_butHTTPResponseCodeWasNot2xx() throws IOException {
- when(mockStore.connections()).thenReturn(new String[]{eventData}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- when(mockURLConnection.getResponseCode()).thenReturn(300);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
-
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(mockURLConnection).connect();
- verify(mockURLConnection).getInputStream();
- verify(mockURLConnection).getResponseCode();
- assertTrue(testInputStream.fullyRead());
- verify(mockStore, times(0)).removeConnection(eventData);
- assertTrue(testInputStream.closed);
- verify(mockURLConnection).disconnect();
- }
-
- public void testRun_storeHasSingleConnection_butResponseWasNotJSON() throws IOException {
- when(mockStore.connections()).thenReturn(new String[]{eventData}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- when(mockURLConnection.getResponseCode()).thenReturn(300);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
-
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(mockURLConnection).connect();
- verify(mockURLConnection).getInputStream();
- verify(mockURLConnection).getResponseCode();
- assertTrue(testInputStream.fullyRead());
- verify(mockStore, times(0)).removeConnection(eventData);
- assertTrue(testInputStream.closed);
- verify(mockURLConnection).disconnect();
- }
-
- public void testRun_storeHasSingleConnection_butResponseJSONWasNotSuccess() throws IOException {
- when(mockStore.connections()).thenReturn(new String[]{eventData}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- when(mockURLConnection.getResponseCode()).thenReturn(300);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
-
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(mockURLConnection).connect();
- verify(mockURLConnection).getInputStream();
- assertTrue(testInputStream.fullyRead());
- verify(mockURLConnection).getResponseCode();
- verify(mockStore, times(0)).removeConnection(eventData);
- assertTrue(testInputStream.closed);
- verify(mockURLConnection).disconnect();
- }
-
- public void testRun_storeHasSingleConnection_successCheckIsCaseInsensitive() throws IOException {
- testInputStream = new CountlyResponseStream("SuCcEsS");
-
- when(mockStore.connections()).thenReturn(new String[]{eventData}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- when(mockURLConnection.getResponseCode()).thenReturn(200);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
-
- connectionProcessor.run();
- verify(mockStore, times(2)).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(mockURLConnection).connect();
- verify(mockURLConnection).getInputStream();
- verify(mockURLConnection).getResponseCode();
- assertTrue(testInputStream.fullyRead());
- verify(mockStore).removeConnection(eventData);
- assertTrue(testInputStream.closed);
- verify(mockURLConnection).disconnect();
- }
-
- public void testRun_storeHasTwoConnections() throws IOException {
- final String eventData2 = "123523523432";
- final CountlyResponseStream testInputStream2 = new CountlyResponseStream("Success");
- testInputStream = new CountlyResponseStream("Success");
-
- when(mockStore.connections()).thenReturn(new String[]{eventData, eventData2}, new String[]{eventData2}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream, testInputStream2);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData2 + "&device_id=" + testDeviceId);
- when(mockURLConnection.getResponseCode()).thenReturn(200, 200);
-
- connectionProcessor.run();
- verify(mockStore, times(3)).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(connectionProcessor).urlConnectionForEventData(eventData2 + "&device_id=" + testDeviceId);
- verify(mockURLConnection, times(2)).connect();
- verify(mockURLConnection, times(2)).getInputStream();
- verify(mockURLConnection, times(2)).getResponseCode();
- assertTrue(testInputStream.fullyRead());
- assertTrue(testInputStream2.fullyRead());
- verify(mockStore).removeConnection(eventData);
- verify(mockStore).removeConnection(eventData2);
- assertTrue(testInputStream.closed);
- assertTrue(testInputStream2.closed);
- verify(mockURLConnection, times(2)).disconnect();
- }
-
- private static class TestInputStream2 extends InputStream {
- boolean closed = false;
-
- @Override
- public int read() throws IOException {
- throw new IOException();
- }
-
- @Override
- public void close() throws IOException {
- super.close();
- closed = true;
- }
- }
-
- public void testRun_storeHasTwoConnections_butFirstOneThrowsWhenInputStreamIsRead() throws IOException {
- final String eventData2 = "123523523432";
- final TestInputStream2 testInputStream = new TestInputStream2();
-
- when(mockStore.connections()).thenReturn(new String[]{eventData, eventData2}, new String[]{eventData2}, new String[0]);
- when(mockDeviceId.getId()).thenReturn(testDeviceId);
- when(mockURLConnection.getInputStream()).thenReturn(testInputStream);
- doReturn(mockURLConnection).when(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
-
- connectionProcessor.run();
- verify(mockStore).connections();
- verify(connectionProcessor).urlConnectionForEventData(eventData + "&device_id=" + testDeviceId);
- verify(connectionProcessor, times(0)).urlConnectionForEventData(eventData2 + "&device_id=" + testDeviceId);
- verify(mockURLConnection).connect();
- verify(mockURLConnection).getInputStream();
- verify(mockStore, times(0)).removeConnection(anyString());
- assertTrue(testInputStream.closed);
- verify(mockURLConnection).disconnect();
- }
-}
\ No newline at end of file
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionQueueTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionQueueTests.java
deleted file mode 100755
index 99bd5bf8a..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/ConnectionQueueTests.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.net.Uri;
-import android.test.AndroidTestCase;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.mockito.ArgumentCaptor;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class ConnectionQueueTests extends AndroidTestCase {
- ConnectionQueue connQ;
- ConnectionQueue freshConnQ;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- freshConnQ = new ConnectionQueue();
- connQ = new ConnectionQueue();
- connQ.setAppKey("abcDeFgHiJkLmNoPQRstuVWxyz");
- connQ.setServerURL("http://countly.coupons.com");
- connQ.setContext(getContext());
- connQ.setCountlyStore(mock(CountlyStore.class));
- connQ.setDeviceId(mock(DeviceId.class));
- connQ.setExecutor(mock(ExecutorService.class));
- }
-
- public void testConstructor() {
- assertNull(freshConnQ.getCountlyStore());
- assertNull(freshConnQ.getDeviceId());
- assertNull(freshConnQ.getAppKey());
- assertNull(freshConnQ.getContext());
- assertNull(freshConnQ.getServerURL());
- assertNull(freshConnQ.getExecutor());
- }
-
- public void testAppKey() {
- final String appKey = "blahblahblah";
- freshConnQ.setAppKey(appKey);
- assertEquals(appKey, freshConnQ.getAppKey());
- }
-
- public void testContext() {
- freshConnQ.setContext(getContext());
- assertSame(getContext(), freshConnQ.getContext());
- }
-
- public void testServerURL() {
- final String serverURL = "http://countly.coupons.com";
- freshConnQ.setServerURL(serverURL);
- assertEquals(serverURL, freshConnQ.getServerURL());
- }
-
- public void testCountlyStore() {
- final CountlyStore store = new CountlyStore(getContext());
- freshConnQ.setCountlyStore(store);
- assertSame(store, freshConnQ.getCountlyStore());
- }
-
- public void testDeviceId() {
- final DeviceId deviceId = new DeviceId("blah");
- freshConnQ.setDeviceId(deviceId);
- assertSame(deviceId, freshConnQ.getDeviceId());
- }
-
- public void testExecutor() {
- final ExecutorService executor = Executors.newSingleThreadExecutor();
- freshConnQ.setExecutor(executor);
- assertSame(executor, freshConnQ.getExecutor());
- }
-
- public void testCheckInternalState_nullAppKey() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setAppKey(null);
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testCheckInternalState_emptyAppKey() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setAppKey("");
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testCheckInternalState_nullStore() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setCountlyStore(null);
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testCheckInternalState_nullContext() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setContext(null);
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testCheckInternalState_nullServerURL() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setServerURL(null);
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testCheckInternalState_invalidServerURL() {
- connQ.checkInternalState(); // shouldn't throw
- connQ.setServerURL("blahblahblah.com");
- try {
- freshConnQ.checkInternalState();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testBeginSession_checkInternalState() {
- try {
- freshConnQ.beginSession();
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testBeginSession() throws JSONException, UnsupportedEncodingException {
- connQ.beginSession();
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp-1) <= actualTimestamp) && ((curTimestamp+1) >= actualTimestamp));
- assertEquals(Seeds.COUNTLY_SDK_VERSION_STRING, queryParams.get("sdk_version"));
- assertEquals("1", queryParams.get("begin_session"));
- // validate metrics
- final JSONObject actualMetrics = new JSONObject(queryParams.get("metrics"));
- final String metricsJsonStr = URLDecoder.decode(DeviceInfo.getMetrics(getContext()), "UTF-8");
- final JSONObject expectedMetrics = new JSONObject(metricsJsonStr);
- assertEquals(expectedMetrics.length(), actualMetrics.length());
- final Iterator actualMetricsKeyIterator = actualMetrics.keys();
- while (actualMetricsKeyIterator.hasNext()) {
- final String key = (String) actualMetricsKeyIterator.next();
- assertEquals(expectedMetrics.get(key), actualMetrics.get(key));
- }
- }
-
- public void testUpdateSession_checkInternalState() {
- try {
- freshConnQ.updateSession(15);
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testUpdateSession_zeroDuration() {
- connQ.updateSession(0);
- verifyZeroInteractions(connQ.getExecutor(), connQ.getCountlyStore());
- }
-
- public void testUpdateSession_negativeDuration() {
- connQ.updateSession(-1);
- verifyZeroInteractions(connQ.getExecutor(), connQ.getCountlyStore());
- }
-
- public void testUpdateSession_moreThanZeroDuration() {
- connQ.updateSession(60);
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp-1) <= actualTimestamp) && ((curTimestamp+1) >= actualTimestamp));
- assertEquals("60", queryParams.get("session_duration"));
- }
-
- public void testEndSession_checkInternalState() {
- try {
- freshConnQ.endSession(15);
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testEndSession_zeroDuration() {
- connQ.endSession(0);
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp-1) <= actualTimestamp) && ((curTimestamp+1) >= actualTimestamp));
- assertFalse(queryParams.containsKey("session_duration"));
- assertEquals("1", queryParams.get("end_session"));
- }
-
- public void testEndSession_negativeDuration() {
- connQ.endSession(-1);
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp-1) <= actualTimestamp) && ((curTimestamp+1) >= actualTimestamp));
- assertFalse(queryParams.containsKey("session_duration"));
- assertEquals("1", queryParams.get("end_session"));
- }
-
- public void testEndSession_moreThanZeroDuration() {
- connQ.endSession(15);
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp-1) <= actualTimestamp) && ((curTimestamp+1) >= actualTimestamp));
- assertEquals("1", queryParams.get("end_session"));
- assertEquals("15", queryParams.get("session_duration"));
- }
-
- public void testRecordEvents_checkInternalState() {
- try {
- freshConnQ.recordEvents("blahblahblah");
- fail("expected IllegalStateException when internal state is not set up");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testRecordEvents() {
- final String eventData = "blahblahblah";
- connQ.recordEvents(eventData);
- final ArgumentCaptor arg = ArgumentCaptor.forClass(String.class);
- verify(connQ.getCountlyStore()).addConnection(arg.capture());
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
-
- // verify query parameters
- final String queryStr = arg.getValue();
- final Map queryParams = parseQueryParams(queryStr);
- assertEquals(connQ.getAppKey(), queryParams.get("app_key"));
- assertNull(queryParams.get("device_id"));
- final long curTimestamp = Seeds.currentTimestamp();
- final int actualTimestamp = Integer.parseInt(queryParams.get("timestamp"));
- // this check attempts to account for minor time changes during this ly.count.android.sdk.test
- assertTrue(((curTimestamp - 1) <= actualTimestamp) && ((curTimestamp + 1) >= actualTimestamp));
- assertEquals(eventData, queryParams.get("events"));
- }
-
- private Map parseQueryParams(final String queryStr) {
- final String urlStr = "http://server?" + queryStr;
- final Uri uri = Uri.parse(urlStr);
- final Set queryParameterNames = uri.getQueryParameterNames();
- final Map queryParams = new HashMap<>(queryParameterNames.size());
- for (String paramName : queryParameterNames) {
- queryParams.put(paramName, uri.getQueryParameter(paramName));
- }
- return queryParams;
- }
-
- public void testEnsureExecutor_nullExecutor() {
- assertNull(freshConnQ.getExecutor());
- freshConnQ.ensureExecutor();
- assertNotNull(freshConnQ.getExecutor());
- }
-
- public void testEnsureExecutor_alreadyHasExecutor() {
- ExecutorService executor = connQ.getExecutor();
- assertNotNull(executor);
- connQ.ensureExecutor();
- assertSame(executor, connQ.getExecutor());
- }
-
- public void testTick_storeHasNoConnections() {
- when(connQ.getCountlyStore().isEmptyConnections()).thenReturn(true);
- connQ.tick();
- verifyZeroInteractions(connQ.getExecutor());
- }
-
- public void testTick_storeHasConnectionsAndFutureIsNull() {
- final Future mockFuture = mock(Future.class);
- when(connQ.getExecutor().submit(any(ConnectionProcessor.class))).thenReturn(mockFuture);
- connQ.tick();
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
- assertSame(mockFuture, connQ.getConnectionProcessorFuture());
- }
-
- public void testTick_checkConnectionProcessor() {
- final ArgumentCaptor arg = ArgumentCaptor.forClass(Runnable.class);
- when(connQ.getExecutor().submit(arg.capture())).thenReturn(null);
- connQ.tick();
- assertEquals(((ConnectionProcessor)arg.getValue()).getServerURL(), connQ.getServerURL());
- assertSame(((ConnectionProcessor)arg.getValue()).getCountlyStore(), connQ.getCountlyStore());
- }
-
- public void testTick_storeHasConnectionsAndFutureIsDone() {
- final Future> mockFuture = mock(Future.class);
- when(mockFuture.isDone()).thenReturn(true);
- connQ.setConnectionProcessorFuture(mockFuture);
- final Future mockFuture2 = mock(Future.class);
- when(connQ.getExecutor().submit(any(ConnectionProcessor.class))).thenReturn(mockFuture2);
- connQ.tick();
- verify(connQ.getExecutor()).submit(any(ConnectionProcessor.class));
- assertSame(mockFuture2, connQ.getConnectionProcessorFuture());
- }
-
- public void testTick_storeHasConnectionsButFutureIsNotDone() {
- final Future> mockFuture = mock(Future.class);
- connQ.setConnectionProcessorFuture(mockFuture);
- connQ.tick();
- verifyZeroInteractions(connQ.getExecutor());
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyStoreTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyStoreTests.java
deleted file mode 100755
index 78364b54a..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyStoreTests.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.test.AndroidTestCase;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class CountlyStoreTests extends AndroidTestCase {
- CountlyStore store;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- store = new CountlyStore(getContext());
- store.clear();
- }
-
- @Override
- protected void tearDown() throws Exception {
- store.clear();
- super.tearDown();
- }
-
- public void testConstructor_nullContext() {
- try {
- new CountlyStore(null);
- fail("expected IllegalArgumentException when calling CountlyStore() ctor with null context");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testConstructor() {
- Context mockContext = mock(Context.class);
- new CountlyStore(mockContext);
- verify(mockContext).getSharedPreferences("COUNTLY_STORE", Context.MODE_PRIVATE);
- }
-
- public void testConnections_prefIsNull() {
- // the clear() call in setUp ensures the pref is not present
- assertTrue(Arrays.equals(new String[0], store.connections()));
- }
-
- public void testConnections_prefIsEmptyString() {
- // the following two calls will result in the pref being an empty string
- final String connStr = "blah";
- store.addConnection(connStr);
- store.removeConnection(connStr);
- assertTrue(Arrays.equals(new String[0], store.connections()));
- }
-
- public void testConnections_prefHasSingleValue() {
- final String connStr = "blah";
- store.addConnection(connStr);
- assertTrue(Arrays.equals(new String[]{connStr}, store.connections()));
- }
-
- public void testConnections_prefHasTwoValues() {
- final String connStr1 = "blah1";
- final String connStr2 = "blah2";
- store.addConnection(connStr1);
- store.addConnection(connStr2);
- assertTrue(Arrays.equals(new String[]{connStr1,connStr2}, store.connections()));
- }
-
- public void testEvents_prefIsNull() {
- // the clear() call in setUp ensures the pref is not present
- assertTrue(Arrays.equals(new String[0], store.events()));
- }
-
- public void testEvents_prefIsEmptyString() {
- // the following two calls will result in the pref being an empty string
- store.addEvent("eventKey", null, Seeds.currentTimestamp(), 1, 0.0d);
- store.removeEvents(store.eventsList());
- assertTrue(Arrays.equals(new String[0], store.events()));
- }
-
- public void testEvents_prefHasSingleValue() throws JSONException {
- final String eventKey = "eventKey";
- store.addEvent(eventKey, null, Seeds.currentTimestamp(), 1, 0.0d);
- final String[] eventJSONStrs = store.events();
- final JSONObject eventJSONObj = new JSONObject(eventJSONStrs[0]);
- assertEquals(eventKey, eventJSONObj.getString("key"));
- // this is good enough, we verify the entire JSON content is written in later unit tests
- }
-
- public void testEvents_prefHasTwoValues() throws JSONException {
- final String eventKey1 = "eventKey1";
- final String eventKey2 = "eventKey2";
- store.addEvent(eventKey1, null, Seeds.currentTimestamp(), 1, 0.0d);
- store.addEvent(eventKey2, null, Seeds.currentTimestamp(), 1, 0.0d);
- final String[] eventJSONStrs = store.events();
- final JSONObject eventJSONObj1 = new JSONObject(eventJSONStrs[0]);
- assertEquals(eventKey1, eventJSONObj1.getString("key"));
- final JSONObject eventJSONObj2 = new JSONObject(eventJSONStrs[1]);
- assertEquals(eventKey2, eventJSONObj2.getString("key"));
- // this is good enough, we verify the entire JSON content is written in later unit tests
- }
-
- public void testEventsList_noEvents() {
- assertEquals(new ArrayList(0), store.eventsList());
- }
-
- public void testEventsList_singleEvent() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp();
- event1.count = 1;
- store.addEvent(event1.key, event1.segmentation, event1.timestamp, event1.count, event1.sum);
- final List expected = new ArrayList(1);
- expected.add(event1);
- final List actual = store.eventsList();
- assertEquals(expected, actual);
- }
-
- public void testEventsList_sortingOfMultipleEvents() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp();
- event1.count = 1;
- final Event event2 = new Event();
- event2.key = "eventKey2";
- event2.timestamp = Seeds.currentTimestamp() - 60;
- event2.count = 1;
- final Event event3 = new Event();
- event3.key = "eventKey3";
- event3.timestamp = Seeds.currentTimestamp() - 30;
- event3.count = 1;
- store.addEvent(event1.key, event1.segmentation, event1.timestamp, event1.count, event1.sum);
- store.addEvent(event2.key, event2.segmentation, event2.timestamp, event2.count, event2.sum);
- store.addEvent(event3.key, event3.segmentation, event3.timestamp, event3.count, event3.sum);
- final List expected = new ArrayList(3);
- expected.add(event2);
- expected.add(event3);
- expected.add(event1);
- final List actual = store.eventsList();
- assertEquals(expected, actual);
- }
-
- public void testEventsList_badJSON() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp() - 60;
- event1.count = 1;
- final Event event2 = new Event();
- event2.key = "eventKey2";
- event2.timestamp = Seeds.currentTimestamp();
- event2.count = 1;
-
- final String joinedEventsWithBadJSON = event1.toJSON().toString() + "===blah===" + event2.toJSON().toString();
- final SharedPreferences prefs = getContext().getSharedPreferences("COUNTLY_STORE", Context.MODE_PRIVATE);
- prefs.edit().putString("EVENTS", joinedEventsWithBadJSON).commit();
-
- final List expected = new ArrayList(2);
- expected.add(event1);
- expected.add(event2);
- final List actual = store.eventsList();
- assertNotSame(expected, actual);
- }
-
- public void testEventsList_EventFromJSONReturnsNull() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp() - 60;
- event1.count = 1;
- final Event event2 = new Event();
- event2.key = "eventKey2";
- event2.timestamp = Seeds.currentTimestamp();
- event2.count = 1;
-
- final String joinedEventsWithBadJSON = event1.toJSON().toString() + "==={\"key\":null}==" + event2.toJSON().toString();
- final SharedPreferences prefs = getContext().getSharedPreferences("COUNTLY_STORE", Context.MODE_PRIVATE);
- prefs.edit().putString("EVENTS", joinedEventsWithBadJSON).commit();
-
- final List expected = new ArrayList(2);
- expected.add(event1);
- expected.add(event2);
- final List actual = store.eventsList();
- assertNotSame(expected, actual);
- }
-
- public void testIsEmptyConnections_prefIsNull() {
- // the clear() call in setUp ensures the pref is not present
- assertTrue(store.isEmptyConnections());
- }
-
- public void testIsEmptyConnections_prefIsEmpty() {
- // the following two calls will result in the pref being an empty string
- final String connStr = "blah";
- store.addConnection(connStr);
- store.removeConnection(connStr);
- assertTrue(store.isEmptyConnections());
- }
-
- public void testIsEmptyConnections_prefIsPopulated() {
- final String connStr = "blah";
- store.addConnection(connStr);
- assertFalse(store.isEmptyConnections());
- }
-
- public void testAddConnection_nullStr() {
- store.addConnection(null);
- assertTrue(store.isEmptyConnections());
- }
-
- public void testAddConnection_emptyStr() {
- store.addConnection("");
- assertTrue(store.isEmptyConnections());
- }
-
- public void testRemoveConnection_nullStr() {
- store.addConnection("blah");
- store.removeConnection(null);
- assertFalse(store.isEmptyConnections());
- }
-
- public void testRemoveConnection_emptyStr() {
- store.addConnection("blah");
- store.removeConnection("");
- assertFalse(store.isEmptyConnections());
- }
-
- public void testRemoveConnection_firstConn() {
- store.addConnection("blah");
- assertFalse(store.isEmptyConnections());
- store.removeConnection("blah");
- assertTrue(store.isEmptyConnections());
- }
-
- public void testRemoveConnection_notFirstConn() {
- store.addConnection("blah1");
- store.addConnection("blah2");
- assertEquals(2, store.connections().length);
- store.removeConnection("blah2");
- assertEquals(1, store.connections().length);
- }
-
- public void testRemoveConnection_onlyRemovesFirstMatchingOne() {
- store.addConnection("blah1");
- store.addConnection("blah2");
- store.addConnection("blah1");
- assertEquals(3, store.connections().length);
- store.removeConnection("blah1");
- assertTrue(Arrays.equals(new String[]{"blah2", "blah1"}, store.connections()));
- }
-
- public void testAddEvent() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp() - 60;
- event1.count = 42;
- event1.sum = 3.2;
- event1.segmentation = new HashMap(2);
- event1.segmentation.put("segKey1", "segValue1");
- event1.segmentation.put("segKey2", "segValue2");
-
- store.addEvent(event1.key, event1.segmentation, event1.timestamp, event1.count, event1.sum);
-
- final List addedEvents = store.eventsList();
- assertEquals(1, addedEvents.size());
- final Event addedEvent = addedEvents.get(0);
- assertEquals(event1, addedEvent);
- assertEquals(event1.count, addedEvent.count);
- assertEquals(event1.sum, addedEvent.sum);
- }
-
- public void testRemoveEvents() {
- final Event event1 = new Event();
- event1.key = "eventKey1";
- event1.timestamp = Seeds.currentTimestamp() - 60;
- event1.count = 1;
- final Event event2 = new Event();
- event2.key = "eventKey2";
- event2.timestamp = Seeds.currentTimestamp() - 30;
- event2.count = 1;
- final Event event3 = new Event();
- event3.key = "eventKey2";
- event3.timestamp = Seeds.currentTimestamp();
- event3.count = 1;
-
- store.addEvent(event1.key, event1.segmentation, event1.timestamp, event1.count, event1.sum);
- store.addEvent(event2.key, event2.segmentation, event2.timestamp, event2.count, event2.sum);
-
- final List eventsToRemove = store.eventsList();
-
- store.addEvent(event3.key, event3.segmentation, event3.timestamp, event3.count, event3.sum);
-
- store.removeEvents(eventsToRemove);
-
- final List events = store.eventsList();
- assertEquals(1, events.size());
- assertEquals(event3, events.get(0));
- }
-
- public void testClear() {
- final SharedPreferences prefs = getContext().getSharedPreferences("COUNTLY_STORE", Context.MODE_PRIVATE);
- assertFalse(prefs.contains("EVENTS"));
- assertFalse(prefs.contains("CONNECTIONS"));
- store.addConnection("blah");
- store.addEvent("eventKey", null, Seeds.currentTimestamp(), 1, 0.0d);
- assertTrue(prefs.contains("EVENTS"));
- assertTrue(prefs.contains("CONNECTIONS"));
- store.clear();
- assertFalse(prefs.contains("EVENTS"));
- assertFalse(prefs.contains("CONNECTIONS"));
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyTests.java
deleted file mode 100755
index 4b1ea6f2d..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CountlyTests.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.content.Context;
-import android.test.AndroidTestCase;
-
-import java.util.HashMap;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-public class CountlyTests extends AndroidTestCase {
- Seeds mUninitedSeeds;
- Seeds mSeeds;
- ConnectionQueue mockConnectionQueue;
- EventQueue mockEventQueue;
- String eventKey;
- Context context;
- String serverUrl;
- String appKey;
- String deviceId;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- context = getContext();
- serverUrl = "http://ly.count.android.sdk.test.count.ly";
- appKey = "appkey";
- deviceId = "1234";
- mUninitedSeeds = new Seeds();
- mSeeds = new Seeds();
- mockEventQueue = mock(EventQueue.class);
- mockConnectionQueue = mock(ConnectionQueue.class);
- final CountlyStore countlyStore = new CountlyStore(context);
- countlyStore.clear();
-
- mSeeds.init(context, null, null, serverUrl, appKey, deviceId);
- mockConnectionQueue.setContext(context);
- mockConnectionQueue.setAppKey("123456");
- mockConnectionQueue.setServerURL(serverUrl);
- mockConnectionQueue.setCountlyStore(mock(CountlyStore.class));
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testConstructor() {
- assertNotNull(mUninitedSeeds.getConnectionQueue());
- assertNull(mUninitedSeeds.getConnectionQueue().getContext());
- assertNull(mUninitedSeeds.getConnectionQueue().getServerURL());
- assertNull(mUninitedSeeds.getConnectionQueue().getAppKey());
- assertNull(mUninitedSeeds.getConnectionQueue().getCountlyStore());
- assertNotNull(mUninitedSeeds.getTimerService());
- assertNull(mUninitedSeeds.getEventQueue());
- assertEquals(0, mUninitedSeeds.getActivityCount());
- assertEquals(0, mUninitedSeeds.getPrevSessionDurationStartTime());
- assertFalse(mUninitedSeeds.getDisableUpdateSessionRequests());
- assertFalse(mUninitedSeeds.isLoggingEnabled());
- }
-
- public void testSharedInstance() {
- Seeds sharedSeeds = Seeds.sharedInstance();
- assertNotNull(sharedSeeds);
- assertSame(sharedSeeds, Seeds.sharedInstance());
- }
-
- public void testInitWithNoDeviceID() {
- mUninitedSeeds = spy(mUninitedSeeds);
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, null);
- verify(mUninitedSeeds).init(context, null, null, serverUrl, appKey, null);
- }
-
- public void testInit_nullContext() {
- try {
- mUninitedSeeds.init(null, null, null, serverUrl, appKey, deviceId);
- fail("expected null context to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_nullServerURL() {
- try {
- mUninitedSeeds.init(context, null, null, appKey, deviceId);
- fail("expected null server URL to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_emptyServerURL() {
- try {
- mUninitedSeeds.init(context, null, null, "", appKey, deviceId);
- fail("expected empty server URL to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_invalidServerURL() {
- try {
- mUninitedSeeds.init(context, null, null, "not-a-valid-server-url", appKey, deviceId);
- fail("expected invalid server URL to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_nullAppKey() {
- try {
- mUninitedSeeds.init(context, null, null, serverUrl, null, deviceId);
- fail("expected null app key to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_emptyAppKey() {
- try {
- mUninitedSeeds.init(context, null, null, serverUrl, "", deviceId);
- fail("expected empty app key to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_nullDeviceID() {
- // null device ID is okay because it tells Seeds to use OpenUDID
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, null);
- }
-
- public void testInit_emptyDeviceID() {
- try {
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, "");
- fail("expected empty device ID to throw IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {
- // success!
- }
- }
-
- public void testInit_twiceWithSameParams() {
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, deviceId);
-
- final EventQueue expectedEventQueue = mUninitedSeeds.getEventQueue();
- final ConnectionQueue expectedConnectionQueue = mUninitedSeeds.getConnectionQueue();
- final CountlyStore expectedCountlyStore = expectedConnectionQueue.getCountlyStore();
- assertNotNull(expectedEventQueue);
- assertNotNull(expectedConnectionQueue);
- assertNotNull(expectedCountlyStore);
-
- // second call with same params should succeed, no exception thrown
- mUninitedSeeds.init(getContext(), null, null, serverUrl, appKey, deviceId);
-
- assertSame(expectedEventQueue, mUninitedSeeds.getEventQueue());
- assertSame(expectedConnectionQueue, mUninitedSeeds.getConnectionQueue());
- assertSame(expectedCountlyStore, mUninitedSeeds.getConnectionQueue().getCountlyStore());
- assertSame(context, mUninitedSeeds.getConnectionQueue().getContext());
- assertEquals(serverUrl, mUninitedSeeds.getConnectionQueue().getServerURL());
- assertEquals(appKey, mUninitedSeeds.getConnectionQueue().getAppKey());
- assertSame(mUninitedSeeds.getConnectionQueue().getCountlyStore(), mUninitedSeeds.getEventQueue().getCountlyStore());
- }
-
- public void testInit_twiceWithDifferentContext() {
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, deviceId);
- // changing context is okay since SharedPrefs are global singletons
- try {
- mUninitedSeeds.init(mock(Context.class), null, null, serverUrl, appKey, deviceId);
- } catch (Exception e) {
- //success!
- }
- }
-
- public void testInit_twiceWithDifferentServerURL() {
- mUninitedSeeds.init(context, null, null, "http://test1.count.ly", appKey, deviceId);
- try {
- mUninitedSeeds.init(context, null, null, "http://test2.count.ly", appKey, deviceId);
- fail("expected IllegalStateException to be thrown when calling init a second time with different serverURL");
- }
- catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testInit_twiceWithDifferentAppKey() {
- mUninitedSeeds.init(context, null, null, serverUrl, "appkey1", deviceId);
- try {
- mUninitedSeeds.init(context, null, null, serverUrl, "appkey2", deviceId);
- fail("expected IllegalStateException to be thrown when calling init a second time with different serverURL");
- }
- catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testInit_twiceWithDifferentDeviceID() {
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, deviceId);
- try {
- mUninitedSeeds.init(context, null, null, serverUrl, appKey, "4321");
- fail("expected IllegalStateException to be thrown when calling init a second time with different serverURL");
- }
- catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testInit_normal() {
- mUninitedSeeds.init(getContext(), null, null, serverUrl, appKey, deviceId);
-
- assertSame(getContext(), mUninitedSeeds.getConnectionQueue().getContext());
- assertEquals(serverUrl, mUninitedSeeds.getConnectionQueue().getServerURL());
- assertEquals(appKey, mUninitedSeeds.getConnectionQueue().getAppKey());
- assertNotNull(mUninitedSeeds.getConnectionQueue().getCountlyStore());
- assertNotNull(mUninitedSeeds.getEventQueue());
- assertSame(mUninitedSeeds.getConnectionQueue().getCountlyStore(), mUninitedSeeds.getEventQueue().getCountlyStore());
- }
-
- public void testHalt_notInitialized() {
- mUninitedSeeds.halt();
- assertNotNull(mUninitedSeeds.getConnectionQueue());
- assertNull(mUninitedSeeds.getConnectionQueue().getContext());
- assertNull(mUninitedSeeds.getConnectionQueue().getServerURL());
- assertNull(mUninitedSeeds.getConnectionQueue().getAppKey());
- assertNull(mUninitedSeeds.getConnectionQueue().getCountlyStore());
- assertNotNull(mUninitedSeeds.getTimerService());
- assertNull(mUninitedSeeds.getEventQueue());
- assertEquals(0, mUninitedSeeds.getActivityCount());
- assertEquals(0, mUninitedSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testHalt() {
- final CountlyStore mockCountlyStore = mock(CountlyStore.class);
- mSeeds.getConnectionQueue().setCountlyStore(mockCountlyStore);
- mSeeds.onStart();
- assertTrue(0 != mSeeds.getPrevSessionDurationStartTime());
- assertTrue(0 != mSeeds.getActivityCount());
- assertNotNull(mSeeds.getEventQueue());
- assertNotNull(mSeeds.getConnectionQueue().getContext());
- assertNotNull(mSeeds.getConnectionQueue().getServerURL());
- assertNotNull(mSeeds.getConnectionQueue().getAppKey());
- assertNotNull(mSeeds.getConnectionQueue().getContext());
-
- mSeeds.halt();
-
- assertNotNull(mSeeds.getConnectionQueue());
- assertNull(mSeeds.getConnectionQueue().getContext());
- assertNull(mSeeds.getConnectionQueue().getServerURL());
- assertNull(mSeeds.getConnectionQueue().getAppKey());
- assertNull(mSeeds.getConnectionQueue().getCountlyStore());
- assertNotNull(mSeeds.getTimerService());
- assertNull(mSeeds.getEventQueue());
- assertEquals(0, mSeeds.getActivityCount());
- assertEquals(0, mSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testOnStart_initNotCalled() {
- try {
- mUninitedSeeds.onStart();
- fail("expected calling onStart before init to throw IllegalStateException");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testOnStart_firstCall() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.onStart();
-
- assertEquals(1, mSeeds.getActivityCount());
- final long prevSessionDurationStartTime = mSeeds.getPrevSessionDurationStartTime();
- assertTrue(prevSessionDurationStartTime > 0);
- assertTrue(prevSessionDurationStartTime <= System.nanoTime());
- }
-
- public void testOnStart_subsequentCall() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.onStart(); // first call to onStart
- final long prevSessionDurationStartTime = mSeeds.getPrevSessionDurationStartTime();
- mSeeds.onStart(); // second call to onStart
-
- assertEquals(2, mSeeds.getActivityCount());
- assertEquals(prevSessionDurationStartTime, mSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testOnStop_initNotCalled() {
- try {
- mUninitedSeeds.onStop();
- fail("expected calling onStop before init to throw IllegalStateException");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testOnStop_unbalanced() {
- try {
- mSeeds.onStop();
- fail("expected calling onStop before init to throw IllegalStateException");
- } catch (IllegalStateException ignored) {
- // success!
- }
- }
-
- public void testOnStop_reallyStopping_emptyEventQueue() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.onStart();
- mSeeds.onStop();
-
- assertEquals(0, mSeeds.getActivityCount());
- assertEquals(0, mSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testOnStop_reallyStopping_nonEmptyEventQueue() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onStart();
- mSeeds.onStop();
-
- assertEquals(0, mSeeds.getActivityCount());
- assertEquals(0, mSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testOnStop_notStopping() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
-
- mSeeds.onStart();
- mSeeds.onStart();
- final long prevSessionDurationStartTime = mSeeds.getPrevSessionDurationStartTime();
- mSeeds.onStop();
-
- assertEquals(1, mSeeds.getActivityCount());
- assertEquals(prevSessionDurationStartTime, mSeeds.getPrevSessionDurationStartTime());
- }
-
- public void testRecordEvent_keyOnly() {
- eventKey = "eventKey";
- final Seeds seeds = spy(mSeeds);
- doNothing().when(seeds).recordEvent(eventKey, null, 1, 0.0d);
- seeds.recordEvent(eventKey);
- }
-
- public void testRecordEvent_keyAndCount() {
- eventKey = "eventKey";
- final int count = 42;
- final Seeds seeds = spy(mSeeds);
- doNothing().when(seeds).recordEvent(eventKey, null, count, 0.0d);
- seeds.recordEvent(eventKey, count);
- }
-
- public void testRecordEvent_keyAndCountAndSum() {
- eventKey = "eventKey";
- final int count = 42;
- final double sum = 3.0d;
- final Seeds seeds = spy(mSeeds);
- doNothing().when(seeds).recordEvent(eventKey, null, count, sum);
- seeds.recordEvent(eventKey, count, sum);
- }
-
- public void testRecordEvent_keyAndSegmentationAndCount() {
- eventKey = "eventKey";
- final int count = 42;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
- final Seeds seeds = spy(mSeeds);
- doNothing().when(seeds).recordEvent(eventKey, segmentation, count, 0.0d);
- seeds.recordEvent(eventKey, segmentation, count);
- }
-
- public void testRecordEvent_initNotCalled() {
- eventKey = "eventKey";
- final int count = 42;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- try {
- mUninitedSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalStateException when recordEvent called before init");
- } catch (IllegalStateException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_nullKey() {
- eventKey = null;
- final int count = 42;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- try {
- //noinspection ConstantConditions
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with null key");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_emptyKey() {
- eventKey = "";
- final int count = 42;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with empty key");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_countIsZero() {
- eventKey = "";
- final int count = 0;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with count=0");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_countIsNegative() {
- eventKey = "";
- final int count = -1;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with a negative count");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_segmentationHasNullKey() {
- eventKey = "";
- final int count = 1;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put(null, "segvalue1");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with segmentation with null key");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_segmentationHasEmptyKey() {
- eventKey = "";
- final int count = 1;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("", "segvalue1");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with segmentation with empty key");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_segmentationHasNullValue() {
- eventKey = "";
- final int count = 1;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", null);
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with segmentation with null value");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent_segmentationHasEmptyValue() {
- eventKey = "";
- final int count = 1;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "");
-
- try {
- mSeeds.recordEvent(eventKey, segmentation, count, sum);
- fail("expected IllegalArgumentException when recordEvent called with segmentation with empty value");
- } catch (IllegalArgumentException ignored) {
- // success
- }
- }
-
- public void testRecordEvent() {
- eventKey = "eventKey";
- final int count = 42;
- final double sum = 3.0d;
- final HashMap segmentation = new HashMap<>(1);
- segmentation.put("segkey1", "segvalue1");
-
- mSeeds.setEventQueue(mockEventQueue);
-
- final Seeds seeds = spy(mSeeds);
- doNothing().when(seeds).sendEventsIfNeeded();
- seeds.recordEvent(eventKey, segmentation, count, sum);
- }
-
- public void testSendEventsIfNeeded_emptyQueue() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.sendEventsIfNeeded();
- }
-
- public void testSendEventsIfNeeded_lessThanThreshold() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.sendEventsIfNeeded();
- }
-
- public void testSendEventsIfNeeded_equalToThreshold() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.sendEventsIfNeeded();
- }
-
- public void testSendEventsIfNeeded_moreThanThreshold() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.sendEventsIfNeeded();
- }
-
- public void testOnTimer_noActiveSession() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onTimer();
- }
-
- public void testOnTimer_activeSession_emptyEventQueue() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onStart();
- mSeeds.onTimer();
- }
-
- public void testOnTimer_activeSession_nonEmptyEventQueue() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onStart();
- mSeeds.onTimer();
- }
-
- public void testOnTimer_activeSession_emptyEventQueue_sessionTimeUpdatesDisabled() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setDisableUpdateSessionRequests(true);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onStart();
- mSeeds.onTimer();
- }
-
- public void testOnTimer_activeSession_nonEmptyEventQueue_sessionTimeUpdatesDisabled() {
- mSeeds.setConnectionQueue(mockConnectionQueue);
- mSeeds.setDisableUpdateSessionRequests(true);
- mSeeds.setEventQueue(mockEventQueue);
- mSeeds.onStart();
- mSeeds.onTimer();
- }
-
- public void testRoundedSecondsSinceLastSessionDurationUpdate() {
- long prevSessionDurationStartTime = System.nanoTime() - 1000000000;
- mSeeds.setPrevSessionDurationStartTime(prevSessionDurationStartTime);
- assertEquals(1, mSeeds.roundedSecondsSinceLastSessionDurationUpdate());
-
- prevSessionDurationStartTime = System.nanoTime() - 2000000000;
- mSeeds.setPrevSessionDurationStartTime(prevSessionDurationStartTime);
- assertEquals(2, mSeeds.roundedSecondsSinceLastSessionDurationUpdate());
-
- prevSessionDurationStartTime = System.nanoTime() - 1600000000;
- mSeeds.setPrevSessionDurationStartTime(prevSessionDurationStartTime);
- assertEquals(2, mSeeds.roundedSecondsSinceLastSessionDurationUpdate());
-
- prevSessionDurationStartTime = System.nanoTime() - 1200000000;
- mSeeds.setPrevSessionDurationStartTime(prevSessionDurationStartTime);
- assertEquals(1, mSeeds.roundedSecondsSinceLastSessionDurationUpdate());
- }
-
- public void testIsValidURL_badURLs() {
- assertFalse(Seeds.isValidURL(null));
- assertFalse(Seeds.isValidURL(""));
- assertFalse(Seeds.isValidURL(" "));
- assertFalse(Seeds.isValidURL("blahblahblah.com"));
- }
-
- public void testIsValidURL_goodURL() {
- assertTrue(Seeds.isValidURL(serverUrl));
- }
-
- public void testCurrentTimestamp() {
- final int testTimestamp = (int) (System.currentTimeMillis() / 1000l);
- final int actualTimestamp = Seeds.currentTimestamp();
- assertTrue(((testTimestamp - 1) <= actualTimestamp) && ((testTimestamp + 1) >= actualTimestamp));
- }
-
- public void testSetDisableUpdateSessionRequests() {
- assertFalse(mSeeds.getDisableUpdateSessionRequests());
- mSeeds.setDisableUpdateSessionRequests(true);
- assertTrue(mSeeds.getDisableUpdateSessionRequests());
- mSeeds.setDisableUpdateSessionRequests(false);
- assertFalse(mSeeds.getDisableUpdateSessionRequests());
- }
-
- public void testLoggingFlag() {
- assertFalse(mUninitedSeeds.isLoggingEnabled());
- mUninitedSeeds.setLoggingEnabled(true);
- assertTrue(mUninitedSeeds.isLoggingEnabled());
- mUninitedSeeds.setLoggingEnabled(false);
- assertFalse(mUninitedSeeds.isLoggingEnabled());
- }
-}
\ No newline at end of file
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CrashDetailsTest.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CrashDetailsTest.java
deleted file mode 100644
index 37cfeafd7..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/CrashDetailsTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.playseeds.android.sdk;
-
-import android.test.AndroidTestCase;
-
-import java.util.HashMap;
-
-public class CrashDetailsTest extends AndroidTestCase {
-
- public void testAddLog() throws Exception {
- String record = "This is a new log";
- CrashDetails.addLog(record);
- String logs = CrashDetails.getLogs();
-
- assertEquals(record + "\n", logs);
- assertNotSame(record, logs);
- }
-
- public void testAddLog_WhenNullRecord() throws Exception {
- CrashDetails.addLog(null);
- String logs = CrashDetails.getLogs();
-
- assertNotSame(null, logs);
- assertNotNull(logs);
- }
-
- public void testSetCustomSegments() throws Exception {
- CrashDetails.setCustomSegments(new HashMap());
-
- assertNull(CrashDetails.getCustomSegments());
- }
-
- public void testGetManufacturer() throws Exception {
- assertNotNull(CrashDetails.getManufacturer());
- }
-
- public void testGetCpu() throws Exception {
- assertNotNull(CrashDetails.getCpu());
- }
-
- public void testGetOpenGL() throws Exception {
- assertNotNull(CrashDetails.getOpenGL(getContext()));
- }
-
- public void testGetRamCurrent() throws Exception {
- assertNotNull(CrashDetails.getRamCurrent(getContext()));
- }
-
- public void testRamTotal() throws Exception {
- assertNotNull(CrashDetails.getRamTotal());
- }
-
- public void testGetDiskCurrent() throws Exception {
- assertNotNull(CrashDetails.getDiskCurrent());
- }
-
- public void testGetDiskTotal() throws Exception {
- assertNotNull(CrashDetails.getDiskTotal());
- }
-
- public void testGetBatteryLevel() throws Exception {
- assertNotNull(CrashDetails.getBatteryLevel(getContext()));
- }
-
- public void testGetRunningTime() throws Exception {
- assertNotNull(CrashDetails.getRunningTime());
- }
-
- public void testGetOrientation() throws Exception {
- assertNotNull(CrashDetails.getOrientation(getContext()));
- }
-
- public void testIsRooted() throws Exception {
- assertNotNull(CrashDetails.isRooted());
- }
-
- public void testIsOnline() throws Exception {
- assertNotNull(CrashDetails.isOnline(getContext()));
- }
-
- public void testIsMuted() throws Exception {
- assertNotNull(CrashDetails.isMuted(getContext()));
- }
-
- public void testGetCrashData() throws Exception {
- assertNotNull(CrashDetails.getCrashData(getContext(), "Error message", false));
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceIdTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceIdTests.java
deleted file mode 100644
index abce65ed1..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceIdTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.playseeds.android.sdk;
-
-import android.test.AndroidTestCase;
-
-public class DeviceIdTests extends AndroidTestCase {
- DeviceId deviceId;
- DeviceId.Type deviceType;
- boolean exceptionThrown;
- String id;
-
- protected void setUp() throws Exception {
- exceptionThrown = false;
- id = "Nexus-XLR";
- deviceType = null;
- }
-
- public void testDeviceIdConstructor_WhenNullParameter() throws Exception {
- try {
- deviceId = new DeviceId(deviceType);
- } catch (IllegalStateException e) {
- exceptionThrown = true;
- }
-
- assertTrue(exceptionThrown);
- }
-
- public void testDeviceIdConstructor_WhenTypeIsDeveloperSupplied() throws Exception {
- deviceType = DeviceId.Type.DEVELOPER_SUPPLIED;
-
- try {
- deviceId = new DeviceId(deviceType);
- } catch (IllegalStateException e) {
- exceptionThrown = true;
- }
-
- assertTrue(exceptionThrown);
- }
-
- public void testDeviceIdConstructor_WhenDeveloperSuppliedIsEmpty() throws Exception {
- id = "";
-
- try {
- deviceId = new DeviceId(id);
- } catch (IllegalStateException e) {
- exceptionThrown= true;
- }
-
- assertTrue(exceptionThrown);
- }
-
- public void testDeviceIdConstructor_WhenDeveloperSupplied() throws Exception {
- try {
- deviceId = new DeviceId(id);
- } catch(IllegalStateException e) {
- exceptionThrown = true;
- }
-
- assertFalse(exceptionThrown);
- }
-
- public void testDeviceIdEqualsNullSafe() throws Exception {
- deviceType = DeviceId.Type.ADVERTISING_ID;
-
- assertTrue(DeviceId.deviceIDEqualsNullSafe(id, deviceType, new DeviceId(deviceType)));
- }
-
- public void testDeviceIdEqualsNullSafe_WhenIdIsNull() throws Exception {
- deviceType = DeviceId.Type.ADVERTISING_ID;
-
- assertTrue(DeviceId.deviceIDEqualsNullSafe(null, deviceType, new DeviceId(deviceType)));
- }
-
- public void testDeviceIdEqualsNullSafe_WhenTypeIsNull() throws Exception {
- assertFalse(DeviceId.deviceIDEqualsNullSafe(id, deviceType, new DeviceId(DeviceId.Type.OPEN_UDID)));
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceInfoTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceInfoTests.java
deleted file mode 100755
index d76f924ab..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/DeviceInfoTests.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.telephony.TelephonyManager;
-import android.test.AndroidTestCase;
-import android.util.DisplayMetrics;
-import android.view.WindowManager;
-
-import junit.framework.Assert;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Locale;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class DeviceInfoTests extends AndroidTestCase {
- Context mockContext;
-
- protected void setUp() throws Exception {
- mockContext = mock(Context.class);
- }
-
- public void testGetOS() {
- Assert.assertEquals("Android", DeviceInfo.getOS());
- }
-
- public void testGetOSVersion() {
- assertEquals(android.os.Build.VERSION.RELEASE, DeviceInfo.getOSVersion());
- }
-
- public void testGetDevice() {
- assertEquals(android.os.Build.MODEL, DeviceInfo.getDevice());
- }
-
- public void testGetResolution() {
- final DisplayMetrics metrics = new DisplayMetrics();
- ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
- final String expected = metrics.widthPixels + "x" + metrics.heightPixels;
- assertEquals(expected, DeviceInfo.getResolution(getContext()));
- }
-
- public void testGetResolution_getWindowManagerReturnsNull() {
- when(mockContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(null);
- assertEquals("", DeviceInfo.getResolution(mockContext));
- }
-
- public void testGetResolution_getDefaultDisplayReturnsNull() {
- final WindowManager mockWindowMgr = mock(WindowManager.class);
-
- when(mockWindowMgr.getDefaultDisplay()).thenReturn(null);
- when(mockContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mockWindowMgr);
- assertEquals("", DeviceInfo.getResolution(mockContext));
- }
-
- private Context mockContextForTestingDensity(final int density) {
- final DisplayMetrics metrics = new DisplayMetrics();
- final Resources mockResources = mock(Resources.class);
- metrics.densityDpi = density;
-
- when(mockResources.getDisplayMetrics()).thenReturn(metrics);
- when(mockContext.getResources()).thenReturn(mockResources);
- return mockContext;
- }
-
- public void testGetDensity() {
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_LOW);
- assertEquals("LDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_MEDIUM);
- assertEquals("MDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_TV);
- assertEquals("TVDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_HIGH);
- assertEquals("HDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XHIGH);
- assertEquals("XHDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XXHIGH);
- assertEquals("XXHDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XXXHIGH);
- assertEquals("XXXHDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_400);
- assertEquals("XMHDPI", DeviceInfo.getDensity(mockContext));
- mockContext = mockContextForTestingDensity(0);
- assertEquals("", DeviceInfo.getDensity(mockContext));
- }
-
- public void testGetCarrier_nullTelephonyManager() {
- when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(null);
- assertEquals("", DeviceInfo.getCarrier(mockContext));
- }
-
- public void testGetCarrier_nullNetOperator() {
- final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
-
- when(mockTelephonyManager.getNetworkOperatorName()).thenReturn(null);
- when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
- assertEquals("", DeviceInfo.getCarrier(mockContext));
- }
-
- public void testGetCarrier_emptyNetOperator() {
- final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
-
- when(mockTelephonyManager.getNetworkOperatorName()).thenReturn("");
- when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
- assertEquals("", DeviceInfo.getCarrier(mockContext));
- }
-
- public void testGetCarrier() {
- final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
-
- when(mockTelephonyManager.getNetworkOperatorName()).thenReturn("Verizon");
- when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
- assertEquals("Verizon", DeviceInfo.getCarrier(mockContext));
- }
-
- public void testGetLocale() {
- final Locale defaultLocale = Locale.getDefault();
- try {
- Locale.setDefault(new Locale("ab", "CD"));
- assertEquals("ab_CD", DeviceInfo.getLocale());
- } finally {
- Locale.setDefault(defaultLocale);
- }
- }
-
- public void testGetAppVersion() throws PackageManager.NameNotFoundException {
- final PackageInfo pkgInfo = new PackageInfo();
- final String fakePkgName = "i.like.chicken";
- final PackageManager mockPkgMgr = mock(PackageManager.class);
- pkgInfo.versionName = "42.0";
-
- when(mockPkgMgr.getPackageInfo(fakePkgName, 0)).thenReturn(pkgInfo);
- when(mockContext.getPackageName()).thenReturn(fakePkgName);
- when(mockContext.getPackageManager()).thenReturn(mockPkgMgr);
- assertEquals("42.0", DeviceInfo.getAppVersion(mockContext));
- }
-
- public void testGetAppVersion_pkgManagerThrows() throws PackageManager.NameNotFoundException {
- final String fakePkgName = "i.like.chicken";
- final PackageManager mockPkgMgr = mock(PackageManager.class);
-
- when(mockPkgMgr.getPackageInfo(fakePkgName, 0)).thenThrow(new PackageManager.NameNotFoundException());
- when(mockContext.getPackageName()).thenReturn(fakePkgName);
- when(mockContext.getPackageManager()).thenReturn(mockPkgMgr);
- assertEquals("1.0", DeviceInfo.getAppVersion(mockContext));
- }
-
- public void testGetMetrics() throws UnsupportedEncodingException, JSONException {
- final JSONObject json = new JSONObject();
- final String expected = URLEncoder.encode(json.toString(), "UTF-8");
-
- json.put("_device", DeviceInfo.getDevice());
- json.put("_os", DeviceInfo.getOS());
- json.put("_os_version", DeviceInfo.getOSVersion());
- if (!"".equals(DeviceInfo.getCarrier(getContext()))) { // ensure tests pass on non-cellular devices
- json.put("_carrier", DeviceInfo.getCarrier(getContext()));
- }
- json.put("_resolution", DeviceInfo.getResolution(getContext()));
- json.put("_density", DeviceInfo.getDensity(getContext()));
- json.put("_locale", DeviceInfo.getLocale());
- json.put("_app_version", DeviceInfo.getAppVersion(getContext()));
- assertNotNull(expected);
- }
-
- public void testFillJSONIfValuesNotEmpty_noValues() {
- final JSONObject mockJSON = mock(JSONObject.class);
-
- DeviceInfo.fillJSONIfValuesNotEmpty(mockJSON);
- verifyZeroInteractions(mockJSON);
- }
-
- public void testFillJSONIfValuesNotEmpty_oddNumberOfValues() {
- final JSONObject mockJSON = mock(JSONObject.class);
-
- DeviceInfo.fillJSONIfValuesNotEmpty(mockJSON, "key1", "value1", "key2");
- verifyZeroInteractions(mockJSON);
- }
-
- public void testFillJSONIfValuesNotEmpty() throws JSONException {
- final JSONObject json = new JSONObject();
-
- DeviceInfo.fillJSONIfValuesNotEmpty(json, "key1", "value1", "key2", null, "key3", "value3", "key4", "", "key5", "value5");
- assertEquals("value1", json.get("key1"));
- assertFalse(json.has("key2"));
- assertEquals("value3", json.get("key3"));
- assertFalse(json.has("key4"));
- assertEquals("value5", json.get("key5"));
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventQueueTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventQueueTests.java
deleted file mode 100755
index a9f247b83..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventQueueTests.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.test.AndroidTestCase;
-
-import org.mockito.ArgumentCaptor;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class EventQueueTests extends AndroidTestCase {
- EventQueue mEventQueue;
- CountlyStore mMockCountlyStore;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- mMockCountlyStore = mock(CountlyStore.class);
- mEventQueue = new EventQueue(mMockCountlyStore);
- }
-
- public void testConstructor() {
- assertSame(mMockCountlyStore, mEventQueue.getCountlyStore());
- }
-
- public void testRecordEvent() {
- final String eventKey = "eventKey";
- final int count = 42;
- final double sum = 3.0d;
- final Map segmentation = new HashMap<>(1);
- final int timestamp = Seeds.currentTimestamp();
- final ArgumentCaptor arg = ArgumentCaptor.forClass(Integer.class);
-
- mEventQueue.recordEvent(eventKey, segmentation, count, sum);
- verify(mMockCountlyStore).addEvent(eq(eventKey), eq(segmentation), arg.capture(), eq(count), eq(sum));
- assertTrue(((timestamp - 1) <= arg.getValue()) && ((timestamp + 1) >= arg.getValue()));
- }
-
- public void testSize_zeroLenArray() {
- when(mMockCountlyStore.events()).thenReturn(new String[0]);
- assertEquals(0, mEventQueue.size());
- }
-
- public void testSize() {
- when(mMockCountlyStore.events()).thenReturn(new String[2]);
- assertEquals(2, mEventQueue.size());
- }
-
- public void testEvents_emptyList() throws UnsupportedEncodingException {
- final List eventsList = new ArrayList<>();
- when(mMockCountlyStore.eventsList()).thenReturn(eventsList);
-
- final String expected = URLEncoder.encode("[]", "UTF-8");
- assertEquals(expected, mEventQueue.events());
- verify(mMockCountlyStore).eventsList();
- verify(mMockCountlyStore).removeEvents(eventsList);
- }
-
- public void testEvents_nonEmptyList() throws UnsupportedEncodingException {
- final List eventsList = new ArrayList<>();
- final Event event1 = new Event();
- event1.key = "event1Key";
- eventsList.add(event1);
- final Event event2 = new Event();
- event2.key = "event2Key";
- eventsList.add(event2);
- when(mMockCountlyStore.eventsList()).thenReturn(eventsList);
-
- final String jsonToEncode = "[" + event1.toJSON().toString() + "," + event2.toJSON().toString() + "]";
- final String expected = URLEncoder.encode(jsonToEncode, "UTF-8");
- assertEquals(expected, mEventQueue.events());
- verify(mMockCountlyStore).eventsList();
- verify(mMockCountlyStore).removeEvents(eventsList);
- }
-}
diff --git a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventTests.java b/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventTests.java
deleted file mode 100755
index 778accd5d..000000000
--- a/seeds-sdk/src/androidTest/java/com/playseeds/android/sdk/EventTests.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
-Copyright (c) 2012, 2013, 2014 Countly
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-package com.playseeds.android.sdk;
-
-import android.test.AndroidTestCase;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.playseeds.android.sdk.Event;
-
-public class EventTests extends AndroidTestCase {
- public void testConstructor() {
- final Event event = new Event();
- assertNull(event.key);
- assertNull(event.segmentation);
- assertEquals(0, event.count);
- assertEquals(0, event.timestamp);
- assertEquals(0.0d, event.sum);
- }
-
- public void testEqualsAndHashCode() {
- final Event event1 = new Event();
- final Event event2 = new Event();
- assertFalse(event1.equals(null));
- assertFalse(event1.equals(new Object()));
- assertTrue(event1.equals(event2));
- assertEquals(event1.hashCode(), event2.hashCode());
-
- event1.key = "eventKey";
- assertFalse(event1.equals(event2));
- assertFalse(event2.equals(event1));
- assertTrue(event1.hashCode() != event2.hashCode());
-
- event2.key = "eventKey";
- assertTrue(event1.equals(event2));
- assertTrue(event2.equals(event1));
- assertEquals(event1.hashCode(), event2.hashCode());
-
- event1.timestamp = 1234;
- assertFalse(event1.equals(event2));
- assertFalse(event2.equals(event1));
- assertTrue(event1.hashCode() != event2.hashCode());
-
- event2.timestamp = 1234;
- assertTrue(event1.equals(event2));
- assertTrue(event2.equals(event1));
- assertEquals(event1.hashCode(), event2.hashCode());
-
- event1.segmentation = new HashMap<>();
- assertFalse(event1.equals(event2));
- assertFalse(event2.equals(event1));
- assertTrue(event1.hashCode() != event2.hashCode());
-
- event2.segmentation = new HashMap<>();
- assertTrue(event1.equals(event2));
- assertTrue(event2.equals(event1));
- assertEquals(event1.hashCode(), event2.hashCode());
-
- event1.segmentation.put("segkey", "segvalue");
- assertFalse(event1.equals(event2));
- assertFalse(event2.equals(event1));
- assertTrue(event1.hashCode() != event2.hashCode());
-
- event2.segmentation.put("segkey", "segvalue");
- assertTrue(event1.equals(event2));
- assertTrue(event2.equals(event1));
- assertEquals(event1.hashCode(), event2.hashCode());
-
- event1.sum = 3.2;
- event2.count = 42;
- assertTrue(event1.equals(event2));
- assertTrue(event2.equals(event1));
- assertEquals(event1.hashCode(), event2.hashCode());
- }
-
- public void testToJSON_nullSegmentation() throws JSONException {
- final Event event = new Event();
- event.key = "eventKey";
- event.timestamp = 1234;
- event.count = 42;
- event.sum = 3.2;
- final JSONObject jsonObj = event.toJSON();
- assertEquals(4, jsonObj.length());
- assertEquals(event.key, jsonObj.getString("key"));
- assertEquals(event.timestamp, jsonObj.getInt("timestamp"));
- assertEquals(event.count, jsonObj.getInt("count"));
- assertEquals(event.sum, jsonObj.getDouble("sum"));
- }
-
- public void testToJSON_emptySegmentation() throws JSONException {
- final Event event = new Event();
- event.key = "eventKey";
- event.timestamp = 1234;
- event.count = 42;
- event.sum = 3.2;
- event.segmentation = new HashMap<>();
- final JSONObject jsonObj = event.toJSON();
- assertEquals(5, jsonObj.length());
- assertEquals(event.key, jsonObj.getString("key"));
- assertEquals(event.timestamp, jsonObj.getInt("timestamp"));
- assertEquals(event.count, jsonObj.getInt("count"));
- assertEquals(event.sum, jsonObj.getDouble("sum"));
- assertEquals(0, jsonObj.getJSONObject("segmentation").length());
- }
-
- public void testToJSON_withSegmentation() throws JSONException {
- final Event event = new Event();
- event.key = "eventKey";
- event.timestamp = 1234;
- event.count = 42;
- event.sum = 3.2;
- event.segmentation = new HashMap<>();
- event.segmentation.put("segkey", "segvalue");
- final JSONObject jsonObj = event.toJSON();
- assertEquals(5, jsonObj.length());
- assertEquals(event.key, jsonObj.getString("key"));
- assertEquals(event.timestamp, jsonObj.getInt("timestamp"));
- assertEquals(event.count, jsonObj.getInt("count"));
- assertEquals(event.sum, jsonObj.getDouble("sum"));
- assertEquals(1, jsonObj.getJSONObject("segmentation").length());
- assertEquals(event.segmentation.get("segkey"), jsonObj.getJSONObject("segmentation").getString("segkey"));
- }
-
- public void testToJSON_sumNaNCausesJSONException() throws JSONException {
- final Event event = new Event();
- event.key = "eventKey";
- event.timestamp = 1234;
- event.count = 42;
- event.sum = Double.NaN;
- event.segmentation = new HashMap<>();
- event.segmentation.put("segkey", "segvalue");
- final JSONObject jsonObj = event.toJSON();
- assertEquals(4, jsonObj.length());
- assertEquals(event.key, jsonObj.getString("key"));
- assertEquals(event.timestamp, jsonObj.getInt("timestamp"));
- assertEquals(event.count, jsonObj.getInt("count"));
- assertEquals(1, jsonObj.getJSONObject("segmentation").length());
- assertEquals(event.segmentation.get("segkey"), jsonObj.getJSONObject("segmentation").getString("segkey"));
- }
-
- public void testFromJSON_nullJSONObj() {
- try {
- Event.fromJSON(null);
- fail("Expected NPE when calling Event.fromJSON with null");
- } catch (NullPointerException ignored) {
- // success
- }
- }
-
- public void testFromJSON_noKeyCausesJSONException() {
- final JSONObject jsonObj = new JSONObject();
- assertNull(Event.fromJSON(jsonObj));
- }
-
- public void testFromJSON_nullKey() throws JSONException {
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", JSONObject.NULL);
- assertNull(Event.fromJSON(jsonObj));
- }
-
- public void testFromJSON_emptyKey() throws JSONException {
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", "");
- assertNull(Event.fromJSON(jsonObj));
- }
-
- public void testFromJSON_keyOnly() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_keyOnly_nullOtherValues() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", JSONObject.NULL);
- jsonObj.put("count", JSONObject.NULL);
- jsonObj.put("sum", JSONObject.NULL);
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_noSegmentation() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", expected.timestamp);
- jsonObj.put("count", expected.count);
- jsonObj.put("sum", expected.sum);
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_nullSegmentation() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", expected.timestamp);
- jsonObj.put("count", expected.count);
- jsonObj.put("sum", expected.sum);
- jsonObj.put("segmentation", JSONObject.NULL);
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_segmentationNotADictionary() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", expected.timestamp);
- jsonObj.put("count", expected.count);
- jsonObj.put("sum", expected.sum);
- jsonObj.put("segmentation", 1234);
- assertNull(Event.fromJSON(jsonObj));
- }
-
- public void testFromJSON_emptySegmentation() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- expected.segmentation = new HashMap<>();
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", expected.timestamp);
- jsonObj.put("count", expected.count);
- jsonObj.put("sum", expected.sum);
- jsonObj.put("segmentation", new JSONObject(expected.segmentation));
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_withSegmentation() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- expected.segmentation = new HashMap<>();
- expected.segmentation.put("segkey", "segvalue");
- final JSONObject jsonObj = new JSONObject();
- jsonObj.put("key", expected.key);
- jsonObj.put("timestamp", expected.timestamp);
- jsonObj.put("count", expected.count);
- jsonObj.put("sum", expected.sum);
- jsonObj.put("segmentation", new JSONObject(expected.segmentation));
- final Event actual = Event.fromJSON(jsonObj);
- assertEquals(expected, actual);
- assertEquals(expected.count, actual.count);
- assertEquals(expected.sum, actual.sum);
- }
-
- public void testFromJSON_withSegmentation_nonStringValue() throws JSONException {
- final Event expected = new Event();
- expected.key = "eventKey";
- expected.timestamp = 1234;
- expected.count = 42;
- expected.sum = 3.2;
- expected.segmentation = new HashMap<>();
- expected.segmentation.put("segkey", "1234");
- final Map