Skip to content

Commit

Permalink
Migrate to AndroidX libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Aug 24, 2019
1 parent 29fac1e commit 9393db7
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 60 deletions.
31 changes: 21 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
apply plugin: 'com.android.application'

dependencies {
implementation 'joda-time:joda-time:2.10.3'
implementation project(':colorpicker')
implementation 'com.android.support:appcompat-v7:28.0.0'
}

android {
compileSdkVersion 28
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

useLibrary 'android.test.runner'

useLibrary 'android.test.base'
useLibrary 'android.test.mock'

defaultConfig {
versionCode getCommitCount()
versionName '2.2.0' + "-" + versionCode
minSdkVersion 15
targetSdkVersion 28
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion

testApplicationId "org.andstatus.todoagenda.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
project.ext.archivesBaseName = "TodoAgenda-$versionName".toString()
}

Expand Down Expand Up @@ -56,6 +56,17 @@ android {
}
}

dependencies {
implementation "joda-time:joda-time:$jodaTimeVersion"
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation project(':colorpicker')

androidTestImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
}

static getCommitCount() {
try {
def git = org.ajoberstar.grgit.Grgit.open()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.andstatus.todoagenda;

import android.test.InstrumentationTestCase;

import org.andstatus.todoagenda.provider.MockCalendarContentProvider;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Before;

import static org.junit.Assert.assertTrue;

/**
* @author [email protected]
*/
public class BaseWidgetTest extends InstrumentationTestCase {
public class BaseWidgetTest {

final String TAG = this.getClass().getSimpleName();

Expand All @@ -19,18 +21,16 @@ protected int getNumberOfOpenTasksSources() {
return 0;
}

@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
provider = MockCalendarContentProvider.getContentProvider(this, getNumberOfOpenTasksSources());
factory = new EventRemoteViewsFactory(provider.getContext(), provider.getWidgetId());
assertTrue(factory.getWidgetEntries().isEmpty());
}

@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
provider.tearDown();
super.tearDown();
}

DateTime dateTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.joda.time.DateTime;
import org.json.JSONException;
import org.junit.Test;

import java.io.IOException;

import androidx.test.platform.app.InstrumentationRegistry;

import static org.junit.Assert.assertEquals;

/**
* @author [email protected]
*/
public class BirthdayTest extends BaseWidgetTest {

@Test
public void testBirthdayOneDayOnly() throws IOException, JSONException {
QueryResultsStorage inputs = provider.loadResults(this.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.birthday);

provider.startEditing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
* @author [email protected]
*/
Expand All @@ -28,6 +32,7 @@ public class IllegalInstantDueToTimeZoneTransitionTest extends BaseWidgetTest {
* <p>
* I couldn't reproduce the problem though.
*/
@Test
public void testIllegalInstantDueToTimeZoneOffsetTransition() {
reproducedTimeZoneOffsetTransitionException();
oneTimeDst("2014-09-07T00:00:00+00:00");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
import org.andstatus.todoagenda.widget.WidgetEntry;
import org.joda.time.DateTime;
import org.json.JSONException;
import org.junit.Test;

import java.io.IOException;

import androidx.test.platform.app.InstrumentationRegistry;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
* @author [email protected]
*/
public class MultidayAllDayEventTest extends BaseWidgetTest {

@Test
public void testInsidePeriod() throws IOException, JSONException {
final String method = "testInsidePeriod";
QueryResultsStorage inputs = provider.loadResults(this.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.multi_day);
provider.addResults(inputs.getResults());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.andstatus.todoagenda.widget.WidgetEntry;
import org.joda.time.DateTime;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* @author [email protected]
Expand All @@ -20,6 +27,7 @@ public class MultidayEventTest extends BaseWidgetTest {
/**
* Issue #206 https://github.com/plusonelabs/calendar-widget/issues/206
*/
@Test
public void testEventWhichCarryOverToTheNextDay() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
Expand Down Expand Up @@ -64,6 +72,7 @@ public void testEventWhichCarryOverToTheNextDay() {
/**
* https://github.com/plusonelabs/calendar-widget/issues/184#issuecomment-142671469
*/
@Test
public void testThreeDaysEvent() {
DateTime friday = dateTime(2015, 9, 18);
DateTime sunday = friday.plusDays(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.andstatus.todoagenda.widget.WidgetEntry;
import org.joda.time.DateTime;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* @author [email protected]
Expand All @@ -16,6 +22,7 @@ public class OngoingEventTest extends BaseWidgetTest {
/**
* @see <a href="https://github.com/plusonelabs/calendar-widget/issues/199">Issue 199</a>
*/
@Test
public void testTodaysOngoingEvent() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
Expand Down Expand Up @@ -45,6 +52,7 @@ public void testTodaysOngoingEvent() {
/**
* @see <a href="https://github.com/plusonelabs/calendar-widget/issues/199">Issue 199</a>
*/
@Test
public void testYesterdaysOngoingEvent() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
Expand Down Expand Up @@ -73,6 +81,7 @@ public void testYesterdaysOngoingEvent() {
assertEquals("End Time didn't change for yesterday's event", event.getEndDate(), entry.getEndDate());
}

@Test
public void testEventWhichCarryOverToTheNextDay() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.andstatus.todoagenda.widget.TaskEntry;
import org.json.JSONException;
import org.junit.Test;

import java.io.IOException;

import androidx.test.platform.app.InstrumentationRegistry;

import static org.junit.Assert.assertEquals;

/**
* @author [email protected]
*/
Expand All @@ -23,9 +28,10 @@ protected int getNumberOfOpenTasksSources() {
/**
* https://github.com/plusonelabs/calendar-widget/issues/205
*/
@Test
public void testPastDueHeaderWithTasks() throws IOException, JSONException {
final String method = "testPastDueHeaderWithTasks";
QueryResultsStorage inputs = provider.loadResults(this.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.past_due_header_with_tasks);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.andstatus.todoagenda.widget.WidgetEntry;
import org.joda.time.DateTime;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

/**
* @author [email protected]
*/
Expand All @@ -20,6 +23,7 @@ public class RecurringEventsTest extends BaseWidgetTest {
* @see <a href="https://github.com/plusonelabs/calendar-widget/issues/191">Issue 191</a> and
* <a href="https://github.com/plusonelabs/calendar-widget/issues/46">Issue 46</a>
*/
@Test
public void testShowRecurringEvents() {
generateEventInstances();
assertEquals("Entries: " + factory.getWidgetEntries().size(), 15, countCalendarEntries());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import org.andstatus.todoagenda.widget.WidgetEntry;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;

/**
* @author [email protected]
Expand All @@ -14,6 +19,7 @@ public class SingleEventTest extends BaseWidgetTest {

private int eventId = 0;

@Test
public void testEventAttributes() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
DateUtil.setNow(today.plusHours(10));
Expand All @@ -35,6 +41,7 @@ public void testEventAttributes() {
assertOneEvent(event, true);
}

@Test
public void testAlldayEventAttributes() {
DateTime today = DateUtil.now(provider.getSettings().getTimeZone()).withTimeAtStartOfDay();
DateUtil.setNow(today.plusHours(10));
Expand All @@ -53,6 +60,7 @@ public void testAlldayEventAttributes() {
}


@Test
public void testAlldayEventMillis() {
DateTime today = DateUtil.now(DateTimeZone.UTC).withTimeAtStartOfDay();
CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import org.andstatus.todoagenda.provider.QueryResultsStorage;
import org.andstatus.todoagenda.widget.CalendarEntry;
import org.json.JSONException;
import org.junit.Test;

import java.io.IOException;

import androidx.test.platform.app.InstrumentationRegistry;

import static org.junit.Assert.assertEquals;

/**
* @author [email protected]
*/
Expand All @@ -16,9 +21,10 @@ public class WrongDatesLostEventsTest extends BaseWidgetTest {
/**
* https://github.com/plusonelabs/calendar-widget/issues/205
*/
@Test
public void testIssue205() throws IOException, JSONException {
final String method = "testIssue205";
QueryResultsStorage inputs = provider.loadResults(this.getInstrumentation().getContext(),
QueryResultsStorage inputs = provider.loadResults(InstrumentationRegistry.getInstrumentation().getContext(),
org.andstatus.todoagenda.tests.R.raw.wrong_dates_lost_events);
provider.addResults(inputs.getResults());
Log.d(method, "Results executed at " + inputs.getResults().get(0).getExecutedAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import android.test.InstrumentationTestCase;

import org.junit.Test;

/**
* @author [email protected]
*/
public class KeywordsFilterTest extends InstrumentationTestCase {

@Test
public void testPhrases() {
String query = "\"do it\"";
final String keywordDN = "do it";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.RawRes;
import android.test.IsolatedContext;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
Expand All @@ -32,6 +30,10 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import androidx.annotation.NonNull;
import androidx.annotation.RawRes;
import androidx.test.platform.app.InstrumentationRegistry;

import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_ID;
import static org.andstatus.todoagenda.provider.QueryResultsStorage.KEY_SETTINGS;

Expand All @@ -53,7 +55,7 @@ public class MockCalendarContentProvider extends MockContentProvider {

public static MockCalendarContentProvider getContentProvider(BaseWidgetTest testCase, int numberOfOpenTasksSources) throws JSONException {
MockContentResolver mockResolver = new MockContentResolver();
Context targetContext = testCase.getInstrumentation().getTargetContext();
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
Context isolatedContext = new IsolatedContext(mockResolver, targetContext);
MockCalendarContentProvider contentProvider =
new MockCalendarContentProvider(targetContext, isolatedContext, numberOfOpenTasksSources);
Expand Down
Loading

0 comments on commit 9393db7

Please sign in to comment.