package net.sf.mockcreator.codegeneration;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import net.sf.mockcreator.TestCase;
import net.sf.mockcreator.codegeneration.FormattingOutputWriter;
public class FormattingOutputWriterTest extends TestCase {
public FormattingOutputWriterTest(String name) {
super(name);
}
ByteArrayOutputStream baos;
FormattingOutputWriter fos;
public void setUp() throws Exception {
baos = new ByteArrayOutputStream();
Writer wr = new OutputStreamWriter(baos);
fos = new FormattingOutputWriter(wr);
}
public String print(String s) throws IOException {
fos.write(s.toCharArray(),0,s.length());
fos.close();
// System.out.println("for =====\n"+s+"\n ===== we got \n"+baos.toString()+"\n =====\n\n\n");
return baos.toString();
}
public void testNoBrackets() throws IOException {
check("s1;\ns2;","s1;\ns2;\n");
}
public void testBracketsOnly() throws IOException {
check("a {}","a {\n}");
}
public void testNestedBracketsOnly() throws IOException {
check("{{}}","{\n {\n }\n}");
}
public void testNoSpaces() throws IOException {
check("s1{s2{s3;s4;}}","s1{\n s2{\n s3;\n s4;\n }\n}");
}
public void testSpaces() throws IOException {
check("s1{ s2{ s3; s4; } }","s1{\n s2{\n s3;\n s4;\n } \n}");
}
public void testLineBreaks() throws IOException {
check("s1\n{s2{s3;}}","s1{\n s2{\n s3;\n }\n}");
}
public void testTwoMethods() throws IOException {
check("a(){}\n\nb(){}","a(){\n}\nb(){\n}");
}
public void testTwoMethodsAndContent() throws IOException {
check("a(){c;}\n\nb(){d;}","a(){\n c;\n}\nb(){\n d;\n}");
}
public void testComment() throws IOException {
check("// a;{}\nwhat? // h;\n{}","// a;{}\nwhat? // h;\n{\n}");
}
private void check(String src,String exp) throws IOException {
String dst = print(src);
assertEquals(exp,dst);
}
}
|