Added initial test for AppDetailsRecyclerViewAdapter.
Doesn't do anything except create an app with no versions, no donate links, anything like that, and ensure that the adapter is able to create the view holders for each resulting item. In the future we can beef this up to check more exotic conditions, such as calling `updateItems(App)` with different apps, each with different combinations of versions, donation links, permissions, etc.
This commit is contained in:
parent
774ca02d22
commit
46eb6ee3b4
@ -44,6 +44,9 @@ dependencies {
|
|||||||
|
|
||||||
testCompile "org.robolectric:robolectric:3.1.2"
|
testCompile "org.robolectric:robolectric:3.1.2"
|
||||||
|
|
||||||
|
// As per https://github.com/robolectric/robolectric/issues/1932#issuecomment-219796474
|
||||||
|
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
|
||||||
|
|
||||||
testCompile "org.mockito:mockito-core:1.10.19"
|
testCompile "org.mockito:mockito-core:1.10.19"
|
||||||
|
|
||||||
androidTestCompile 'com.android.support:support-annotations:24.2.1'
|
androidTestCompile 'com.android.support:support-annotations:24.2.1'
|
||||||
|
@ -0,0 +1,120 @@
|
|||||||
|
package org.fdroid.fdroid.views;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.BuildConfig;
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.data.Apk;
|
||||||
|
import org.fdroid.fdroid.data.App;
|
||||||
|
import org.fdroid.fdroid.data.FDroidProvider;
|
||||||
|
import org.fdroid.fdroid.data.FDroidProviderTest;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricGradleTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
// TODO: Use sdk=24 when Robolectric supports this
|
||||||
|
@Config(constants = BuildConfig.class, application = Application.class, sdk = 23)
|
||||||
|
@RunWith(RobolectricGradleTestRunner.class)
|
||||||
|
public class AppDetailsAdapterTest extends FDroidProviderTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() {
|
||||||
|
ImageLoader.getInstance().destroy();
|
||||||
|
FDroidProvider.clearDbHelperSingleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void appWithNoVersions() {
|
||||||
|
App app = new App();
|
||||||
|
app.name = "Test App";
|
||||||
|
app.description = "Test App <b>Description</b>";
|
||||||
|
|
||||||
|
AppDetailsRecyclerViewAdapter adapter = new AppDetailsRecyclerViewAdapter(context, app, dummyCallbacks);
|
||||||
|
populateViewHolders(adapter);
|
||||||
|
|
||||||
|
assertEquals(5, adapter.getItemCount());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that every single item in the adapter gets its view holder created and bound.
|
||||||
|
* Doesn't care about what type of holder it should be, the adapter is able to figure all that
|
||||||
|
* out for us .
|
||||||
|
*/
|
||||||
|
private void populateViewHolders(RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
|
||||||
|
ViewGroup parent = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.app_details2_links, null);
|
||||||
|
for (int i = 0; i < adapter.getItemCount(); i++) {
|
||||||
|
RecyclerView.ViewHolder viewHolder = adapter.createViewHolder(parent, adapter.getItemViewType(i));
|
||||||
|
adapter.bindViewHolder(viewHolder, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks dummyCallbacks = new AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks() {
|
||||||
|
@Override
|
||||||
|
public boolean isAppDownloading() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enableAndroidBeam() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disableAndroidBeam() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openUrl(String url) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApk(Apk apk) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void upgradeApk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uninstallApk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installCancel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void launchApk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user