Skip to content

Commit

Permalink
Started Espresso Tests, fixed some unit tests, fix gradle wrapper and…
Browse files Browse the repository at this point in the history
… build files, added animation files, added cipher util. Updated rxredux and gadapter
  • Loading branch information
Zeyad-37 committed Jan 15, 2018
1 parent 85570f6 commit 60f969d
Show file tree
Hide file tree
Showing 43 changed files with 933 additions and 373 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ project.ext {
archComp = '1.0.0'
rxjava = '2.1.7'
rxAndroid = '2.0.1'
genericRecyclerViewAdapter = '1.6.2'
rxredux = '2.0.0'
genericRecyclerViewAdapter = '1.8.0'
rxredux = '2.1.1'
glide = '4.0.0'
lottie = '2.2.0'
retrofit = '2.3.0'
Expand All @@ -16,7 +16,8 @@ project.ext {
leakCanary = '1.5.4'
androidSupportTest = '1.0.1'
espressoCore = '3.0.1'
powerMock = '1.7.3'
powerMock = '1.6.6'
// powerMock = '1.7.3'
robolectric = '3.3.2'
// robolectric = '3.5.1'
okhttpIdelingResource = '1.0.0'
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Dec 11 16:14:29 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
67 changes: 23 additions & 44 deletions sampleApp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
}
}

repositories {
mavenCentral()
}

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "com.zeyad.usecase.accesslayer"
minSdkVersion 21
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.zeyad.usecases.app.UseCasesTestRunner"
Expand Down Expand Up @@ -107,17 +93,6 @@ android {
}
}

ext {
supportLibrary = '25.4.0'
butterKnife = '8.6.0'
rxbinding = '2.0.0'
rxLifeCycle = '2.0.1'
leakCanary = '1.5.1'
androidSupportTest = '0.5'
espressoCore = '2.2.2'
archComp = '1.0.0-alpha5'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':usecases')
Expand All @@ -132,12 +107,12 @@ dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'

// Bootstrap
compile 'com.github.Zeyad-37:GenericRecyclerViewAdapter:1.3.0'
compile 'com.github.Zeyad-37:RxRedux:1.5.2'
compile "com.github.Zeyad-37:GenericRecyclerViewAdapter:$genericRecyclerViewAdapter"
compile "com.github.Zeyad-37:RxRedux:$rxredux"

// compile "android.arch.lifecycle:runtime:$archComp"
compile "android.arch.lifecycle:extensions:$archComp"
compile "android.arch.lifecycle:reactivestreams:$archComp"
// compile "android.arch.lifecycle:extensions:$archComp"
// compile "android.arch.lifecycle:reactivestreams:$archComp"
// Network
compile 'com.github.bumptech.glide:glide:3.7.0'
// Rx
Expand All @@ -146,17 +121,19 @@ dependencies {
compile "com.jakewharton.rxbinding2:rxbinding-appcompat-v7:$rxbinding"
compile "com.jakewharton.rxbinding2:rxbinding-design:$rxbinding"
compile "com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:$rxbinding"
compile "com.trello.rxlifecycle2:rxlifecycle:$rxLifeCycle"
compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxLifeCycle"
// compile "com.trello.rxlifecycle2:rxlifecycle:$rxLifeCycle"
// compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxLifeCycle"
// Injection
compile "com.jakewharton:butterknife:$butterKnife"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnife"
// Utilities
compile 'com.airbnb.android:lottie:2.1.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
annotationProcessor "org.parceler:parceler:1.1.9"
compile "nl.littlerobots.rxlint:rxlint:$rxlint"
compile 'com.airbnb.android:lottie:2.2.0'
debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanary"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanary"
testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanary"
compile 'org.parceler:parceler-api:1.1.9'
annotationProcessor 'org.parceler:parceler:1.1.9'
// compile("io.flowup:android-sdk:0.2.4") {
// exclude group: 'com.google.android.gms'
// }
Expand All @@ -168,17 +145,19 @@ dependencies {
androidTestCompile "com.android.support.test.espresso:espresso-core:$espressoCore"
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile "org.mockito:mockito-core:$mockito"
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile('com.jakewharton.espresso:okhttp3-idling-resource:1.0.0') {
exclude group: 'com.android.support'
}
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.8.0'
androidTestCompile 'com.github.andrzejchm.RESTMock:android:0.1.4'
androidTestCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
androidTestCompile "com.github.andrzejchm.RESTMock:android:$restMock"

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile "org.mockito:mockito-core:$mockito"
debugCompile 'com.21buttons:fragment-test-rule:1.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

//apply from: "$project.rootDir/tools/script-git-version.gradle"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.zeyad.usecases.app.screens;

import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAssertion;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.hamcrest.Matcher;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
* @author by ZIaDo on 7/31/17.
*/
public class RecyclerViewItemCountAssertion implements ViewAssertion {
private final Matcher<Integer> matcher;

private RecyclerViewItemCountAssertion(Matcher<Integer> matcher) {
this.matcher = matcher;
}

public static RecyclerViewItemCountAssertion withItemCount(int expectedCount) {
return withItemCount(is(expectedCount));
}

public static RecyclerViewItemCountAssertion withItemCount(Matcher<Integer> matcher) {
return new RecyclerViewItemCountAssertion(matcher);
}

@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.Adapter adapter = recyclerView.getAdapter();
assertThat(adapter.getItemCount(), matcher);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.zeyad.usecases.app.screens.splash;

import android.support.test.rule.ActivityTestRule;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Rule;
import org.junit.Test;

@LargeTest
//@RunWith(AndroidJUnit4.class)
public class UserListActivityTest {

@Rule
public ActivityTestRule<SplashActivity> mActivityTestRule = new ActivityTestRule<>(SplashActivity.class);

@Test
public void userListActivityTest() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.zeyad.usecases.app.screens.user.detail;

import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;

import com.zeyad.usecases.app.screens.user.list.User;

import org.junit.Rule;

import java.util.ArrayList;
import java.util.List;

/**
* @author by ZIaDo on 8/1/17.
*/
public class UserDetailFragmentTest {
private User user;
private List<Repository> repositories;
@Rule
public ActivityTestRule<UserDetailActivity> mActivityTestRule = new ActivityTestRule<UserDetailActivity>(
UserDetailActivity.class) {
@Override
protected Intent getActivityIntent() {
return UserDetailActivity.getCallingIntent(
InstrumentationRegistry.getInstrumentation().getTargetContext(), UserDetailState.builder()
.setIsTwoPane(false).setRepos(mockRepos()).setUser(mockUser().getLogin()).build());
}
};

private User mockUser() {
user = new User();
user.setAvatarUrl("https://avatars2.githubusercontent.com/u/5938141?v=3");
user.setId(5938141);
user.setLogin("Zeyad-37");
return user;
}

private List<Repository> mockRepos() {
repositories = new ArrayList<>();
Repository repository = new Repository();
repository.setId(1);
repository.setName("Repo");
repository.setOwner(user);
return repositories;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.zeyad.usecases.app.screens.user.detail;

import com.android21buttons.fragmenttestrule.FragmentTestRule;
import com.zeyad.usecases.app.screens.user.list.User;

import org.junit.Rule;

import java.util.ArrayList;
import java.util.List;

/**
* @author by ZIaDo on 8/1/17.
*/
public class UserDetailFragmentTest2 {
@Rule
public FragmentTestRule<?, UserDetailFragment> fragmentTestRule =
FragmentTestRule.create(UserDetailFragment.class);
private User user;
private List<Repository> repositories;

private User mockUser() {
user = new User();
user.setAvatarUrl("https://avatars2.githubusercontent.com/u/5938141?v=3");
user.setId(5938141);
user.setLogin("Zeyad-37");
return user;
}

private List<Repository> mockRepos() {
repositories = new ArrayList<>();
Repository repository = new Repository();
repository.setId(1);
repository.setName("Repo");
repository.setOwner(user);
return repositories;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.zeyad.usecases.app.screens.user.list;

import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import com.zeyad.usecases.app.OkHttpIdlingResourceRule;
import com.zeyad.usecases.app.R;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
Expand All @@ -15,12 +26,20 @@
import io.appflate.restmock.RequestsVerifier;
import okhttp3.mockwebserver.MockResponse;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.zeyad.usecases.app.screens.RecyclerViewItemCountAssertion.withItemCount;
import static io.appflate.restmock.utils.RequestMatchers.pathEndsWith;
import static io.appflate.restmock.utils.RequestMatchers.pathStartsWith;
import static org.hamcrest.Matchers.allOf;

/**
* @author by ZIaDo on 6/15/17.
*/
@LargeTest
@RunWith(AndroidJUnit4.class)
public class UserListActivityTest {
private static final String USER_LIST_BODY = "{ \"login\" : \"octocat\", \"followers\" : 1500 }";
private final String urlPart = "users?since=0";
Expand All @@ -34,11 +53,35 @@ public class UserListActivityTest {
// @Rule
// public MockWebServerRule mockWebServerRule = new MockWebServerRule();

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
parentMatcher.describeTo(description.appendText("Child at position " + position + " in parent "));
}

@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}

@Before
public void before() {
RESTMockServer.reset();
}

@Test
public void userListActivityTest() {
ViewInteraction recyclerView = onView(allOf(withId(R.id.user_list),
childAtPosition(childAtPosition(withId(R.id.frameLayout), 0), 0), isDisplayed()));
recyclerView.check(matches(isDisplayed()));
onView(withId(R.id.user_list)).check(withItemCount(30));
}

@Test
public void followers() throws IOException, InterruptedException {
RESTMockServer.whenGET(pathEndsWith(urlPart))
Expand Down
Loading

0 comments on commit 60f969d

Please sign in to comment.