Skip to content

Commit 3ec4cf9

Browse files
committed
Treewide: Refactoring Repository
- Drop fetch data from Dummy on repository - Drop all JSON assets data - Drop genre & cast data on layout that was fetched from dummy - Drop dependencies on Injection class from JsonHelper after getting refactoring to Helper - Include Production Companies on layout & fetch genre only from API - Move API Key to BuildConfig on gradle properties - Re-implement MutableLiveData for repository - Refactoring repository for only fetch data from API - Refactoring all JSON tree response from Dummy to only using API JSON tree response (Include changes to all activity, viewmodel and adapter) - Reconfigure Datasource after refactoring repository tree - Reconfigure all adapter after refactoring JSON tree response - Re-write JSON Helper -> Helper class which are not tighten to JSON reading scenario from assets folder anymore, since now helper directly append data from repository - Other misc changes (Including code cleanup) ...
1 parent 832d120 commit 3ec4cf9

File tree

93 files changed

+1771
-3487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1771
-3487
lines changed

.idea/deploymentTargetDropDown.xml

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ android {
1212
minSdk 21
1313
targetSdk 31
1414
versionCode 1
15-
versionName "1.3"
15+
versionName "1.5"
16+
buildConfigField("String", "KEY", '"138cf97267100e481f54f6ac6dad2f8c"')
1617

1718
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1819
vectorDrawables.useSupportLibrary = true

app/src/androidTest/java/com/dicoding/moviecatalog/activity/MainActivityTest.kt

+65-26
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
1212
import com.dicoding.moviecatalog.R
1313
import com.dicoding.moviecatalog.utils.CatalogDatabase
1414
import com.dicoding.moviecatalog.utils.EspressoIdlingResource
15+
import com.dicoding.moviecatalog.utils.InlineVariable
1516
import org.junit.After
1617
import org.junit.Before
1718
import org.junit.Rule
1819
import org.junit.Test
1920

20-
2121
class MainActivityTest {
22-
private val dummyMovie = CatalogDatabase.generateMovieDatabase()
23-
private val dummyCastMovie1 = CatalogDatabase.generateCastListMovie1()
24-
private val dummyCastTvShow1 = CatalogDatabase.generateCastListTvShow1()
25-
private val dummyTvShow = CatalogDatabase.generateTvShowDatabase()
22+
private val dummyMovie = CatalogDatabase.generateMovieLocal()
23+
private val dummyGenreMovie = CatalogDatabase.generateGenreMovies()
24+
private val dummyProductionMovie = CatalogDatabase.generateCompaniesMovies()
25+
private val dummyProductionTvShow = CatalogDatabase.generateCompaniesTvShow()
26+
private val dummyGenreTvShow = CatalogDatabase.generateGenreTvShow()
27+
private val dummyTvShow = CatalogDatabase.generateTvShowLocal()
28+
private val inlineVariable = InlineVariable()
2629

2730
@get:Rule
2831
var activityRule = ActivityScenarioRule(MainActivity::class.java)
@@ -40,6 +43,7 @@ class MainActivityTest {
4043

4144
@Test
4245
fun loadMovie() {
46+
inlineVariable.delayTwoSecond()
4347
onView(withText("MOVIE")).perform(click())
4448
onView(withId(R.id.rv_movie)).check(matches(isDisplayed()))
4549
onView(withId(R.id.rv_movie)).perform(
@@ -51,6 +55,7 @@ class MainActivityTest {
5155

5256
@Test
5357
fun loadDetailMovie() {
58+
inlineVariable.delayTwoSecond()
5459
onView(withText("MOVIE")).perform(click())
5560
onView(withId(R.id.rv_movie)).check(matches(isDisplayed()))
5661
onView(withId(R.id.rv_movie)).perform(
@@ -59,28 +64,40 @@ class MainActivityTest {
5964
click()
6065
)
6166
)
67+
inlineVariable.delayTwoSecond()
6268
onView(withId(R.id.movie_title_text)).check(matches(isDisplayed()))
6369
onView(withId(R.id.movie_title_text)).check(matches(withText(dummyMovie[0].title)))
6470
onView(withId(R.id.movie_release_date)).check(matches(isDisplayed()))
65-
onView(withId(R.id.movie_release_date)).check(matches(withText(dummyMovie[0].releaseDate)))
71+
val releaseDate = inlineVariable.setReleaseDate(dummyMovie[0].releaseDate)
72+
onView(withId(R.id.movie_release_date)).check(matches(withText(releaseDate)))
6673
onView(withId(R.id.image_poster)).check(matches(isDisplayed()))
67-
onView(withId(R.id.image_poster)).check(matches(withContentDescription(dummyMovie[0].imagePath)))
74+
onView(withId(R.id.image_poster)).check(matches(withContentDescription(dummyMovie[0].posterPath)))
6875
onView(withId(R.id.movie_rating_text)).check(matches(isDisplayed()))
69-
onView(withId(R.id.movie_rating_text)).check(matches(withText(dummyMovie[0].rating)))
70-
onView(withId(R.id.movie_duration_text)).check(matches(isDisplayed()))
71-
onView(withId(R.id.movie_duration_text)).check(matches(withText(dummyMovie[0].duration)))
76+
onView(withId(R.id.movie_rating_text)).check(matches(withText(dummyMovie[0].voteAverage.toString())))
77+
onView(withId(R.id.movie_revenue_text)).check(matches(isDisplayed()))
78+
val revenue = inlineVariable.setRevenue(dummyMovie[0].revenue.toString())
79+
onView(withId(R.id.movie_revenue_text)).check(matches(withText(revenue)))
7280
onView(withId(R.id.desc_text)).check(matches(isDisplayed()))
73-
onView(withId(R.id.desc_text)).check(matches(withText(dummyMovie[0].description)))
74-
onView(withId(R.id.rv_cast)).check(matches(isDisplayed()))
75-
onView(withId(R.id.rv_cast)).perform(
81+
onView(withId(R.id.desc_text)).check(matches(withText(dummyMovie[0].overview)))
82+
inlineVariable.delayTwoSecond()
83+
onView(withId(R.id.rv_genre_api)).check(matches(isDisplayed()))
84+
onView(withId(R.id.rv_genre_api)).perform(
7685
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
77-
dummyCastMovie1.size
86+
dummyGenreMovie.size
87+
)
88+
)
89+
inlineVariable.delayTwoSecond()
90+
onView(withId(R.id.rv_companies)).check(matches(isDisplayed()))
91+
onView(withId(R.id.rv_companies)).perform(
92+
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
93+
dummyProductionMovie.size
7894
)
7995
)
8096
}
8197

8298
@Test
8399
fun loadDetailTvShow() {
100+
inlineVariable.delayTwoSecond()
84101
onView(withText("TV SHOW")).perform(click())
85102
onView(withId(R.id.rv_tvshow)).check(matches(isDisplayed()))
86103
onView(withId(R.id.rv_tvshow)).perform(
@@ -89,30 +106,49 @@ class MainActivityTest {
89106
click()
90107
)
91108
)
109+
inlineVariable.delayTwoSecond()
92110
onView(withId(R.id.movie_title_text)).check(matches(isDisplayed()))
93-
onView(withId(R.id.movie_title_text)).check(matches(withText(dummyTvShow[0].title)))
111+
onView(withId(R.id.movie_title_text)).check(matches(withText(dummyTvShow[0].tvShowName)))
94112
onView(withId(R.id.movie_release_date)).check(matches(isDisplayed()))
95-
onView(withId(R.id.movie_release_date)).check(matches(withText(dummyTvShow[0].releaseDate)))
113+
val releaseDate = dummyTvShow[0].tvShowFirstAirDate
114+
onView(withId(R.id.movie_release_date)).check(
115+
matches(
116+
withText(
117+
inlineVariable.setReleaseDate(
118+
releaseDate
119+
)
120+
)
121+
)
122+
)
96123
onView(withId(R.id.image_poster)).check(matches(isDisplayed()))
97-
onView(withId(R.id.image_poster)).check(matches(withContentDescription(dummyTvShow[0].imagePath)))
124+
onView(withId(R.id.image_poster)).check(matches(withContentDescription(dummyTvShow[0].tvShowPoster)))
98125
onView(withId(R.id.movie_rating_text)).check(matches(isDisplayed()))
99-
onView(withId(R.id.movie_rating_text)).check(matches(withText(dummyTvShow[0].rating)))
126+
onView(withId(R.id.movie_rating_text)).check(matches(withText(dummyTvShow[0].tvShowVote.toString())))
100127
onView(withId(R.id.movie_episode_text)).check(matches(isDisplayed()))
101-
onView(withId(R.id.movie_episode_text)).check(matches(withText(dummyTvShow[0].episode + " | " + dummyTvShow[0].season)))
102-
onView(withId(R.id.movie_duration_text)).check(matches(isDisplayed()))
103-
onView(withId(R.id.movie_duration_text)).check(matches(withText(dummyTvShow[0].duration)))
128+
onView(withId(R.id.movie_episode_text)).check(matches(withText(dummyTvShow[0].tvShowEpisodes.toString() + " Episode | " + dummyTvShow[0].tvShowSeasons.toString() + " Season")))
129+
onView(withId(R.id.tvShow_language_text)).check(matches(isDisplayed()))
130+
onView(withId(R.id.tvShow_language_text)).check(matches(withText(dummyTvShow[0].tvShowLanguage)))
104131
onView(withId(R.id.desc_text)).check(matches(isDisplayed()))
105-
onView(withId(R.id.desc_text)).check(matches(withText(dummyTvShow[0].description)))
106-
onView(withId(R.id.rv_cast)).check(matches(isDisplayed()))
107-
onView(withId(R.id.rv_cast)).perform(
132+
onView(withId(R.id.desc_text)).check(matches(withText(dummyTvShow[0].tvShowOverview)))
133+
inlineVariable.delayTwoSecond()
134+
onView(withId(R.id.rv_genre_api)).check(matches(isDisplayed()))
135+
onView(withId(R.id.rv_genre_api)).perform(
108136
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
109-
dummyCastTvShow1.size
137+
dummyGenreTvShow.size
138+
)
139+
)
140+
inlineVariable.delayTwoSecond()
141+
onView(withId(R.id.rv_companies)).check(matches(isDisplayed()))
142+
onView(withId(R.id.rv_companies)).perform(
143+
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
144+
dummyProductionTvShow.size
110145
)
111146
)
112147
}
113148

114149
@Test
115150
fun loadTvShow() {
151+
inlineVariable.delayTwoSecond()
116152
onView(withText("TV SHOW")).perform(click())
117153
onView(withId(R.id.rv_tvshow)).check(matches(isDisplayed()))
118154
onView(withId(R.id.rv_tvshow)).perform(
@@ -124,6 +160,7 @@ class MainActivityTest {
124160

125161
@Test
126162
fun loadShareMovie() {
163+
inlineVariable.delayTwoSecond()
127164
onView(withText("MOVIE")).perform(click())
128165
onView(withId(R.id.rv_movie)).check(matches(isDisplayed()))
129166
onView(withId(R.id.rv_movie)).perform(
@@ -132,13 +169,15 @@ class MainActivityTest {
132169
click()
133170
)
134171
)
172+
inlineVariable.delayTwoSecond()
135173
onView(withId(R.id.img_share)).check(matches(isDisplayed()))
136174
onView(withId(R.id.img_share)).check(matches(isClickable()))
137175
onView(withId(R.id.img_share)).perform(click())
138176
}
139177

140178
@Test
141179
fun loadShareTvShow() {
180+
inlineVariable.delayTwoSecond()
142181
onView(withText("TV SHOW")).perform(click())
143182
onView(withId(R.id.rv_tvshow)).check(matches(isDisplayed()))
144183
onView(withId(R.id.rv_tvshow)).perform(
@@ -147,9 +186,9 @@ class MainActivityTest {
147186
click()
148187
)
149188
)
189+
inlineVariable.delayTwoSecond()
150190
onView(withId(R.id.img_share)).check(matches(isDisplayed()))
151191
onView(withId(R.id.img_share)).check(matches(isClickable()))
152192
onView(withId(R.id.img_share)).perform(click())
153193
}
154-
155194
}

app/src/main/assets/MovieCast10Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast1Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast2Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast3Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast4Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast5Responses.json

-22
This file was deleted.

app/src/main/assets/MovieCast6Responses.json

-22
This file was deleted.

0 commit comments

Comments
 (0)