Skip to content

Commit

Permalink
Fixed rest of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed May 9, 2019
1 parent c368733 commit 3eddbd8
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.widgets.DateTimeWidget;
import org.odk.collect.android.widgets.DateWidget;
import org.odk.collect.android.widgets.TimeWidget;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.TimeZone;

Expand Down Expand Up @@ -106,7 +107,7 @@ private DateWidget prepareDateWidget(int year, int month, int day) {
when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);

DateWidget dateWidget = new DateWidget(RuntimeEnvironment.application, formEntryPromptStub);
DateWidget dateWidget = new DateWidget(Robolectric.buildActivity(FormEntryActivity.class).create().get(), formEntryPromptStub);
dateWidget.setDatePickerDialog(datePickerDialog);
return dateWidget;
}
Expand All @@ -128,7 +129,7 @@ private DateTimeWidget prepareDateTimeWidget(int year, int month, int day, int h
when(timeWidget.getHour()).thenReturn(hour);
when(timeWidget.getMinute()).thenReturn(minute);

DateTimeWidget dateTimeWidget = new DateTimeWidget(RuntimeEnvironment.application, formEntryPromptStub);
DateTimeWidget dateTimeWidget = new DateTimeWidget(Robolectric.buildActivity(FormEntryActivity.class).create().get(), formEntryPromptStub);
dateTimeWidget.setDateWidget(dateWidget);
dateTimeWidget.setTimeWidget(timeWidget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import org.javarosa.core.model.data.BooleanData;
import org.junit.Test;
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.widgets.base.WidgetTest;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Robolectric;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -18,7 +19,7 @@ public class BooleanWidgetTest extends WidgetTest {

@NonNull
private BooleanWidget getWidget() {
return new BooleanWidget(RuntimeEnvironment.application, formEntryPrompt);
return new BooleanWidget(Robolectric.buildActivity(FormEntryActivity.class).create().get(), formEntryPrompt);
}

// BooleanWidgets always return a non-null answer, so we need to handle these tests manually:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.widgets.base.GeneralDateTimeWidgetTest;
import org.robolectric.RuntimeEnvironment;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -31,7 +30,7 @@ public void setUp() throws Exception {
@NonNull
@Override
public DateTimeWidget createWidget() {
return new DateTimeWidget(RuntimeEnvironment.application, formEntryPrompt);
return new DateTimeWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.widgets.base.GeneralDateTimeWidgetTest;
import org.robolectric.RuntimeEnvironment;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -30,7 +29,7 @@ public void setUp() throws Exception {
@NonNull
@Override
public DateWidget createWidget() {
return new DateWidget(RuntimeEnvironment.application, formEntryPrompt);
return new DateWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.javarosa.core.model.data.DecimalData;
import org.odk.collect.android.widgets.base.GeneralExStringWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.text.NumberFormat;
import java.util.Locale;
Expand All @@ -20,7 +19,7 @@ public class ExDecimalWidgetTest extends GeneralExStringWidgetTest<ExDecimalWidg
@NonNull
@Override
public ExDecimalWidget createWidget() {
return new ExDecimalWidget(RuntimeEnvironment.application, formEntryPrompt);
return new ExDecimalWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.javarosa.core.model.data.StringData;
import org.odk.collect.android.widgets.base.GeneralExStringWidgetTest;
import org.robolectric.RuntimeEnvironment;

import static org.mockito.Mockito.when;

Expand All @@ -19,7 +18,7 @@ public class ExStringWidgetTest extends GeneralExStringWidgetTest<ExStringWidget
@NonNull
@Override
public ExStringWidget createWidget() {
return new ExStringWidget(RuntimeEnvironment.application, formEntryPrompt);
return new ExStringWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.javarosa.core.model.data.helper.Selection;
import org.junit.Test;
import org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,7 +23,7 @@ public class GridMultiWidgetTest extends GeneralSelectMultiWidgetTest<GridMultiW
@NonNull
@Override
public GridMultiWidget createWidget() {
return new GridMultiWidget(RuntimeEnvironment.application, formEntryPrompt, 1);
return new GridMultiWidget(activity, formEntryPrompt, 1);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -13,6 +12,6 @@ public class GridWidgetTest extends GeneralSelectOneWidgetTest<GridWidget> {
@NonNull
@Override
public GridWidget createWidget() {
return new GridWidget(RuntimeEnvironment.application, formEntryPrompt, 1, false);
return new GridWidget(activity, formEntryPrompt, 1, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.javarosa.core.model.data.IntegerData;
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.util.Random;

Expand All @@ -18,7 +17,7 @@ public class IntegerWidgetTest extends GeneralStringWidgetTest<IntegerWidget, In
public IntegerWidget createWidget() {
Random random = new Random();
boolean useThousandSeparator = random.nextBoolean();
return new IntegerWidget(RuntimeEnvironment.application, formEntryPrompt, false, useThousandSeparator);
return new IntegerWidget(activity, formEntryPrompt, false, useThousandSeparator);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.odk.collect.android.utilities.FileUtil;
import org.odk.collect.android.utilities.XPathParseTool;
import org.odk.collect.android.widgets.base.QuestionWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.io.File;
import java.util.HashMap;
Expand Down Expand Up @@ -91,7 +90,7 @@ public class ItemsetWidgetTest extends QuestionWidgetTest<ItemsetWidget, StringD
@NonNull
@Override
public ItemsetWidget createWidget() {
return new ItemsetWidget(RuntimeEnvironment.application, formEntryPrompt,
return new ItemsetWidget(activity, formEntryPrompt,
false, parseTool, adapter, fileUtil);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -13,6 +12,6 @@ public class ListWidgetTest extends GeneralSelectOneWidgetTest<ListWidget> {
@NonNull
@Override
public ListWidget createWidget() {
return new ListWidget(RuntimeEnvironment.application, formEntryPrompt, false, false);
return new ListWidget(activity, formEntryPrompt, false, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.javarosa.core.model.data.DecimalData;
import org.odk.collect.android.widgets.base.RangeWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -15,7 +14,7 @@ public class RangeDecimalWidgetTest extends RangeWidgetTest<RangeDecimalWidget,
@NonNull
@Override
public RangeDecimalWidget createWidget() {
return new RangeDecimalWidget(RuntimeEnvironment.application, formEntryPrompt);
return new RangeDecimalWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.javarosa.core.model.data.IntegerData;
import org.odk.collect.android.widgets.base.RangeWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -15,7 +14,7 @@ public class RangeIntegerWidgetTest extends RangeWidgetTest<RangeIntegerWidget,
@NonNull
@Override
public RangeIntegerWidget createWidget() {
return new RangeIntegerWidget(RuntimeEnvironment.application, formEntryPrompt);
return new RangeIntegerWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -13,6 +12,6 @@ public class SelectMultiWidgetTest extends GeneralSelectMultiWidgetTest<SelectMu
@NonNull
@Override
public SelectMultiWidget createWidget() {
return new SelectMultiWidget(RuntimeEnvironment.application, formEntryPrompt);
return new SelectMultiWidget(activity, formEntryPrompt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -13,6 +12,6 @@ public class SelectOneSearchWidgetTest extends GeneralSelectOneWidgetTest<Select
@NonNull
@Override
public SelectOneSearchWidget createWidget() {
return new SelectOneSearchWidget(RuntimeEnvironment.application, formEntryPrompt, false);
return new SelectOneSearchWidget(activity, formEntryPrompt, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -14,6 +13,6 @@ public class SelectOneWidgetTest extends GeneralSelectOneWidgetTest<AbstractSele
@NonNull
@Override
public SelectOneWidget createWidget() {
return new SelectOneWidget(RuntimeEnvironment.application, formEntryPrompt, false);
return new SelectOneWidget(activity, formEntryPrompt, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.javarosa.core.model.SelectChoice;
import org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.util.List;

Expand All @@ -18,7 +17,7 @@ public class SpinnerMultiWidgetTest extends GeneralSelectMultiWidgetTest<Spinner
@NonNull
@Override
public SpinnerMultiWidget createWidget() {
return new SpinnerMultiWidget(RuntimeEnvironment.application, formEntryPrompt);
return new SpinnerMultiWidget(activity, formEntryPrompt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;

import org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -13,6 +12,6 @@ public class SpinnerWidgetTest extends GeneralSelectOneWidgetTest<SpinnerWidget>
@NonNull
@Override
public SpinnerWidget createWidget() {
return new SpinnerWidget(RuntimeEnvironment.application, formEntryPrompt, false);
return new SpinnerWidget(activity, formEntryPrompt, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.javarosa.core.model.data.StringData;
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;
import org.robolectric.RuntimeEnvironment;

import java.util.Random;

Expand All @@ -21,7 +20,7 @@ public class StringNumberWidgetTest
public StringNumberWidget createWidget() {
Random random = new Random();
boolean useThousandSeparator = random.nextBoolean();
return new StringNumberWidget(RuntimeEnvironment.application, formEntryPrompt, false, useThousandSeparator);
return new StringNumberWidget(activity, formEntryPrompt, false, useThousandSeparator);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.javarosa.core.model.data.StringData;
import org.odk.collect.android.widgets.base.GeneralStringWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -16,7 +15,7 @@ public class StringWidgetTest extends GeneralStringWidgetTest<StringWidget, Stri
@NonNull
@Override
public StringWidget createWidget() {
return new StringWidget(RuntimeEnvironment.application, formEntryPrompt, false);
return new StringWidget(activity, formEntryPrompt, false);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.junit.Test;
import org.mockito.Mock;
import org.odk.collect.android.widgets.base.GeneralDateTimeWidgetTest;
import org.robolectric.RuntimeEnvironment;

import static org.junit.Assert.assertEquals;

Expand All @@ -24,7 +23,7 @@ public class TimeWidgetTest extends GeneralDateTimeWidgetTest<TimeWidget, TimeDa
@NonNull
@Override
public TimeWidget createWidget() {
return new TimeWidget(RuntimeEnvironment.application, formEntryPrompt);
return new TimeWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.javarosa.core.model.data.StringData;
import org.odk.collect.android.widgets.base.QuestionWidgetTest;
import org.robolectric.RuntimeEnvironment;

/**
* @author James Knight
Expand All @@ -16,7 +15,7 @@ public class UrlWidgetTest extends QuestionWidgetTest<UrlWidget, StringData> {
@NonNull
@Override
public UrlWidget createWidget() {
return new UrlWidget(RuntimeEnvironment.application, formEntryPrompt);
return new UrlWidget(activity, formEntryPrompt);
}

@NonNull
Expand Down
Loading

0 comments on commit 3eddbd8

Please sign in to comment.