package nodomain.freeyourgadget.gadgetbridge.test;

import android.support.annotation.NonNull;

import org.junit.After;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import nodomain.freeyourgadget.gadgetbridge.Logging;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;

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.
 */
public class LoggingTest extends TestBase {

    public LoggingTest() throws Exception {
    }

    private Logging logging = new Logging() {
        @Override
        protected String createLogDirectory() throws IOException {
            return logFilesDir.getAbsolutePath();
        }
    };

    @After
    public void tearDown() {
        assertTrue(FileUtils.deleteRecursively(getLogFilesDir()));
    }

    @NonNull
    private File getLogFilesDir() {
        String dirName = System.getProperty(Logging.PROP_LOGFILES_DIR);
        if (dirName != null && dirName.length() > 5) {
            File dir = new File(dirName);
            return dir;
        }
        fail("Property " + Logging.PROP_LOGFILES_DIR + " has invalid value: " + dirName);
        return null; // not reached
    }

    @Test
    public void testToggleLogging() {
        try {
            File dir = getLogFilesDir();
        } catch (AssertionError ignored) {
            // expected, as not yet set up
        }

        try {
            logging.setupLogging(true);
            File dir = getLogFilesDir();
            assertEquals(1, dir.list().length);
            assertNotNull(logging.getFileLogger());
            assertTrue(logging.getFileLogger().isStarted());

            logging.setupLogging(false);
            assertNotNull(logging.getFileLogger());
            assertFalse(logging.getFileLogger().isStarted());

            logging.setupLogging(true);
            assertNotNull(logging.getFileLogger());
            assertTrue(logging.getFileLogger().isStarted());
        } catch (AssertionError ex) {
            logging.debugLoggingConfiguration();
            System.err.println(System.getProperty("java.class.path"));
            throw ex;
        }
    }
}

@@ -588,106 +588,8 @@
 rs.%0A
- * Test is currently disabled because logback-android does not work%0A * inside a plain junit test.%0A
  */%0A

Remove outdated comment