Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
public class DefaultHomeLocalDataSource implements HomeLocalDataSource {

private static final String PLAY_STORE_BASE_URL = "https://play.google.com/store/apps/details?id=";

private final Context context;

public DefaultHomeLocalDataSource(Context context) {
Expand All @@ -17,12 +19,15 @@ public DefaultHomeLocalDataSource(Context context) {

@Override
public String getPlayStoreUrl() {
return "https://play.google.com/store/apps/details?id=com.d4rk.androidtutorials";
return PLAY_STORE_BASE_URL;
}
Comment on lines 20 to 23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Returning base Play Store URL breaks app listing intent

The new getPlayStoreUrl() now returns only "https://play.google.com/store/apps/details?id=" without a package ID. HomeViewModel.getOpenPlayStoreIntent() uses this value directly to build the intent launched from the Home screen’s “Google Play” button, so after this change tapping the button will open a generic Play Store page (or an error) instead of the app’s listing (com.d4rk.androidtutorials). This is a functional regression; the method should still include the app’s package name, for example by appending a constant or the runtime package name.

Useful? React with 👍 / 👎.


@Override
public String getAppPlayStoreUrl(String packageName) {
return "https://play.google.com/store/apps/details?id=" + packageName;
if (packageName == null) {
return PLAY_STORE_BASE_URL;
}
return PLAY_STORE_BASE_URL + packageName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.androidtutorials.java.data.source;
package com.d4rk.androidtutorials.java.data.source.local;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
Expand All @@ -8,17 +8,45 @@
import android.content.res.Resources;

import com.d4rk.androidtutorials.java.R;
import com.d4rk.androidtutorials.java.data.source.DefaultHomeLocalDataSource;

import org.junit.Test;

public class DefaultHomeLocalDataSourceTest {

private static final String PLAY_STORE_BASE_URL = "https://play.google.com/store/apps/details?id=";

@Test
public void getPlayStoreUrl_returnsBaseUrl() {
DefaultHomeLocalDataSource dataSource =
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));

assertEquals(PLAY_STORE_BASE_URL, dataSource.getPlayStoreUrl());
}

@Test
public void getAppPlayStoreUrl_appendsPackageName() {
DefaultHomeLocalDataSource dataSource =
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));

assertEquals(PLAY_STORE_BASE_URL + "com.example.app",
dataSource.getAppPlayStoreUrl("com.example.app"));
}

@Test
public void getAppPlayStoreUrl_allowsEmptyPackageName() {
DefaultHomeLocalDataSource dataSource =
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));

assertEquals(PLAY_STORE_BASE_URL, dataSource.getAppPlayStoreUrl(""));
}

@Test
public void playStoreUrlsFormattedCorrectly() {
public void getAppPlayStoreUrl_handlesNullPackageName() {
DefaultHomeLocalDataSource dataSource =
new DefaultHomeLocalDataSource(mockContextWithTips(new String[]{"tip"}));
assertEquals("https://play.google.com/store/apps/details?id=com.d4rk.androidtutorials", dataSource.getPlayStoreUrl());
assertEquals("https://play.google.com/store/apps/details?id=pkg", dataSource.getAppPlayStoreUrl("pkg"));

assertEquals(PLAY_STORE_BASE_URL, dataSource.getAppPlayStoreUrl(null));
}

@Test
Expand Down