Skip to content

Commit 38e9b78

Browse files
Merge pull request #211 from MihaiCristianCondrea/codex/add-tests-for-defaulthomelocaldatasource
Adjust Play Store URLs and add local data source tests
2 parents 7b1dc07 + a12a91c commit 38e9b78

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/data/source/DefaultHomeLocalDataSource.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
public class DefaultHomeLocalDataSource implements HomeLocalDataSource {
1111

12+
private static final String PLAY_STORE_BASE_URL = "https://play.google.com/store/apps/details?id=";
13+
1214
private final Context context;
1315

1416
public DefaultHomeLocalDataSource(Context context) {
@@ -17,12 +19,15 @@ public DefaultHomeLocalDataSource(Context context) {
1719

1820
@Override
1921
public String getPlayStoreUrl() {
20-
return "https://play.google.com/store/apps/details?id=com.d4rk.androidtutorials";
22+
return PLAY_STORE_BASE_URL;
2123
}
2224

2325
@Override
2426
public String getAppPlayStoreUrl(String packageName) {
25-
return "https://play.google.com/store/apps/details?id=" + packageName;
27+
if (packageName == null) {
28+
return PLAY_STORE_BASE_URL;
29+
}
30+
return PLAY_STORE_BASE_URL + packageName;
2631
}
2732

2833
@Override
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.d4rk.androidtutorials.java.data.source;
1+
package com.d4rk.androidtutorials.java.data.source.local;
22

33
import static org.junit.Assert.assertEquals;
44
import static org.mockito.Mockito.mock;
@@ -8,17 +8,45 @@
88
import android.content.res.Resources;
99

1010
import com.d4rk.androidtutorials.java.R;
11+
import com.d4rk.androidtutorials.java.data.source.DefaultHomeLocalDataSource;
1112

1213
import org.junit.Test;
1314

1415
public class DefaultHomeLocalDataSourceTest {
1516

17+
private static final String PLAY_STORE_BASE_URL = "https://play.google.com/store/apps/details?id=";
18+
19+
@Test
20+
public void getPlayStoreUrl_returnsBaseUrl() {
21+
DefaultHomeLocalDataSource dataSource =
22+
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));
23+
24+
assertEquals(PLAY_STORE_BASE_URL, dataSource.getPlayStoreUrl());
25+
}
26+
27+
@Test
28+
public void getAppPlayStoreUrl_appendsPackageName() {
29+
DefaultHomeLocalDataSource dataSource =
30+
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));
31+
32+
assertEquals(PLAY_STORE_BASE_URL + "com.example.app",
33+
dataSource.getAppPlayStoreUrl("com.example.app"));
34+
}
35+
36+
@Test
37+
public void getAppPlayStoreUrl_allowsEmptyPackageName() {
38+
DefaultHomeLocalDataSource dataSource =
39+
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));
40+
41+
assertEquals(PLAY_STORE_BASE_URL, dataSource.getAppPlayStoreUrl(""));
42+
}
43+
1644
@Test
17-
public void playStoreUrlsFormattedCorrectly() {
45+
public void getAppPlayStoreUrl_handlesNullPackageName() {
1846
DefaultHomeLocalDataSource dataSource =
1947
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));
20-
assertEquals("https://play.google.com/store/apps/details?id=com.d4rk.androidtutorials", dataSource.getPlayStoreUrl());
21-
assertEquals("https://play.google.com/store/apps/details?id=pkg", dataSource.getAppPlayStoreUrl("pkg"));
48+
49+
assertEquals(PLAY_STORE_BASE_URL, dataSource.getAppPlayStoreUrl(null));
2250
}
2351

2452
@Test

0 commit comments

Comments
 (0)