Skip to content

Commit

Permalink
Code formatting .Unit Test class added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeharivhth committed Aug 10, 2018
1 parent 8795fd6 commit 1e8f7f7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

buildToolsVersion '27.0.3'
}

dependencies {
Expand All @@ -33,6 +35,12 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'

androidTestImplementation 'org.mockito:mockito-core:2.4.0'
androidTestImplementation "org.assertj:assertj-core:1.7.0"
testImplementation "org.robolectric:robolectric:3.8"


//UI
api 'com.github.bumptech.glide:glide:4.7.1'
Expand All @@ -44,11 +52,9 @@ dependencies {
api 'com.android.support:support-annotations:27.1.1'
api 'com.android.support:support-compat:27.1.1'
api 'com.android.support:support-core-ui:27.1.1'

//Dagger 2
api 'com.google.dagger:dagger:2.16'
annotationProcessor 'com.google.dagger:dagger-compiler:2.16'

//Retrofit , RxJava Dependencies
api 'com.squareup.retrofit2:retrofit:2.3.0'
api 'com.squareup.okhttp3:okhttp:3.10.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.dev.movieapp.ui.fragments.detailfrag;

import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.dev.movieapp.R;
import com.dev.movieapp.models.Result;
import com.dev.movieapp.ui.activities.detail.ResultDetailActivity;
import com.dev.movieapp.ui.activities.splash.SplashActivity;
import com.dev.movieapp.utils.AppUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

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 android.support.test.espresso.matcher.ViewMatchers.withText;
import static java.lang.Boolean.FALSE;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class ResultDetailFragmentTest {

public final Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
@Rule
public final ActivityTestRule<ResultDetailActivity> detailActivityTestRule =
new ActivityTestRule<ResultDetailActivity>(ResultDetailActivity.class,true,true){
@Override
protected Intent getActivityIntent() {

Intent intent = new Intent(targetContext, ResultDetailActivity.class);
Result result= new Result();
result.setAdult(FALSE);
result.setBackdropPath("/bHarw8xrmQeqf3t8HpuMY7zoK4x.jpg");
result.setId(1);
result.setOriginalTitle("Avengers");
result.setTitle("Avengers Marvel");
result.setVoteAverage(4.2);
result.setVoteCount(13);
result.setOverview("Movie Description");
result.setReleaseDate("4-01-2018");
Parcel parcel = Parcel.obtain();
result.writeToParcel(parcel,result.describeContents());
parcel.setDataPosition(0);
Result createdFromParcel = Result.CREATOR.createFromParcel(parcel);
intent.putExtra(AppUtils.RESULT_KEY, createdFromParcel);
return intent;
}
};

@Before
public void setUp() throws Exception {

}


@Test
public void testUIElements(){
onView(withId(R.id.title)).check(matches(withText("Avengers Marvel")));
onView(withId(R.id.result_detail)).check(matches(withText("Movie Description")));
onView(withId(R.id.votes)).check(matches(withText("4.2"+ " "+targetContext.getString(R.string.percentage))));
onView(withId(R.id.releaseDate)).check(matches(withText(targetContext.getString(R.string.release)+" : " +"4-01-2018")));
onView(withId(R.id.totalVotes)).check(matches(withText("13"+" "+targetContext.getString(R.string.votes))));
}


@After
public void tearDown() throws Exception {
}


}
2 changes: 1 addition & 1 deletion app/src/main/java/com/dev/movieapp/app/MovieApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class MovieApp extends Application {

private static MovieApp movieAppInstance;
NetworkComponent mNetworkComponent;
private NetworkComponent mNetworkComponent;
private ContextComponent mContextComponent;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public NetworkProcessor(NetworkService networkService){
* @param lang
* @param page
*/
@SuppressWarnings("unchecked")
public void getPopularList(final GetPopularMovieCallBack callback,String api_key,String lang,String page){

Single singleResponse = mNetworkService.getPopularMovies(api_key,lang,page);
Expand Down Expand Up @@ -67,6 +68,7 @@ public void onError(Throwable e) {
/**
* Call backs for success and error scenarios
*/
@SuppressWarnings("unchecked")
public interface GetPopularMovieCallBack{
void onSuccess(PopularMovies movieList);
void onError(NetError networkError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public class ResultDetailActivity extends BaseActivity implements ResultDetailVi
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResult = getIntent().getExtras().getParcelable(AppUtils.RESULT_KEY);
try {
mResult = getIntent().getExtras().getParcelable(AppUtils.RESULT_KEY);
} catch (Exception e) {
e.printStackTrace();
}
renderView();
init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public class SplashPresenter {
*/
public SplashPresenter(SplashView splashView){
mSplashView = splashView;
new Handler().postDelayed(new Runnable() {
/*new Handler().postDelayed(new Runnable() {
@Override
public void run() {
postDelayAction();
}
}, SPLASH_TIME_OUT);
}, SPLASH_TIME_OUT);*/
postDelayAction();
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context="com.dev.movieapp.ui.activities.splash.SplashActivity">

<ImageView
android:id="@+id/splashImageId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/imbd_main"
Expand Down

0 comments on commit 1e8f7f7

Please sign in to comment.