package org.schoellerfamily.gedbrowser.reader.test;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.schoellerfamily.gedbrowser.datamodel.Root;
import org.schoellerfamily.gedbrowser.reader.CharsetScanner;
import org.schoellerfamily.gedbrowser.reader.testreader.TestDataReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author Dick Schoeller
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestConfiguration.class })
public class CharsetScannerTest {
    /** */
    @Autowired
    private transient TestDataReader reader;

    /** */
    @Test
    public void testFileUTF8() {
        final CharsetScanner scanner = new CharsetScanner();
        assertEquals("Charset mismatch",
                "UTF-8", scanner.charset("mini-schoeller.ged"));
    }

    /** */
    @Test
    public void testFileANSI() {
        final CharsetScanner scanner =
                new CharsetScanner();
        assertEquals("Charset mismatch",
                "Cp1252", scanner.charset("/var/lib/gedbrowser/gl120368.ged"));
    }

    /** */
    @Test
    public void testFileASCII() {
        final CharsetScanner scanner =
                new CharsetScanner();
        assertEquals("Charset mismatch",
                "ASCII", scanner.charset("simple.ged"));
    }

    /** */
    @Test
    public void testFileANSEL() {
        final CharsetScanner scanner =
                new CharsetScanner();
        assertEquals("Charset mismatch",
                "ANSEL", scanner.charset("TGC551LF.ged"));
    }

    /** */
    @Test
    public void testFileANSEL2() {
        final CharsetScanner scanner =
                new CharsetScanner();
        assertEquals("Charset mismatch",
                "ANSEL", scanner.charset("ansel.ged"));
    }

    /**
     * @throws IOException if there is an error reading the file.
     */
    @Test
    public void testRootUTF8() throws IOException {
        final Root root = reader.readFileTestSource("mini-schoeller.ged");
        final CharsetScanner scanner = new CharsetScanner();
        assertEquals("Charset mismatch",
                "UTF-8", scanner.charset(root));
    }

    /**
     * @throws IOException if there is an error reading the file.
     */
    @Test
    public void testRootANSEL2() throws IOException {
        final Root root = reader.readFileTestSource("ansel.ged");
        final CharsetScanner scanner = new CharsetScanner();
        assertEquals("Charset mismatch",
                "ANSEL", scanner.charset(root));
    }
}

@@ -427,16 +427,75 @@
 owired;%0A
+import org.springframework.beans.factory.annotation.Value;%0A
 import o
@@ -548,16 +548,16 @@
 ration;%0A
-
 import o
@@ -862,16 +862,126 @@
 eader;%0A%0A
+    /** */%0A    @Value(%22$%7Bgedbrowser.home:/var/lib/gedbrowser%7D%22)%0A    private transient String gedbrowserHome;%0A%0A
     /** 
@@ -1418,18 +1418,8 @@
 set(
-%22/var/lib/
 gedb
@@ -1424,16 +1424,24 @@
 dbrowser
+Home + %22
 /gl12036

fix test on travis