Skip to content

Commit

Permalink
Merge pull request #346 from openxc/update-test-unit-library
Browse files Browse the repository at this point in the history
Migrate openxc-android project to Androidx which supports the the tes…
  • Loading branch information
jstoke53 authored Mar 2, 2020
2 parents 697e712 + 7b445a5 commit 5dabfd1
Show file tree
Hide file tree
Showing 21 changed files with 795 additions and 798 deletions.
2 changes: 1 addition & 1 deletion enabler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ android {

dependencies {
implementation project(":library")
implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'com.bugsnag:bugsnag-android:4.3.2'
implementation 'com.microsoft.appcenter:appcenter-analytics:2.3.0'
implementation 'com.microsoft.appcenter:appcenter-crashes:2.3.0'
Expand Down
100 changes: 50 additions & 50 deletions enabler/src/androidTest/java/com/openxc/SupportSettingsUtilsTests.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
//package com.openxc;
//
//import java.util.HashSet;
//import java.util.Set;
//
//import android.content.SharedPreferences;
//import android.preference.PreferenceManager;
//import android.test.ServiceTestCase;
//import android.test.suitebuilder.annotation.SmallTest;
//
//import com.openxc.util.SupportSettingsUtils;
//
//public class SupportSettingsUtilsTests extends ServiceTestCase<VehicleManager> {
// SharedPreferences preferences;
// Set<String> value;
// String key = "mykey";
//
// public SupportSettingsUtilsTests() {
// super(VehicleManager.class);
// }
//
// @Override
// protected void setUp() throws Exception {
// super.setUp();
// preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
// SharedPreferences.Editor editor = preferences.edit();
// editor.clear();
// editor.commit();
// value = new HashSet<String>();
// value.add("abcd");
// value.add("1234");
// value.add("zxy");
// }
//
// @SmallTest
// public void testStoreRetreiveStringSet() {
// SharedPreferences.Editor editor = preferences.edit();
// SupportSettingsUtils.putStringSet(editor, key, value);
// editor.commit();
// assertEquals(value, SupportSettingsUtils.getStringSet(
// preferences, key, new HashSet<String>()));
// }
//
// @SmallTest
// public void testRetreiveInvalidKeyStringSet() {
// assertEquals(new HashSet<String>(), SupportSettingsUtils.getStringSet(
// preferences, key, new HashSet<String>()));
// }
//}
//
package com.openxc;

import java.util.HashSet;
import java.util.Set;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.ServiceTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.openxc.util.SupportSettingsUtils;

public class SupportSettingsUtilsTests extends ServiceTestCase<VehicleManager> {
SharedPreferences preferences;
Set<String> value;
String key = "mykey";

public SupportSettingsUtilsTests() {
super(VehicleManager.class);
}

@Override
protected void setUp() throws Exception {
super.setUp();
preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
value = new HashSet<String>();
value.add("abcd");
value.add("1234");
value.add("zxy");
}

@SmallTest
public void testStoreRetreiveStringSet() {
SharedPreferences.Editor editor = preferences.edit();
SupportSettingsUtils.putStringSet(editor, key, value);
editor.commit();
assertEquals(value, SupportSettingsUtils.getStringSet(
preferences, key, new HashSet<String>()));
}

@SmallTest
public void testRetreiveInvalidKeyStringSet() {
assertEquals(new HashSet<String>(), SupportSettingsUtils.getStringSet(
preferences, key, new HashSet<String>()));
}
}

80 changes: 40 additions & 40 deletions enabler/src/androidTest/java/com/openxc/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
//package com.openxc;
//
//import static org.junit.Assert.*;
//
//import java.io.File;
//import java.io.IOException;
//import java.net.URI;
//import java.net.URISyntaxException;
//
//import org.apache.commons.io.FileUtils;
//
//import android.content.Context;
//
//public class TestUtils {
// public static void pause(int millis) {
// try {
// Thread.sleep(millis);
// } catch(InterruptedException e) {}
// }
//
// public static URI copyToStorage(Context context, int resource,
// String filename) {
// URI uri = null;
// try {
// uri = new URI("file:///sdcard/com.openxc/" + filename);
// } catch(URISyntaxException e) {
// fail("Couldn't construct resource URIs: " + e);
// }
//
// try {
// FileUtils.copyInputStreamToFile(
// context.getResources().openRawResource(resource),
// new File(uri));
// } catch(IOException e) {
// fail("Couldn't copy trace files to SD card" + e);
// }
// return uri;
// }
//
//}
package com.openxc;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.commons.io.FileUtils;

import android.content.Context;

public class TestUtils {
public static void pause(int millis) {
try {
Thread.sleep(millis);
} catch(InterruptedException e) {}
}

public static URI copyToStorage(Context context, int resource,
String filename) {
URI uri = null;
try {
uri = new URI("file:///sdcard/com.openxc/" + filename);
} catch(URISyntaxException e) {
fail("Couldn't construct resource URIs: " + e);
}

try {
FileUtils.copyInputStreamToFile(
context.getResources().openRawResource(resource),
new File(uri));
} catch(IOException e) {
fail("Couldn't copy trace files to SD card" + e);
}
return uri;
}

}
Loading

0 comments on commit 5dabfd1

Please sign in to comment.