package shoehorn;

import com.google.common.collect.ImmutableMap;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.*;

/**
 * @author Ryan Brainard
 */
public class ShoehornTest {

    @Test
    public void testGetMappings() {
        final String mapFilePath = ClassLoader.getSystemResource("shoehorn.map.test").getPath();
        final Map<String, String> mappings = Shoehorn.getMappings(mapFilePath);

        assertTrue(mappings.containsKey("SOME_KEY"));
        assertEquals("SOME_VALUE", mappings.get("SOME_KEY"));

        assertTrue(mappings.containsKey("BARE_KEY"));
        assertEquals("", mappings.get("BARE_KEY"));

        assertTrue(mappings.containsKey("BARE_KEY_WITH_EQUALS"));
        assertEquals("", mappings.get("BARE_KEY_WITH_EQUALS"));

        assertFalse(mappings.containsKey("MISSING_KEY"));
        assertEquals(null, mappings.get("MISSING_KEY"));
    }

    @Test
    public void testGetMappings_BadFileName() {
        final String mapFilePath = "bad-file-name";
        final Map<String, String> mappings = Shoehorn.getMappings(mapFilePath);

        assertTrue(mappings.isEmpty());
    }

    @Test
    public void testShoehorn() throws Exception {
        final Map<String, String> feet = ImmutableMap.of("ORIGINAL_KEY_A", "ORIGINAL_VALUE_A",
                "ORIGINAL_KEY_B", "ORIGINAL_VALUE_B",
                "ORIGINAL_KEY_C", "ORIGINAL_VALUE_C");

        final Map<String, String> mappings = ImmutableMap.of("ORIGINAL_KEY_B", "",
                "ORIGINAL_KEY_C", "NEW_KEY_C");

        final Shoehorn shoehorn = new Shoehorn(feet, mappings);

        shoehorn.shoehorn();

        assertEquals("Unmapped key should not be shoe horned", null, System.getProperty("ORIGINAL_KEY_A"));
        assertEquals("Bare key should be shoe horned as is", "ORIGINAL_VALUE_B", System.getProperty("ORIGINAL_KEY_B"));
        assertEquals("Mapped key should be shoe horned to new key", "ORIGINAL_VALUE_C", System.getProperty("NEW_KEY_C"));
        assertEquals("Mapped key should be shoe horned to new key", null, System.getProperty("ORIGINAL_KEY_C"));
    }
}

@@ -1180,16 +1180,28 @@
 Shoehorn
+_UnmappedKey
 () throw
@@ -1226,418 +1226,259 @@
     
-final Map%3CString, String%3E feet = ImmutableMap.of(%22ORIGINAL_KEY_A%22, %22ORIGINAL_VALUE_A%22,%0A                %22ORIGINAL_KEY_B%22, %22ORIGINAL_VALUE_B%22,%0A                %22ORIGINAL_KEY_C%22, %22ORIGINAL_VALUE_C%22);%0A%0A        final Map%3CString, String%3E mappings = ImmutableMap.of(%22ORIGINAL_KEY_B%22, %22%22,%0A                %22ORIGINAL_KEY_C%22, %22NEW_KEY_C%22);%0A%0A        final Shoehorn shoehorn = new Shoehorn(feet, mappings);%0A%0A        shoehorn
+createShoehornFixture().shoehorn();%0A%0A        assertEquals(%22Unmapped key should not be shoe horned%22, null, System.getProperty(%22ORIGINAL_KEY_A%22));%0A    %7D%0A%0A    @Test%0A    public void testShoehorn_BareKey() throws Exception %7B%0A        createShoehornFixture()
 .sho
@@ -1505,32 +1505,28 @@
 sertEquals(%22
-Unmapped
+Bare
  key should 
@@ -1517,36 +1517,32 @@
 Bare key should 
-not 
 be shoe horned%22,
@@ -1531,39 +1531,59 @@
 d be shoe horned
-%22, null
+ as is%22, %22ORIGINAL_VALUE_B%22
 , System.getProp
@@ -1593,33 +1593,33 @@
 y(%22ORIGINAL_KEY_
-A
+B
 %22));%0A        ass
@@ -1615,124 +1615,126 @@
     
+%7D%0A%0A
     
-assertEquals(%22Bare key should be s
+@Test%0A    public void testS
 hoe
- 
 horn
-ed as is%22, %22ORIGINAL_VALUE_B%22, System.getProperty(%22ORIGINAL_KEY_B%22)
+_MappedKey() throws Exception %7B%0A        createShoehornFixture().shoehorn(
 );%0A
+%0A
     
@@ -1969,11 +1969,454 @@
 );%0A    %7D
+%0A%0A    private static Shoehorn createShoehornFixture() %7B%0A        final Map%3CString, String%3E feet = ImmutableMap.of(%22ORIGINAL_KEY_A%22, %22ORIGINAL_VALUE_A%22,%0A                %22ORIGINAL_KEY_B%22, %22ORIGINAL_VALUE_B%22,%0A                %22ORIGINAL_KEY_C%22, %22ORIGINAL_VALUE_C%22);%0A%0A        final Map%3CString, String%3E mappings = ImmutableMap.of(%22ORIGINAL_KEY_B%22, %22%22,%0A                %22ORIGINAL_KEY_C%22, %22NEW_KEY_C%22);%0A%0A        return new Shoehorn(feet, mappings);%0A    %7D
 %0A%7D%0A

break out tests into separate methods