Skip to content
Open
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
100 changes: 100 additions & 0 deletions Android/Entrevoisins/.idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Android/Entrevoisins/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Android/Entrevoisins/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Android/Entrevoisins/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Android/Entrevoisins/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions Android/Entrevoisins/.idea/runConfigurations.xml

This file was deleted.

38 changes: 36 additions & 2 deletions Android/Entrevoisins/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# OpenClassrooms
# Entrevoisin

Ce dépôt contient une mini-application pour le P3 du parcours **Grande École du Numérique**.
## Description
Ce dépôt contient une mini-application pour le P3 du parcours “Développement d’application Android” d’Openclassrooms.

Cette application consiste à:
*Afficher une liste de voisins.
*Faire une création de nouveau voisin
*Supprimer un voisin choisi
*Afficher les détails d’un voisin sélection
*Mettre un voisin en favori
*Afficher la liste de voisins favoris
## Prérequis
* Installation de [Android Studio](https://developer.android.com/studio?gclid=CjwKCAiAlp2fBhBPEiwA2Q10DylEC18SIGfmsSq9IHXwIvfDtvdeyjUUL9axVlY7wGES4gyH5kgjdxoCqlsQAvD_BwE&gclsrc=aw.ds)
* Installation du [Java sdk](https://www.oracle.com/fr/java/technologies/downloads/)
* Installation de [Git](https://git-scm.com/book/fr/v2/D%C3%A9marrage-rapide-Installation-de-Git)
* Télécharger les fichiers du projet Entre Voisin ou faire un [clone](https://docs.github.com/fr/repositories/creating-and-managing-repositories/cloning-a-repository) sur votre ordinateur
## Comment exécuter et compiler
* Ouvrir les fichiers avec android studio
* Synchroniser le build.gradle
* minSdkVersion 21
* targetSdkVersion 28
* dépendances
* [glide](https://github.com/bumptech/glide)
* [butterknife](https://jakewharton.github.io/butterknife/)
* [eventbus](https://greenrobot.org/eventbus/)
* [espresso](https://developer.android.com/training/testing/espresso)
* Sélectionner le device pour l'émulateur
* Sélectionner “app” dans la configuration
* appuyer sur le bouton Run


![Image](images/ExecuterCompiler.JPG)

## Crédits
Ce code est basé sur le code créé par Deyine d’Openclassrooms.
Voici le lien [Github](https://github.com/Deyine/OpenClassrooms/tree/master/Android/Entrevoisins)
10 changes: 8 additions & 2 deletions Android/Entrevoisins/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.openclassrooms.entrevoisins'
buildFeatures {
viewBinding true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.jakewharton:butterknife:9.0.0'
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
implementation 'android.arch.navigation:navigation-ui:1.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'

implementation 'com.github.bumptech.glide:glide:4.9.0'
Expand All @@ -41,7 +47,7 @@ dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'

// UNIT TEST
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
// INSTRUMENTATION TEST
androidTestImplementation 'com.android.support.test:rules:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package com.openclassrooms.entrevoisins.neighbour_list;

import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.openclassrooms.entrevoisins.R;
import com.openclassrooms.entrevoisins.di.DI;
import com.openclassrooms.entrevoisins.model.Neighbour;
import com.openclassrooms.entrevoisins.service.NeighbourApiService;
import com.openclassrooms.entrevoisins.ui.neighbour_list.ListNeighbourActivity;
import com.openclassrooms.entrevoisins.utils.DeleteViewAction;

Expand All @@ -16,12 +18,22 @@
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static android.support.test.espresso.matcher.ViewMatchers.hasMinimumChildCount;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.openclassrooms.entrevoisins.utils.RecyclerViewItemCountAssertion.withItemCount;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.core.IsNull.notNullValue;

import java.util.List;


/**
Expand All @@ -34,6 +46,8 @@ public class NeighboursListTest {
private static int ITEMS_COUNT = 12;

private ListNeighbourActivity mActivity;
private NeighbourApiService mApiService;
private List<Neighbour> mNeighbours;

@Rule
public ActivityTestRule<ListNeighbourActivity> mActivityRule =
Expand All @@ -43,6 +57,8 @@ public class NeighboursListTest {
public void setUp() {
mActivity = mActivityRule.getActivity();
assertThat(mActivity, notNullValue());
mApiService = DI.getNeighbourApiService();
mNeighbours = mApiService.getNeighbours();
}

/**
Expand All @@ -51,8 +67,7 @@ public void setUp() {
@Test
public void myNeighboursList_shouldNotBeEmpty() {
// First scroll to the position that needs to be matched and click on it.
onView(ViewMatchers.withId(R.id.list_neighbours))
.check(matches(hasMinimumChildCount(1)));
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).check(matches(hasMinimumChildCount(1)));
}

/**
Expand All @@ -61,11 +76,41 @@ public void myNeighboursList_shouldNotBeEmpty() {
@Test
public void myNeighboursList_deleteAction_shouldRemoveItem() {
// Given : We remove the element at position 2
onView(ViewMatchers.withId(R.id.list_neighbours)).check(withItemCount(ITEMS_COUNT));
//onView(withId(R.id.list_neighbours))
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).check(withItemCount(ITEMS_COUNT));
// When perform a click on a delete icon
onView(ViewMatchers.withId(R.id.list_neighbours))
onView(allOf(withId(R.id.list_neighbours), isDisplayed()))
.perform(RecyclerViewActions.actionOnItemAtPosition(1, new DeleteViewAction()));
// Then : the number of element is 11
onView(ViewMatchers.withId(R.id.list_neighbours)).check(withItemCount(ITEMS_COUNT-1));
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).check(withItemCount(ITEMS_COUNT-1));
}
@Test
public void neighbourIsClicked_shouldOpenDetailPage_withCorrectInfo() {
//launches second page
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
Neighbour neighbour = mNeighbours.get(0);
onView(withId(R.id.constraintLayout_UserInfo)).check(matches(isDisplayed()));

onView(withId(R.id.detail_avatar_lable_name)).check(matches(withText(neighbour.getName())));
onView(withId(R.id.detail_info_text_name)).check(matches(withText(neighbour.getName())));
}
@Test
public void testFavoriteList_OnlyDisplaysFavoriteNeighbours() throws InterruptedException {
//checks that the favorite list is empty at first
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).perform(swipeLeft());
Thread.sleep(500);
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).check(withItemCount(0));
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).perform(swipeRight());
Thread.sleep(500);
//adds a favorite neighbour by clicking on the fab button
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
Neighbour neighbour = mNeighbours.get(0);
onView(withId(R.id.detail_button_favorite)).perform(click());
onView(withId(R.id.detail_back_arrow)).perform(click());//go back home page
//Checks the the favorite list has one member and that it is the correct neighbour
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).perform(swipeLeft());
Thread.sleep(500);
onView(allOf(withId(R.id.list_neighbours), isDisplayed())).check(withItemCount(1));
onView(allOf(withText(neighbour.getName()),isDisplayed())).check(matches(isDisplayed()));
}
}
Loading