remove broken seeds tests

This commit is contained in:
Phillip Thelen 2017-02-23 11:47:48 +01:00
parent 5a65b3b96b
commit c6a691ef18
24 changed files with 0 additions and 3438 deletions

View file

@ -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) {
}
}
}

View file

@ -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();
}
}

View file

@ -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<String> 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<String, String> 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<String> 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<String, String> 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<String> 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<String, String> 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<String> 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<String, String> 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<String> 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<String, String> 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<String> 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<String, String> 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<String, String> parseQueryParams(final String queryStr) {
final String urlStr = "http://server?" + queryStr;
final Uri uri = Uri.parse(urlStr);
final Set<String> queryParameterNames = uri.getQueryParameterNames();
final Map<String, String> 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<Runnable> 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());
}
}

View file

@ -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<Event>(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<Event> expected = new ArrayList<Event>(1);
expected.add(event1);
final List<Event> 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<Event> expected = new ArrayList<Event>(3);
expected.add(event2);
expected.add(event3);
expected.add(event1);
final List<Event> 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<Event> expected = new ArrayList<Event>(2);
expected.add(event1);
expected.add(event2);
final List<Event> 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<Event> expected = new ArrayList<Event>(2);
expected.add(event1);
expected.add(event2);
final List<Event> 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<String, String>(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<Event> 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<Event> eventsToRemove = store.eventsList();
store.addEvent(event3.key, event3.segmentation, event3.timestamp, event3.count, event3.sum);
store.removeEvents(eventsToRemove);
final List<Event> 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"));
}
}

View file

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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());
}
}

View file

@ -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<String, String>());
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));
}
}

View file

@ -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)));
}
}

View file

@ -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"));
}
}

View file

@ -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<String, String> segmentation = new HashMap<>(1);
final int timestamp = Seeds.currentTimestamp();
final ArgumentCaptor<Integer> 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<Event> 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<Event> 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);
}
}

View file

@ -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<Object, Object> badMap = new HashMap<>();
badMap.put("segkey", 1234); // JSONObject.getString will end up converting this to the string "1234"
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(badMap));
final Event actual = Event.fromJSON(jsonObj);
assertEquals(expected, actual);
assertEquals(expected.count, actual.count);
assertEquals(expected.sum, actual.sum);
}
}

View file

@ -1,24 +0,0 @@
package com.playseeds.android.sdk;
import android.content.Context;
import android.test.AndroidTestCase;
public class MessagingAdapterTest extends AndroidTestCase {
public void testIsMessagingAvailable() throws Exception {
boolean isAvailable = MessagingAdapter.isMessagingAvailable();
assertNotNull(isAvailable);
}
public void testInit() throws Exception {
boolean isInit = MessagingAdapter.init(null, null, null, null);
assertFalse(isInit);
}
public void testStoreConfiguration() throws Exception {
Context context = getContext();
boolean config = MessagingAdapter.storeConfiguration(context,
"http://www.devdash.playseeds.com", "appkey", "id", DeviceId.Type.ADVERTISING_ID);
assertNotNull(config);
}
}

View file

@ -1,48 +0,0 @@
package com.playseeds.android.sdk;
import android.content.Context;
import android.content.Intent;
import android.test.AndroidTestCase;
public class ReferrerReceiverTest extends AndroidTestCase {
ReferrerReceiver receiver;
Context context;
public void setUp() throws Exception {
receiver = new ReferrerReceiver();
context = getContext();
}
public void testOnReceive() throws Exception {
Intent intent = new Intent();
intent.setAction("com.android.vending.INSTALL_REFERRER");
intent.putExtra("referrer", "testReferrer");
try {
receiver.onReceive(context, intent);
} catch (Exception e) {
}
}
public void testOnReceiveWhenNullIntent() throws Exception {
try {
receiver.onReceive(context, null);
} catch(Exception e) {
// success
}
}
public void testDeleteReferrer() throws Exception {
try {
ReferrerReceiver.deleteReferrer(context);
} catch(Exception e) {
//
}
}
public void testGetReferrer() throws Exception {
String referrer = ReferrerReceiver.getReferrer(context);
assertNull(referrer);
}
}

View file

@ -1,141 +0,0 @@
package com.playseeds.android.sdk;
import android.app.Activity;
import android.content.Context;
import android.test.AndroidTestCase;
import com.playseeds.android.sdk.inappmessaging.InAppMessageListener;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
public class SeedsTest extends AndroidTestCase {
Seeds seeds;
Seeds seedsSpy;
Context context;
ConnectionQueue mockQueue;
public void setUp() throws Exception {
seeds = Seeds.sharedInstance();
seedsSpy = spy(seeds);
context = getContext();
mockQueue = mock(ConnectionQueue.class);
ExecutorService mockService = mock(ExecutorService.class);
mockQueue.setContext(context);
mockQueue.setAppKey("fake key");
mockQueue.setServerURL("https://devdash.com");
mockQueue.setCountlyStore(mock(CountlyStore.class));
mockQueue.setExecutor(mockService);
}
public void testInitMessaging() throws Exception {
try {
seeds.initMessaging(new Activity(), testActivity.class, null, Seeds.CountlyMessagingMode.TEST);
fail("IllegalStateException expected!");
} catch(IllegalStateException e) {
// success
}
}
public void testInitMessaging_WhenNullMode() throws Exception {
try {
seeds.initMessaging(new Activity(), testActivity.class, null, null);
fail("IllegalStateException expected");
} catch(IllegalStateException e) {
// success
}
}
public void testOnRegistrationId() throws Exception {
seedsSpy.setConnectionQueue(mockQueue);
doCallRealMethod().when(seedsSpy).onRegistrationId("fake id");
seedsSpy.onRegistrationId("fake id");
verify(seedsSpy).onRegistrationId("fake id");
}
public void testTrackPurchase() throws Exception {
seedsSpy.init(context, null, mock(InAppMessageListener.class), "https://devdash.com", "fake key", "Nexus");
doCallRealMethod().when(seedsSpy).trackPurchase("fake key", 1.00);
seedsSpy.trackPurchase("fake key", 1.00);
verify(seedsSpy).trackPurchase("fake key", 1.00);
verify(seedsSpy).recordIAPEvent("fake key", 1.00);
}
public void testSetUserData() throws Exception {
Map<String, String> data = new HashMap<>();
doCallRealMethod().when(seedsSpy).setUserData(data, data);
seedsSpy.setConnectionQueue(mockQueue);
seedsSpy.setUserData(data, data);
verify(seedsSpy).setUserData(data, data);
}
public void testSetCustomUserData() throws Exception {
Map<String, String> data = new HashMap<>();
doCallRealMethod().when(seedsSpy).setCustomUserData(data);
seedsSpy.setConnectionQueue(mockQueue);
seedsSpy.setCustomUserData(data);
verify(seedsSpy).setCustomUserData(data);
}
public void testSetLocation() throws Exception {
doCallRealMethod().when(seedsSpy).setLocation(2.34, 3.45);
seedsSpy.setConnectionQueue(mockQueue);
seedsSpy.setLocation(2.34, 3.45);
verify(seedsSpy).setLocation(2.34, 3.45);
}
public void testCustomCrashSegments() throws Exception {
Map<String, String> data = new HashMap<>();
doCallRealMethod().when(seedsSpy).setCustomCrashSegments(data);
seedsSpy.setCustomCrashSegments(data);
verify(seedsSpy).setCustomCrashSegments(data);
}
public void testAddCrashLog() throws Exception {
doCallRealMethod().when(seedsSpy).addCrashLog("fake crash");
seedsSpy.addCrashLog("fake crash");
verify(seedsSpy).addCrashLog("fake crash");
}
public void testLogException() throws Exception {
Exception e = new Exception();
doCallRealMethod().when(seedsSpy).logException(e);
seedsSpy.setConnectionQueue(mockQueue);
seedsSpy.logException(e);
verify(seedsSpy).logException(e);
}
public void testLogExceptionWhenString() throws Exception {
doCallRealMethod().when(seedsSpy).logException("Exception");
seedsSpy.setConnectionQueue(mockQueue);
seedsSpy.logException("Exception");
verify(seedsSpy).logException("Exception");
}
public void testEnableCrashReporting() throws Exception {
doCallRealMethod().when(seedsSpy).enableCrashReporting();
seedsSpy.enableCrashReporting();
verify(seedsSpy).enableCrashReporting();
}
public class testActivity extends Activity {
}
}

View file

@ -1,93 +0,0 @@
package com.playseeds.android.sdk;
import android.test.AndroidTestCase;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import com.playseeds.android.sdk.UserData;
public class UserDataTests extends AndroidTestCase {
public void testSetData(){
HashMap<String, String> data = new HashMap<String, String>();
data.put("name", "Test Test");
data.put("username", "ly/count/android/sdk/test");
data.put("email", "ly.count.android.sdk.test@gmail.com");
data.put("organization", "Tester");
data.put("phone", "+1234567890");
data.put("gender", "M");
data.put("picture", "http://domain.com/ly.count.android.sdk.test.png");
data.put("byear", "2000");
UserData.setData(data);
assertEquals("Test Test", UserData.name);
assertEquals("ly/count/android/sdk/test", UserData.username);
assertEquals("ly.count.android.sdk.test@gmail.com", UserData.email);
assertEquals("Tester", UserData.org);
assertEquals("+1234567890", UserData.phone);
assertEquals("M", UserData.gender);
assertEquals("http://domain.com/ly.count.android.sdk.test.png", UserData.picture);
assertEquals(2000, UserData.byear);
}
public void testJSON() throws JSONException{
HashMap<String, String> data = new HashMap<String, String>();
data.put("name", "Test Test");
data.put("username", "ly/count/android/sdk/test");
data.put("email", "ly.count.android.sdk.test@gmail.com");
data.put("organization", "Tester");
data.put("phone", "+1234567890");
data.put("gender", "M");
data.put("picture", "http://domain.com/ly.count.android.sdk.test.png");
data.put("byear", "2000");
UserData.setData(data);
JSONObject json = UserData.toJSON();
assertEquals("Test Test", json.getString("name"));
assertEquals("ly/count/android/sdk/test", json.getString("username"));
assertEquals("ly.count.android.sdk.test@gmail.com", json.getString("email"));
assertEquals("Tester", json.getString("organization"));
assertEquals("+1234567890", json.getString("phone"));
assertEquals("M", json.getString("gender"));
assertEquals("http://domain.com/ly.count.android.sdk.test.png", json.getString("picture"));
assertEquals(2000, json.getInt("byear"));
}
public void testPicturePath() throws MalformedURLException{
String path = "http://ly.count.android.sdk.test.com/?key1=val1&picturePath=%2Fmnt%2Fsdcard%2Fpic.jpg&key2=val2";
String picturePath = UserData.getPicturePathFromQuery(new URL(path));
assertEquals("/mnt/sdcard/pic.jpg", picturePath);
}
public void testSetCustomData() throws Exception {
Map<String, String> data = new HashMap<>();
data.put("key", "data");
UserData.setCustomData(data);
assertNotNull(UserData.custom);
assertFalse(UserData.isSynced);
}
public void testGetDataForRequest() throws Exception {
String request = UserData.getDataForRequest();
assertTrue(UserData.isSynced);
assertSame("", request);
}
public void testGetDataForRequestWhenNotSynced() throws Exception {
UserData.setCustomData(new HashMap<String, String>());
String request = UserData.getDataForRequest();
assertTrue(UserData.isSynced);
assertNotNull(request);
}
}

View file

@ -1,20 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.test.AndroidTestCase;
public class GeneralInAppMessageProviderTest extends AndroidTestCase {
GeneralInAppMessageProvider generalInAppMessageProvider;
public void setUp() throws Exception {
generalInAppMessageProvider = new GeneralInAppMessageProvider();
}
public void testParseCountlyJsonWithNullValues() throws Exception {
try {
generalInAppMessageProvider.parseCountlyJSON(null, null);
fail("RequestException expected");
} catch (RequestException e) {
// success
}
}
}

View file

@ -1,101 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.content.Context;
import android.test.AndroidTestCase;
import com.playseeds.android.sdk.DeviceId;
import com.playseeds.android.sdk.Seeds;
import java.util.Date;
import java.util.HashMap;
public class InAppMessageManagerTest extends AndroidTestCase {
InAppMessageResponse inAppMessageResponse;
testInAppMessageListener inAppMessageListener;
HashMap<Long, InAppMessageManager> runningAds;
Long timeStamp;
String serverUrl;
Context context;
public void setUp() throws Exception {
timeStamp = new Date().getTime();
inAppMessageResponse = new InAppMessageResponse();
inAppMessageListener = new testInAppMessageListener();
runningAds = new HashMap<>();
context = getContext();
serverUrl = "http://devdash.playseeds.com";
inAppMessageResponse.setTimestamp(timeStamp);
runningAds.put(timeStamp, InAppMessageManager.sharedInstance());
InAppMessageManager.sharedInstance().setRunningAds(runningAds);
InAppMessageManager.sharedInstance().setListener(inAppMessageListener);
Seeds.sharedInstance().init(context, null, inAppMessageListener, serverUrl, "12345");
InAppMessageManager.sharedInstance().init(context, null, serverUrl, "c30f02a55541cbe362449d29d83d777c125c8dd6", "Nexus-XLR", DeviceId.Type.ADVERTISING_ID);
}
public void testNotifyInAppMessageClick() throws Exception {
InAppMessageManager.notifyInAppMessageClick(inAppMessageResponse);
synchronized (inAppMessageListener) {
inAppMessageListener.wait(1000);
}
assertTrue(inAppMessageListener.isClicked);
}
public void testCloseRunningInAppMessage() throws Exception {
InAppMessageManager.closeRunningInAppMessage(inAppMessageResponse);
synchronized (inAppMessageListener) {
inAppMessageListener.wait(1000);
}
assertTrue(inAppMessageListener.isClosed);
}
public void testRequestInAppMessage_WhenBadRequest() throws Exception {
InAppMessageManager.sharedInstance().init(context, null, "http://dev.playseeds.co", "1234", "Nexus-XLR", DeviceId.Type.ADVERTISING_ID);
InAppMessageManager.sharedInstance().requestInAppMessage(null);
synchronized (inAppMessageListener) {
inAppMessageListener.wait(50000);
}
assertTrue(inAppMessageListener.notFound);
}
public void testRequestInAppMessage() throws Exception {
InAppMessageManager.sharedInstance().requestInAppMessage(null);
synchronized (inAppMessageListener) {
inAppMessageListener.wait(10000);
}
assertTrue(inAppMessageListener.isLoadSucceeded);
}
private class testInAppMessageListener implements InAppMessageListener {
boolean isClicked = false;
boolean isClosed = false;
boolean isLoadSucceeded = false;
boolean isShown = false;
boolean notFound = false;
@Override
public void inAppMessageClicked(String messageId, InAppMessage inAppMessage) {
isClicked = true;
}
@Override
public void inAppMessageClosed(String messageId, InAppMessage inAppmessage, boolean completed) {
isClosed = true;
}
@Override
public void inAppMessageShown(String messageId, InAppMessage inAppMessage, boolean succeeded) {
isShown = true;
}
@Override
public void inAppMessageLoadSucceeded(String messageId, InAppMessage inAppMessage) {
isLoadSucceeded = true;
}
@Override
public void noInAppMessageFound(String messageId) {
notFound = true;
}
}
}

View file

@ -1,66 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.test.AndroidTestCase;
import com.playseeds.android.sdk.DeviceId;
import java.util.ArrayList;
import java.util.Date;
public class InAppMessageRequestTest extends AndroidTestCase {
public void testGettersAndSetters() throws Exception {
InAppMessageRequest request = new InAppMessageRequest();
long timeStamp = new Date().getTime();
request.setDeviceId("fake id");
request.setGender(Gender.FEMALE);
request.setUserAge(30);
request.setKeywords(new ArrayList<String>());
request.setIdMode(DeviceId.Type.ADVERTISING_ID);
request.setConnectionType("fake connection type");
request.setAdDoNotTrack(true);
request.setOrientation("landscape");
request.setHeaders("fake headers");
request.setIpAddress("fake address");
request.setLatitude(23.43);
request.setListAds("fake list ads");
request.setLongitude(34.34);
request.setProtocolVersion("fake protocol version");
request.setAppKey("fake app key");
request.setTimestamp(timeStamp);
request.setUserAgent("fake user agent");
request.setUserAgent2("fake user agent 2");
request.setRequestURL("fake Url");
request.setAdspaceStrict(true);
request.setAdspaceHeight(10);
request.setAdspaceWidth(10);
request.setAndroidAdId("fake android id");
assertSame("fake id", request.getDeviceId());
assertSame(Gender.FEMALE, request.getGender());
assertEquals(30, request.getUserAge());
assertNotNull(request.getKeywords());
assertSame(DeviceId.Type.ADVERTISING_ID, request.getIdMode());
assertSame("fake connection type", request.getConnectionType());
assertTrue(request.hasAdDoNotTrack());
assertSame("landscape", request.getOrientation());
assertSame("fake headers", request.getHeaders());
assertSame("fake address", request.getIpAddress());
assertEquals(23.43, request.getLatitude());
assertSame("fake list ads", request.getListAds());
assertEquals(34.34, request.getLongitude());
assertSame("fake protocol version", request.getProtocolVersion());
assertSame("fake app key", request.getAppKey());
assertEquals(timeStamp, request.getTimestamp());
assertSame("fake user agent", request.getUserAgent());
assertSame("fake user agent 2", request.getUserAgent2());
assertSame("fake Url", request.getRequestURL());
assertTrue(request.isAdspaceStrict());
assertEquals(10, request.getAdspaceHeight());
assertEquals(10, request.getAdspaceWidth());
assertSame("fake android id", request.getAndroidAdId());
assertNotNull(request.countlyUriToString());
assertNotNull(request.toCountlyUri());
}
}

View file

@ -1,59 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.test.AndroidTestCase;
import java.util.Date;
public class InAppMessageResponseTest extends AndroidTestCase {
public void testGettersAndSetters() throws Exception {
InAppMessageResponse response = new InAppMessageResponse();
long timeStamp = new Date().getTime();
response.setTimestamp(timeStamp);
response.setClickType(ClickType.BROWSER);
response.setBannerHeight(300);
response.setBannerWidth(300);
response.setClickUrl("fake url");
response.setImageUrl("fake image url");
response.setRefresh(60);
response.setScale(true);
response.setSkipPreflight(true);
response.setText("fake text");
response.setUrlType("fake url type");
response.setType(0);
response.setSkipOverlay(0);
response.setHorizontalOrientationRequested(true);
assertNotNull(response.getTimestamp());
assertNotNull(response.getClickType());
assertNotNull(response.getBannerHeight());
assertNotNull(response.getBannerWidth());
assertNotNull(response.getClickUrl());
assertNotNull(response.getImageUrl());
assertNotNull(response.getRefresh());
assertNotNull(response.isScale());
assertNotNull(response.isSkipPreflight());
assertNotNull(response.getText());
assertNotNull(response.getUrlType());
assertNotNull(response.getType());
assertNotNull(response.getSkipOverlay());
assertNotNull(response.isHorizontalOrientationRequested());
assertNotNull(response.getString());
assertEquals(response.getTimestamp(), timeStamp);
assertSame(ClickType.BROWSER, response.getClickType());
assertEquals(300, response.getBannerHeight());
assertEquals(300, response.getBannerWidth());
assertSame("fake url", response.getClickUrl());
assertSame("fake image url", response.getImageUrl());
assertEquals(60, response.getRefresh());
assertTrue(response.isScale());
assertTrue(response.isSkipPreflight());
assertSame("fake text", response.getText());
assertSame("fake url type", response.getUrlType());
assertEquals(0, response.getType());
assertEquals(0, response.getSkipOverlay());
assertTrue(response.isHorizontalOrientationRequested());
}
}

View file

@ -1,50 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.test.AndroidTestCase;
public class LogTest extends AndroidTestCase {
public void testIsLoggable() throws Exception {
assertTrue(Log.isLoggable(0));
}
public void testDebug() {
Log.d("random message");
}
public void testDebugThrowable() throws Exception {
Log.d("faker", new Throwable());
}
public void testError() throws Exception {
Log.e("error");
}
public void testErrorThrowable() throws Exception {
Log.e("error", new Throwable());
}
public void testInfo() throws Exception {
Log.i("Info");
}
public void testInfoThrowable() throws Exception {
Log.i("info", new Throwable());
}
public void testVerbose() throws Exception {
Log.v("verbose");
}
public void testVerboseThrowable() throws Exception {
Log.v("verbose", new Throwable());
}
public void testW() throws Exception {
Log.w("Www");
}
public void testWThrowable() throws Exception {
Log.w("www", new Throwable());
}
}

View file

@ -1,43 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.test.AndroidTestCase;
public class RequestExceptionTest extends AndroidTestCase {
public void testDefaultConstructor() throws Exception {
try {
throw new RequestException();
} catch (RequestException e) {
assertNull(e.getMessage());
assertNull(e.getCause());
}
}
public void testRequestException_WhenStringParameter() throws Exception {
try {
throw new RequestException("Request exception thrown");
} catch(RequestException e) {
assertNotNull(e.getMessage());
assertNull(e.getCause());
}
}
public void testRequestException_WhenStringAndThrowableParameter() throws Exception {
try {
throw new RequestException("Request exception thrown", new Throwable());
} catch(RequestException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
}
}
public void testRequestException_WhenThrowableParameter() throws Exception {
try {
throw new RequestException(new Throwable());
} catch(RequestException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
}
}
}

View file

@ -1,57 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.content.Context;
import android.test.AndroidTestCase;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
public class ResourceManagerTest extends AndroidTestCase {
ResourceManager resourceManager;
Context context;
public void setUp() throws Exception {
resourceManager = new ResourceManager();
context = getContext();
}
public void testReleaseInstance() throws Exception {
ResourceManager spyResourceManager = spy(resourceManager);
doCallRealMethod().when(spyResourceManager).releaseInstance();
spyResourceManager.releaseInstance();
verify(spyResourceManager).releaseInstance();
}
public void testIsDownloading() throws Exception {
assertFalse(ResourceManager.isDownloading());
}
public void testCancel() throws Exception {
ResourceManager.cancel();
assertTrue(resourceManager.getsResources().isEmpty());
}
public void testGetResource_WhenFakeResourceId() throws Exception {
assertNull(resourceManager.getResource(context, android.R.layout.simple_list_item_1));
}
public void testGetResource_WithDefaultCloseButtonId() throws Exception {
assertNotNull(resourceManager.getResource(context, -29));
}
public void testGetStaticResource_WhenFakeResourceId() throws Exception {
int id = android.R.layout.simple_list_item_1;
assertNull(ResourceManager.getStaticResource(context, id));
}
public void testGetStaticResource() throws Exception {
assertNotNull(ResourceManager.getStaticResource(context, -11));
}
public void testGetStaticResource_WithDefaultCloseButtonId() throws Exception {
assertNotNull(ResourceManager.getStaticResource(context, -29));
}
}

View file

@ -1,120 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.os.Message;
import android.test.AndroidTestCase;
import android.view.KeyEvent;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class RichMediaActivityTest extends AndroidTestCase {
RichMediaActivity mockRichMediaActivity;
InAppMessageResponse mockResponse;
RichMediaActivity spyActivity;
@Override
public void setUp() throws Exception {
super.setUp();
mockRichMediaActivity = mock(RichMediaActivity.class);
mockResponse = mock(InAppMessageResponse.class);
spyActivity = new RichMediaActivity();
spyActivity = spy(spyActivity);
}
public void testFinish() throws Exception {
doCallRealMethod().when(mockRichMediaActivity).finish();
mockRichMediaActivity.finish();
verify(mockRichMediaActivity).finish();
}
public void testOnKeyDown_WithMockMethod() throws Exception {
KeyEvent keyEvent = mock(KeyEvent.class);
boolean isKey;
when(mockRichMediaActivity.onKeyDown(23, keyEvent)).thenReturn(true);
isKey = mockRichMediaActivity.onKeyDown(23, keyEvent);
assertTrue(isKey);
verify(mockRichMediaActivity).onKeyDown(23, keyEvent);
when(mockRichMediaActivity.onKeyDown(24, keyEvent)).thenReturn(false);
isKey = mockRichMediaActivity.onKeyDown(24, keyEvent);
assertFalse(isKey);
verify(mockRichMediaActivity).onKeyDown(24, keyEvent);
}
public void testKeyDown_WithActualMethodCall() throws Exception {
KeyEvent keyEvent = mock(KeyEvent.class);
boolean isKey;
doCallRealMethod().when(mockRichMediaActivity).onKeyDown(keyEvent.KEYCODE_BACK, keyEvent);
isKey = mockRichMediaActivity.onKeyDown(keyEvent.KEYCODE_BACK, keyEvent);
assertTrue(isKey);
verify(mockRichMediaActivity).onKeyDown(keyEvent.KEYCODE_BACK, keyEvent);
verify(mockRichMediaActivity).goBack();
}
public void testOnResume() throws Exception {
doNothing().when(spyActivity).onResume();
spyActivity.onResume();
verify(spyActivity).onResume();
}
public void testOnDestroy() throws Exception {
doNothing().when(spyActivity).onDestroy();
spyActivity.onDestroy();
verify(spyActivity).onDestroy();
}
public void testClose() throws Exception {
doCallRealMethod().when(mockRichMediaActivity).close();
mockRichMediaActivity.close();
verify(mockRichMediaActivity).close();
verify(mockRichMediaActivity).finish();
}
public void testHandleMessage() throws Exception {
Message message = new Message();
doCallRealMethod().when(mockRichMediaActivity).handleMessage(message);
mockRichMediaActivity.handleMessage(message);
verify(mockRichMediaActivity).handleMessage(message);
}
public void testGoBack_WhenTypeBrowser() throws Exception {
doCallRealMethod().when(mockRichMediaActivity).goBack();
doCallRealMethod().when(mockRichMediaActivity).setTypeInterstitial(0);
mockRichMediaActivity.setTypeInterstitial(0);
mockRichMediaActivity.goBack();
verify(mockRichMediaActivity).goBack();
verify(mockRichMediaActivity).finish();
}
public void testGoBack_WhenTypeInterstitial() throws Exception {
doCallRealMethod().when(mockRichMediaActivity).goBack();
doCallRealMethod().when(mockRichMediaActivity).setTypeInterstitial(2);
mockRichMediaActivity.setTypeInterstitial(2);
mockRichMediaActivity.goBack();
verify(mockRichMediaActivity).goBack();
verify(mockRichMediaActivity).finish();
}
public void testOnCreate() throws Exception {
doNothing().when(spyActivity).onCreate(null);
spyActivity.onCreate(null);
verify(spyActivity).onCreate(null);
}
}

View file

@ -1,60 +0,0 @@
package com.playseeds.android.sdk.inappmessaging;
import android.content.Context;
import android.graphics.Bitmap;
import android.location.Location;
import android.test.AndroidTestCase;
public class UtilTest extends AndroidTestCase {
Context context;
public void setUp() throws Exception {
context = getContext();
}
public void testIsNetworkAvailable() throws Exception {
boolean isAvailable = Util.isNetworkAvailable(context);
assertNotNull(isAvailable);
assertTrue(isAvailable);
}
public void testGetConnectionType() throws Exception {
String connectionType = Util.getConnectionType(context);
assertNotNull(connectionType);
}
public void testGetLocalIpAddress() throws Exception {
String localIpAddress = Util.getLocalIpAddress();
assertNotNull(localIpAddress);
}
public void testGetLocation() throws Exception {
Location location = Util.getLocation(context);
assertNull(location);
}
public void testGetDefaultUserAgentString() throws Exception{
String userAgent = Util.getDefaultUserAgentString();
assertNotNull(userAgent);
}
public void testBuildUserAgent() throws Exception {
String userAgent = Util.buildUserAgent();
assertNotNull(userAgent);
}
public void testGetMemoryClass() throws Exception {
int memoryClass = Util.getMemoryClass(context);
assertNotNull(memoryClass);
}
public void testGetAndroidAdId() throws Exception {
String androidAdId = Util.getAndroidAdId();
assertNotNull(androidAdId);
}
public void testLoadBitMap() throws Exception {
Bitmap bitmap = Util.loadBitmap("http://devdash.playseeds.com");
assertNull(bitmap);
}
}

View file

@ -1,33 +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.test;
import android.os.Bundle;
public class InstrumentationTestRunner extends android.test.InstrumentationTestRunner {
// TODO: since Android 4.3 dexmaker requires this workaround, can be removed once dexmaker fixes this issue http://code.google.com/p/dexmaker/issues/detail?id=2
@Override
public void onCreate(Bundle arguments) {
super.onCreate(arguments);
System.setProperty("dexmaker.dexcache", getTargetContext().getCacheDir().toString());
}
}