package org.jetbrains.kotlin.android.xmlconverter;

import org.junit.Rule;
import org.junit.rules.TestName;
import sun.plugin.dom.exception.InvalidStateException;
import java.io.File;

import static kotlin.collections.SetsKt.*;
import static kotlin.io.FilesKt.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BaseXmlConverterTest {

    @Rule
    public TestName name = new TestName();

    protected void doLayoutTest() {
        File testDataDir = new File("xml-converter/testData");
        String testName = name.getMethodName();
        if (!testName.startsWith("test")) {
            throw new InvalidStateException("Test name must start with a 'test' preffix");
        }

        File testDir = new File(testDataDir, decapitalize(testName.substring("test".length())));
        File inputFile = new File(testDir, "layout.xml");
        File outputFile = new File(testDir, "layout.kt");

        assertTrue(inputFile + " does not exist", inputFile.exists());
        assertTrue(outputFile + " does not exist", outputFile.exists());

        String actual = XmlConverter.INSTANCE.convert(readText(inputFile, "UTF-8"), setOf("raw"));
        String expected = readText(outputFile, "UTF-8");

        assertEquals(expected, actual);
    }

    private String decapitalize(String original) {
        if (original.isEmpty()) return original;
        return Character.toLowerCase(original.charAt(0)) + original.substring(1);
    }

}

@@ -45,16 +45,45 @@
 erter;%0A%0A
+import kotlin.text.Charsets;%0A
 import o
@@ -1191,23 +1191,30 @@
 utFile, 
-%22UTF-8%22
+Charsets.UTF_8
 ), setOf
@@ -1274,15 +1274,22 @@
 le, 
-%22UTF-8%22
+Charsets.UTF_8
 );%0A%0A

Fix compilation error with Kotlin 1.0