mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-10 12:09:27 +01:00
Enable LoggingTest with robolectric
This commit is contained in:
parent
c93186cc56
commit
bcb07ccacd
@ -6,10 +6,7 @@ def ABORT_ON_CHECK_FAILURE=false
|
||||
|
||||
tasks.withType(Test) { systemProperty 'MiFirmwareDir', System.getProperty('MiFirmwareDir', null) }
|
||||
|
||||
// sourceSets.test.runtimeClasspath += File('src/main/assets')
|
||||
|
||||
android {
|
||||
|
||||
compileOptions {
|
||||
// for KitKat
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
|
@ -138,7 +138,7 @@ public class FileUtils {
|
||||
File[] dirs;
|
||||
try {
|
||||
dirs = context.getExternalFilesDirs(null);
|
||||
} catch (NullPointerException ex) {
|
||||
} catch (NullPointerException | UnsupportedOperationException ex) {
|
||||
// workaround for robolectric 3.1.2 not implementinc getExternalFilesDirs()
|
||||
// https://github.com/robolectric/robolectric/issues/2531
|
||||
File dir = context.getExternalFilesDir(null);
|
||||
|
@ -2,48 +2,55 @@ package nodomain.freeyourgadget.gadgetbridge.test;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests dynamic enablement and disablement of file appenders.
|
||||
* Test is currently disabled because logback-android does not work
|
||||
* inside a plain junit test.
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(constants = BuildConfig.class, sdk = 19)
|
||||
// need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java
|
||||
public class LoggingTest {
|
||||
|
||||
private static File logFilesDir;
|
||||
|
||||
public LoggingTest() throws Exception {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupSuite() {
|
||||
System.setProperty("logback.configurationFile", "logback.xml");
|
||||
public static void setupSuite() throws Exception {
|
||||
logFilesDir = FileUtils.createTempDir("logfiles");
|
||||
System.setProperty(Logging.PROP_LOGFILES_DIR, logFilesDir.getAbsolutePath());
|
||||
File workingDir = new File(System.getProperty("user.dir"));
|
||||
File configFile = new File(workingDir, "src/main/assets/logback.xml");
|
||||
System.out.println(configFile.getAbsolutePath());
|
||||
System.setProperty("logback.configurationFile", configFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
private Logging logging = new Logging() {
|
||||
@Override
|
||||
protected String createLogDirectory() throws IOException {
|
||||
File dir = ensureLogFilesDir();
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private File ensureLogFilesDir() throws IOException {
|
||||
return FileUtils.createTempDir("logfiles");
|
||||
return logFilesDir.getAbsolutePath();
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,7 +74,7 @@ public class LoggingTest {
|
||||
public void testToggleLogging() {
|
||||
try {
|
||||
File dir = getLogFilesDir();
|
||||
} catch (AssertionFailedError ignored) {
|
||||
} catch (AssertionError ignored) {
|
||||
// expected, as not yet set up
|
||||
}
|
||||
|
||||
@ -85,7 +92,7 @@ public class LoggingTest {
|
||||
logging.setupLogging(true);
|
||||
assertNotNull(logging.getFileLogger());
|
||||
assertTrue(logging.getFileLogger().isStarted());
|
||||
} catch (AssertionFailedError ex) {
|
||||
} catch (AssertionError ex) {
|
||||
logging.debugLoggingConfiguration();
|
||||
System.err.println(System.getProperty("java.class.path"));
|
||||
throw ex;
|
||||
|
Loading…
Reference in New Issue
Block a user