Skip to content

Commit

Permalink
Finish Release-1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
riggaroo committed Apr 24, 2016
2 parents a356df9 + 51de0ec commit adccd70
Show file tree
Hide file tree
Showing 70 changed files with 1,995 additions and 799 deletions.
57 changes: 40 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: 'com.github.triplet.play'

repositories {
maven { url 'https://maven.fabric.io/public' }
}



android {
dataBinding { enabled = true}
dataBinding { enabled = true }
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "org.bookdash.android"
minSdkVersion 16
targetSdkVersion 23
versionCode 17
versionName "1.0.17"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 18
versionName "1.1.0"
testInstrumentationRunner "org.bookdash.android.presentation.CustomTestRunner"
buildConfigField "String", "PARSE_APPLICATION_ID", "\"${BOOKDASH_PARSE_APP_ID}\""
buildConfigField "String", "PARSE_CLIENT_KEY", "\"${BOOKDASH_PARSE_CLIENT_ID}\""
vectorDrawables.useSupportLibrary = true

}

File signFile = rootProject.file('release-keystore.properties')
if (signFile.exists()) {
signingConfigs {
Expand Down Expand Up @@ -74,7 +77,7 @@ android {
}
// Remove mockRelease as it's not needed.
android.variantFilter { variant ->
if(variant.buildType.name.equals('release')
if (variant.buildType.name.equals('release')
&& variant.getFlavors().get(0).name.equals('mock')) {
variant.setIgnore(true);
}
Expand All @@ -90,7 +93,7 @@ android {
release {
shrinkResources false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ext.enableCrashlytics = true
}
debug {
Expand All @@ -110,37 +113,37 @@ dependencies {
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile ("org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito")
testCompile ("org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito")
testCompile("org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito")
testCompile("org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito")

// Android Testing Support Library's runner and rules
androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.1'){
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.1') {
exclude module: 'support-annotations'
exclude module: 'support-v4'
}
androidTestCompile ("com.android.support.test:runner:$rootProject.ext.runnerVersion"){
androidTestCompile("com.android.support.test:runner:$rootProject.ext.runnerVersion") {
exclude module: 'support-annotations'
exclude module: 'support-v4'
}
androidTestCompile ("com.android.support.test:rules:$rootProject.ext.runnerVersion"){
androidTestCompile("com.android.support.test:rules:$rootProject.ext.runnerVersion") {
exclude module: 'support-annotations'
exclude module: 'support-v4'
}

// Espresso UI Testing
androidTestCompile ("com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"){
androidTestCompile("com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion") {
exclude module: 'recyclerview-v7'
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude group: "javax.inject"

}
androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion") {
androidTestCompile("com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion") {
exclude module: 'recyclerview-v7'
exclude module: 'support-annotations'
exclude module: 'support-v4'
}
androidTestCompile ("com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"){
androidTestCompile("com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion") {
exclude module: 'recyclerview-v7'
exclude module: 'support-annotations'
exclude module: 'support-v4'
Expand All @@ -159,8 +162,8 @@ dependencies {
compile 'com.google.code.gson:gson:2.4'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0'

// compile 'com.parse.bolts:bolts-android:1.3.0'
// compile 'com.parse:parse-android:1.11.0'
// compile 'com.parse.bolts:bolts-android:1.3.0'
// compile 'com.parse:parse-android:1.11.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.3@aar') {
transitive = true;
}
Expand All @@ -170,3 +173,23 @@ dependencies {
compile "com.android.support:design:$rootProject.ext.googlePlayServicesVersion"
compile "com.google.android.gms:play-services-analytics:$rootProject.ext.googlePlayServicesVersion"
}

// Grant animation permissions to avoid test failure because of ui sync.
task grantAnimationPermissions(type: Exec, dependsOn: 'installMock') {
group = 'test'
description = 'Grant permissions for testing.'

def absolutePath = file('..') // Get project absolute path
commandLine "$absolutePath/set_animation_permissions.sh org.bookdash.android".split(" ")
}

// Source: http://stackoverflow.com/q/29908110/112705
afterEvaluate {
// When launching individual tests from Android Studio, it seems that only the assemble tasks
// get called directly, not the install* versions
tasks.each { task ->
if (task.name.startsWith('assembleMockAndroidTest')) {
task.dependsOn grantAnimationPermissions
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.bookdash.android.presentation;

import android.Manifest;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.test.runner.AndroidJUnitRunner;
import android.util.Log;

import java.lang.reflect.Method;

/**
* Tests can fail for other reasons than code, it´ because of the animations and espresso sync and
* emulator state (screen off or locked)
* <p/>
* Before all the tests prepare the device to run tests and avoid these problems.
* <p/>
* - Disable animations
* - Disable keyguard lock
* - Set it to be awake all the time (dont let the processor sleep)
*
* @see <a href="u2020 open source app by Jake Wharton">https://github.com/JakeWharton/u2020</a>
* @see <a href="Daj gist">https://gist.github.com/daj/7b48f1b8a92abf960e7b</a>
*/
public final class CustomTestRunner extends AndroidJUnitRunner {

private static final String TAG = "CustomTestRunner";

@Override
public void onStart() {

runOnMainSync(new Runnable() {
@Override
public void run() {
Context app = CustomTestRunner.this.getTargetContext().getApplicationContext();

CustomTestRunner.this.disableAnimations(app);

String name = CustomTestRunner.class.getSimpleName();
unlockScreen(app, name);
keepSceenAwake(app, name);
}
});

super.onStart();
}


@Override
public void finish(int resultCode, Bundle results) {
super.finish(resultCode, results);
enableAnimations(getContext());
}
private void keepSceenAwake(Context app, String name) {
PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
power.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, name)
.acquire();
}

private void unlockScreen(Context app, String name) {
KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
keyguard.newKeyguardLock(name).disableKeyguard();
}

void disableAnimations(Context context) {
int permStatus = context.checkCallingOrSelfPermission(Manifest.permission.SET_ANIMATION_SCALE);
if (permStatus == PackageManager.PERMISSION_GRANTED) {
setSystemAnimationsScale(0.0f);
}
}

void enableAnimations(Context context) {
int permStatus = context.checkCallingOrSelfPermission(Manifest.permission.SET_ANIMATION_SCALE);
if (permStatus == PackageManager.PERMISSION_GRANTED) {
setSystemAnimationsScale(1.0f);
}
}

private void setSystemAnimationsScale(float animationScale) {
try {
Class<?> windowManagerStubClazz = Class.forName("android.view.IWindowManager$Stub");
Method asInterface = windowManagerStubClazz.getDeclaredMethod("asInterface", IBinder.class);
Class<?> serviceManagerClazz = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClazz.getDeclaredMethod("getService", String.class);
Class<?> windowManagerClazz = Class.forName("android.view.IWindowManager");
Method setAnimationScales = windowManagerClazz.getDeclaredMethod("setAnimationScales", float[].class);
Method getAnimationScales = windowManagerClazz.getDeclaredMethod("getAnimationScales");

IBinder windowManagerBinder = (IBinder) getService.invoke(null, "window");
Object windowManagerObj = asInterface.invoke(null, windowManagerBinder);
float[] currentScales = (float[]) getAnimationScales.invoke(windowManagerObj);
for (int i = 0; i < currentScales.length; i++) {
currentScales[i] = animationScale;
}
setAnimationScales.invoke(windowManagerObj, new Object[]{currentScales});
Log.d(TAG, "Changed permissions of animations");
} catch (Exception e) {
Log.e(TAG, "Could not change animation scale to " + animationScale + " :'(");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,50 @@
import android.support.test.espresso.intent.Intents;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.widget.NestedScrollView;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.Html;
import android.view.View;

import junit.framework.Assert;

import org.bookdash.android.R;
import org.bookdash.android.presentation.main.MainActivity;
import org.bookdash.android.presentation.utils.NavigationUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;


import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasData;
import static android.support.test.espresso.matcher.RootMatchers.isDialog;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;


import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;

/**
* @author rebeccafranks
* @since 15/11/21.
*/
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AboutActivityTest {
public class AboutFragmentTest {
@Rule
public ActivityTestRule<AboutActivity> testRule = new ActivityTestRule<>(AboutActivity.class);
public ActivityTestRule<MainActivity> testRule = new ActivityTestRule<>(MainActivity.class);

@Before
public void setUp(){
public void setUp() {
Intents.init();
NavigationUtils.selectNavDrawItem(testRule.getActivity(), R.id.action_about);

}

@After
public void tearDown(){
public void tearDown() {
Intents.release();
}

Expand All @@ -76,12 +70,13 @@ public void clickLearnMore_OpenBrowser() throws Throwable {
onView(withText(R.string.learn_more)).perform(scrollTo(), click());

intended(allOf(hasAction(Intent.ACTION_VIEW),
hasData(Uri.parse("http://bookdash.org"))
hasData(Uri.parse("http://bookdash.org"))
)
);
}

@Test
public void testGetScreenName(){
Assert.assertEquals("About Screen",testRule.getActivity().getScreenName());
public void testGetScreenName() {
Assert.assertEquals("MainActivity", testRule.getActivity().getScreenName());
}
}
Loading

0 comments on commit adccd70

Please sign in to comment.