Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ParseLoginUI/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ dependencies {
provided rootProject.ext.facebookSDK
provided files("$rootProject.projectDir/ParseLoginUI/libs/ParseFacebookUtilsV4-1.10.0.jar")
provided files("$rootProject.projectDir/ParseLoginUI/libs/ParseTwitterUtils-1.10.0.jar")

androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'org.skyscreamer:jsonassert:1.2.3'
}

android {
Expand Down
30 changes: 30 additions & 0 deletions ParseLoginUI/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2014, Parse, LLC. All rights reserved.
~
~ You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
~ copy, modify, and distribute this software in source code or binary form for use
~ in connection with the web services and APIs provided by Parse.
~
~ As with any software that integrates with the Parse platform, your use of
~ this software is subject to the Parse Terms of Service
~ [https://www.parse.com/about/terms]. This copyright 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.
-->

<manifest
package="com.parse.ui"
xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".TestActivity"
android:screenOrientation="portrait" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2014, Parse, LLC. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Parse.
*
* As with any software that integrates with the Parse platform, your use of
* this software is subject to the Parse Terms of Service
* [https://www.parse.com/about/terms]. This copyright 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.parse;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;

public abstract class BaseActivityInstrumentationTestCase2<T extends android.app.Activity>
extends ActivityInstrumentationTestCase2<T> {

protected Activity activity = null;

public BaseActivityInstrumentationTestCase2(Class<T> activityClass) {
super(activityClass);
}

@Override
protected void setUp() throws Exception {
super.setUp();

activity = getActivity();

Instrumentation instrumentation = this.getInstrumentation();
Context context = instrumentation.getTargetContext();
// Wait for the application context to exist (to avoid an Android bug)
// http://stackoverflow.com/questions/6516441/why-does-androidtestcase-getcontext-getapplicationcontext-return-null
while (context == null || context.getApplicationContext() == null) {
Thread.sleep(100);
context = instrumentation.getTargetContext();
}

// Work around a bug with Mockito and dexmaker on 4.3: https://code.google.com/p/dexmaker/issues/detail?id=2
System.setProperty("dexmaker.dexcache", context.getCacheDir().toString());
}

@Override
protected void tearDown() throws Exception {
activity = null;
super.tearDown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2014, Parse, LLC. All rights reserved.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
* copy, modify, and distribute this software in source code or binary form for use
* in connection with the web services and APIs provided by Parse.
*
* As with any software that integrates with the Parse platform, your use of
* this software is subject to the Parse Terms of Service
* [https://www.parse.com/about/terms]. This copyright 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.parse;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.test.InstrumentationTestCase;

import com.parse.ui.test.R;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;

public class ParseImageViewTest extends InstrumentationTestCase {

public void testParseImageViewWithNullParseFile() throws Exception {
final Drawable drawable = new ColorDrawable();
final ParseImageView imageView = new ParseImageView(getInstrumentation().getTargetContext());
imageView.setPlaceholder(drawable);
imageView.setParseFile(null);

byte[] data = ParseTaskUtils.wait(imageView.loadInBackground());

assertNull(data);
assertEquals(drawable, imageView.getDrawable());
}

public void testParseImageViewWithNotImageParseFile() throws Exception {
byte[] data = "hello".getBytes();
ParseFile file = new ParseFile(data);

final Drawable drawable = new ColorDrawable();
final ParseImageView imageView = new ParseImageView(getInstrumentation().getTargetContext());
imageView.setPlaceholder(drawable);
imageView.setParseFile(file);

byte[] dataAgain = ParseTaskUtils.wait(imageView.loadInBackground());

assertTrue(Arrays.equals(data, dataAgain));
// Since the parseFile can not be decode as an image, the getDrawable should not be changed
assertEquals(drawable, imageView.getDrawable());
}

public void testParseImageViewWithImageParseFile() throws Exception {
Context context = getInstrumentation().getTargetContext();
final Drawable iconImage = context.getResources().getDrawable(R.drawable.icon);
Bitmap iconBitmap = ((BitmapDrawable) iconImage).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
final byte[] imageData = stream.toByteArray();
ParseFile file = new ParseFile(imageData);

final Drawable drawable = new ColorDrawable();
final ParseImageView imageView = new ParseImageView(context);
imageView.setPlaceholder(drawable);
imageView.setParseFile(file);

byte[] dataAgain = ParseTaskUtils.wait(imageView.loadInBackground());

assertEquals(imageData, dataAgain);
assertNotNull(imageView.getDrawable());
// It is hard to assert whether the two images are equal or not, so we just verify the image has
// been changed
assertNotSame(drawable, imageView.getDrawable());
}
}


Loading