package yokohama.unit.ast_junit;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.text.StrBuilder;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import yokohama.unit.util.SBuilder;

public class TestMethodTest {
    
    @Test
    public void testImportedNames() {
        TestMethod instance = new TestMethod("test", 
                Arrays.asList(),
                Arrays.asList()
        );
        Set<ImportedName> expected = new HashSet<ImportedName>();
        expected.add(new ImportClass("org.junit.Test"));
        expected.add(new ImportClass("ognl.OgnlContext"));
        Set<ImportedName> actual = instance.importedNames(new OgnlExpressionStrategy());
        assertThat(actual, is(expected));
    }

    @Test
    public void testImportedNames1() {
        TestMethod instance = new TestMethod(
                "test name",
                Arrays.asList(),
                Arrays.asList(new IsStatement("", ""))
        );
        Set<ImportedName> expected = new TreeSet<ImportedName>();
        expected.add(new ImportClass("org.junit.Test"));
        expected.add(new ImportClass("ognl.Ognl"));
        expected.add(new ImportClass("ognl.OgnlContext"));
        expected.add(new ImportClass("org.junit.Assert.assertThat"));
        expected.add(new ImportStatic("org.hamcrest.CoreMatchers.is"));
        Set<ImportedName> actual = instance.importedNames(new OgnlExpressionStrategy());
        assertThat(actual, is(expected));
    }

    @Test
    public void testImportedNames2() {
        TestMethod instance = new TestMethod(
                "test name",
                Arrays.asList(),
                Arrays.asList(new IsStatement("", ""), new IsNotStatement("", ""))
        );
        Set<ImportedName> expected = new TreeSet<ImportedName>();
        expected.add(new ImportClass("org.junit.Test"));
        expected.add(new ImportClass("ognl.Ognl"));
        expected.add(new ImportClass("ognl.OgnlContext"));
        expected.add(new ImportClass("org.junit.Assert.assertThat"));
        expected.add(new ImportStatic("org.hamcrest.CoreMatchers.is"));
        expected.add(new ImportStatic("org.hamcrest.CoreMatchers.not"));
        Set<ImportedName> actual = instance.importedNames(new OgnlExpressionStrategy());
        assertThat(actual, is(expected));
    }

    @Test
    public void testImportedNames3() {
        TestMethod instance = new TestMethod(
                "test name",
                Arrays.asList(),
                Arrays.asList(new IsStatement("", ""), new ThrowsStatement("", ""))
        );
        Set<ImportedName> expected = new TreeSet<ImportedName>();
        expected.add(new ImportClass("org.junit.Test"));
        expected.add(new ImportClass("ognl.Ognl"));
        expected.add(new ImportClass("ognl.OgnlContext"));
        expected.add(new ImportClass("ognl.OgnlException"));
        expected.add(new ImportClass("org.junit.Assert.assertThat"));
        expected.add(new ImportClass("org.junit.Assert.fail"));
        expected.add(new ImportStatic("org.hamcrest.CoreMatchers.instanceOf"));
        expected.add(new ImportStatic("org.hamcrest.CoreMatchers.is"));
        Set<ImportedName> actual = instance.importedNames(new OgnlExpressionStrategy());
        assertThat(actual, is(expected));
    }

    @Test
    public void testToString_SBuilder() {
        SBuilder actual = new SBuilder(4);
        TestMethod instance = new TestMethod("test", Arrays.asList(), Arrays.asList());
        instance.toString(actual, new OgnlExpressionStrategy());

        StrBuilder expected = new StrBuilder();
        expected.appendln("@Test");
        expected.appendln("public void test() throws Exception {");
        expected.appendln("    OgnlContext env = new OgnlContext();");
        expected.appendln("}");

        assertThat(actual.toString(), is(expected.toString()));
    }

    @Test
    public void testToString_SBuilder1() {
        SBuilder actual = new SBuilder(4);
        TestMethod instance = new TestMethod(
                "test",
                Arrays.asList(),
                Arrays.asList(new IsStatement("x", "y")));
        instance.toString(actual, new OgnlExpressionStrategy());

        StrBuilder expected = new StrBuilder();
        expected.appendln("@Test");
        expected.appendln("public void test() throws Exception {");
        expected.appendln("    OgnlContext env = new OgnlContext();");
        expected.appendln("    {");
        expected.appendln("        Object actual = Ognl.getValue(\"x\", env);");
        expected.appendln("        Object expected = Ognl.getValue(\"y\", env);");
        expected.appendln("        assertThat(actual, is(expected));");
        expected.appendln("    }");
        expected.appendln("}");

        assertThat(actual.toString(), is(expected.toString()));
    }

}

@@ -502,32 +502,100 @@
 rays.asList(),%0D%0A
+                Arrays.asList(),%0D%0A                Arrays.asList(),%0D%0A
                 
@@ -611,16 +611,16 @@
 List()%0D%0A
-
         
@@ -1104,32 +1104,66 @@
 rays.asList(),%0D%0A
+                Arrays.asList(),%0D%0A
                 
@@ -1192,32 +1192,66 @@
 atement(%22%22, %22%22))
+,%0D%0A                Arrays.asList()
 %0D%0A        );%0D%0A  
@@ -1926,32 +1926,66 @@
 rays.asList(),%0D%0A
+                Arrays.asList(),%0D%0A
                 
@@ -2042,32 +2042,66 @@
 atement(%22%22, %22%22))
+,%0D%0A                Arrays.asList()
 %0D%0A        );%0D%0A  
@@ -2850,32 +2850,66 @@
 rays.asList(),%0D%0A
+                Arrays.asList(),%0D%0A
                 
@@ -2975,16 +2975,50 @@
 %22%22, %22%22))
+,%0D%0A                Arrays.asList()
 %0D%0A      
@@ -3922,16 +3922,50 @@
 sList(),
+ Arrays.asList(), Arrays.asList(),
  Arrays.
@@ -4619,33 +4619,101 @@
 ist(
-new IsStatement(%22x%22, %22y%22)
+),%0D%0A                Arrays.asList(new IsStatement(%22x%22, %22y%22)),%0D%0A                Arrays.asList(
 ));%0D

Fix arguments for TestMethod constructor