Skip to content

Commit

Permalink
Updated RoboElectric in the hope it would work
Browse files Browse the repository at this point in the history
Spoiler: it didn't
  • Loading branch information
TheLastProject committed Nov 27, 2019
1 parent 691497e commit 0a9611e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 20 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ findbugs {
}

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
applicationId "protect.card_locker"
Expand Down Expand Up @@ -52,8 +52,9 @@ dependencies {
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile 'com.github.apl-devs:appintro:v4.2.0'
compile "com.vanniktech:vntnumberpickerpreference:1.0.0"
testCompile "androidx.test:core:1.0.0"
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.3.2"
testCompile "org.robolectric:robolectric:4.3"
}

task findbugs(type: FindBugs, dependsOn: 'assembleDebug') {
Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/protect/card_locker/DatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class DatabaseTest
{
private DBHelper db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@
import android.net.Uri;
import android.view.View;

import androidx.test.core.app.ApplicationProvider;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.res.builder.RobolectricPackageManager;
import org.robolectric.shadows.ShadowPackageManager;

import static org.robolectric.Shadows.shadowOf;

import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class ImportExportActivityTest
{
private void registerIntentHandler(String handler)
{
// Add something that will 'handle' the given intent type
RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());
ShadowPackageManager packageManager = shadowOf(ApplicationProvider.getApplicationContext().getPackageManager());

ResolveInfo info = new ResolveInfo();
info.isDefault = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class ImportExportTest
{
private Activity activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.junit.Assert.assertEquals;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class LoyaltyCardCursorAdapterTest
{
private Activity activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.widget.EditText;
import android.widget.TextView;

import androidx.test.core.app.ApplicationProvider;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.android.Intents;

Expand All @@ -27,7 +29,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.res.builder.RobolectricPackageManager;
import org.robolectric.shadows.ShadowPackageManager;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.shadows.ShadowLog;
import org.robolectric.android.controller.ActivityController;
Expand All @@ -40,7 +42,7 @@
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class LoyaltyCardViewActivityTest
{
private final String BARCODE_DATA = "428311627547";
Expand Down Expand Up @@ -70,7 +72,7 @@ public void setUp()
private void registerMediaStoreIntentHandler()
{
// Add something that will 'handle' the media capture intent
RobolectricPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());
ShadowPackageManager packageManager = shadowOf(ApplicationProvider.getApplicationContext().getPackageManager());

ResolveInfo info = new ResolveInfo();
info.isDefault = true;
Expand Down Expand Up @@ -350,7 +352,7 @@ private ActivityController createActivityWithLoyaltyCard(boolean editMode)

intent.putExtras(bundle);

return Robolectric.buildActivity(clazz).withIntent(intent).create();
return Robolectric.buildActivity(clazz, intent).create();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
@Config(sdk = 23)
public class MainActivityTest
{
private SharedPreferences prefs;
Expand Down
18 changes: 14 additions & 4 deletions app/src/test/java/protect/card_locker/SearchViewShadow.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
package protect.card_locker;

import android.support.v7.widget.SearchView;
import android.view.CollapsibleActionView;

import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadows.ShadowLinearLayout;

@Implements(SearchView.class)
public class SearchViewShadow {
@RealObject private SearchView realSearchView;
public class SearchViewShadow extends ShadowLinearLayout implements CollapsibleActionView {
private SearchView.OnQueryTextListener onQueryTextListener;

@Implementation
public void setOnQueryTextListener(SearchView.OnQueryTextListener listener) {
protected void setOnQueryTextListener(SearchView.OnQueryTextListener listener) {
onQueryTextListener = listener;
}

public void search(String query) {
onQueryTextListener.onQueryTextChange(query);
}

@Override
public void onActionViewExpanded() {

}

@Override
public void onActionViewCollapsed() {

}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.5.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
# a bug. Build tools 27.0.1 has a mitigation. Avoiding aapt2 also avoids hitting the bug.
# See: https://issuetracker.google.com/issues/64434571
android.enableAapt2=false

android.enableUnitTestBinaryResources=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jun 27 14:32:00 EDT 2018
#Wed Nov 27 14:21:08 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 comments on commit 0a9611e

Please sign in to comment.