Skip to content

Commit 653ec99

Browse files
committed
Add test target
1 parent 76886c0 commit 653ec99

File tree

9 files changed

+843
-0
lines changed

9 files changed

+843
-0
lines changed

ParseLoginUI/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ dependencies {
88
provided rootProject.ext.facebookSDK
99
provided files("$rootProject.projectDir/ParseLoginUI/libs/ParseFacebookUtilsV4-1.10.0.jar")
1010
provided files("$rootProject.projectDir/ParseLoginUI/libs/ParseTwitterUtils-1.10.0.jar")
11+
12+
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
13+
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
14+
androidTestCompile 'org.mockito:mockito-core:1.10.19'
15+
androidTestCompile 'org.skyscreamer:jsonassert:1.2.3'
1116
}
1217

1318
android {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2014, Parse, LLC. All rights reserved.
4+
~
5+
~ You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
6+
~ copy, modify, and distribute this software in source code or binary form for use
7+
~ in connection with the web services and APIs provided by Parse.
8+
~
9+
~ As with any software that integrates with the Parse platform, your use of
10+
~ this software is subject to the Parse Terms of Service
11+
~ [https://www.parse.com/about/terms]. This copyright notice shall be
12+
~ included in all copies or substantial portions of the software.
13+
~
14+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
~ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
~ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
~ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
-->
21+
22+
<manifest
23+
package="com.parse.ui"
24+
xmlns:android="http://schemas.android.com/apk/res/android">
25+
<application>
26+
<activity
27+
android:name=".TestActivity"
28+
android:screenOrientation="portrait" />
29+
</application>
30+
</manifest>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2014, Parse, LLC. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Parse.
7+
*
8+
* As with any software that integrates with the Parse platform, your use of
9+
* this software is subject to the Parse Terms of Service
10+
* [https://www.parse.com/about/terms]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*
20+
*/
21+
22+
package com.parse;
23+
24+
import android.app.Activity;
25+
import android.app.Instrumentation;
26+
import android.content.Context;
27+
import android.test.ActivityInstrumentationTestCase2;
28+
29+
public abstract class BaseActivityInstrumentationTestCase2<T extends android.app.Activity>
30+
extends ActivityInstrumentationTestCase2<T> {
31+
32+
protected Activity activity = null;
33+
34+
public BaseActivityInstrumentationTestCase2(Class<T> activityClass) {
35+
super(activityClass);
36+
}
37+
38+
@Override
39+
protected void setUp() throws Exception {
40+
super.setUp();
41+
42+
activity = getActivity();
43+
44+
Instrumentation instrumentation = this.getInstrumentation();
45+
Context context = instrumentation.getTargetContext();
46+
// Wait for the application context to exist (to avoid an Android bug)
47+
// http://stackoverflow.com/questions/6516441/why-does-androidtestcase-getcontext-getapplicationcontext-return-null
48+
while (context == null || context.getApplicationContext() == null) {
49+
Thread.sleep(100);
50+
context = instrumentation.getTargetContext();
51+
}
52+
53+
// Work around a bug with Mockito and dexmaker on 4.3: https://code.google.com/p/dexmaker/issues/detail?id=2
54+
System.setProperty("dexmaker.dexcache", context.getCacheDir().toString());
55+
}
56+
57+
@Override
58+
protected void tearDown() throws Exception {
59+
activity = null;
60+
super.tearDown();
61+
}
62+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2014, Parse, LLC. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Parse.
7+
*
8+
* As with any software that integrates with the Parse platform, your use of
9+
* this software is subject to the Parse Terms of Service
10+
* [https://www.parse.com/about/terms]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*
20+
*/
21+
22+
package com.parse;
23+
24+
import android.content.Context;
25+
import android.graphics.Bitmap;
26+
import android.graphics.drawable.BitmapDrawable;
27+
import android.graphics.drawable.ColorDrawable;
28+
import android.graphics.drawable.Drawable;
29+
import android.test.InstrumentationTestCase;
30+
31+
import com.parse.ui.test.R;
32+
33+
import java.io.ByteArrayOutputStream;
34+
import java.util.Arrays;
35+
36+
public class ParseImageViewTest extends InstrumentationTestCase {
37+
38+
public void testParseImageViewWithNullParseFile() throws Exception {
39+
final Drawable drawable = new ColorDrawable();
40+
final ParseImageView imageView = new ParseImageView(getInstrumentation().getTargetContext());
41+
imageView.setPlaceholder(drawable);
42+
imageView.setParseFile(null);
43+
44+
byte[] data = ParseTaskUtils.wait(imageView.loadInBackground());
45+
46+
assertNull(data);
47+
assertEquals(drawable, imageView.getDrawable());
48+
}
49+
50+
public void testParseImageViewWithNotImageParseFile() throws Exception {
51+
byte[] data = "hello".getBytes();
52+
ParseFile file = new ParseFile(data);
53+
54+
final Drawable drawable = new ColorDrawable();
55+
final ParseImageView imageView = new ParseImageView(getInstrumentation().getTargetContext());
56+
imageView.setPlaceholder(drawable);
57+
imageView.setParseFile(file);
58+
59+
byte[] dataAgain = ParseTaskUtils.wait(imageView.loadInBackground());
60+
61+
assertTrue(Arrays.equals(data, dataAgain));
62+
// Since the parseFile can not be decode as an image, the getDrawable should not be changed
63+
assertEquals(drawable, imageView.getDrawable());
64+
}
65+
66+
public void testParseImageViewWithImageParseFile() throws Exception {
67+
Context context = getInstrumentation().getTargetContext();
68+
final Drawable iconImage = context.getResources().getDrawable(R.drawable.icon);
69+
Bitmap iconBitmap = ((BitmapDrawable) iconImage).getBitmap();
70+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
71+
iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
72+
final byte[] imageData = stream.toByteArray();
73+
ParseFile file = new ParseFile(imageData);
74+
75+
final Drawable drawable = new ColorDrawable();
76+
final ParseImageView imageView = new ParseImageView(context);
77+
imageView.setPlaceholder(drawable);
78+
imageView.setParseFile(file);
79+
80+
byte[] dataAgain = ParseTaskUtils.wait(imageView.loadInBackground());
81+
82+
assertEquals(imageData, dataAgain);
83+
assertNotNull(imageView.getDrawable());
84+
// It is hard to assert whether the two images are equal or not, so we just verify the image has
85+
// been changed
86+
assertNotSame(drawable, imageView.getDrawable());
87+
}
88+
}
89+
90+

0 commit comments

Comments
 (0)