package bluej.collect;
import junit.framework.TestCase;
import bluej.utility.Utility;
public class TestAnonymisation
extends TestCase{
private static String combineLines(String[] lines)
{
StringBuilder s = new StringBuilder();
for (String line : lines)
{
s.append(line).append("\n");
}
return s.toString();
}
private static void assertAutoAnon(String[] input)
{
assertAnon(input, input);
}
private static void assertAnon(String[] input, String[] expectedOutput)
{
String[] actualOutput = Utility.splitLines(CodeAnonymiser.anonymise(combineLines(input)));
assertEquals(expectedOutput.length, actualOutput.length);
for (int i = 0; i < expectedOutput.length; i++)
{
assertEquals("Line " + i + " differs", expectedOutput[i], actualOutput[i]);
}
}
public void test1()
{
assertAutoAnon(new String[] {
"class Foo",
"{",
"}"});
assertAutoAnon(new String[] {
" class Foo",
"{",
"}"});
}
public void test2()
{
assertAutoAnon(new String[] {
" import bar;",
"",
"class Foo",
"{",
"}"});
}
public void test3()
{
assertAnon(new String[] {
" import bar;",
"/** Some comment",
"*/",
"class Foo",
"{",
"}"},
new String[] {
" import bar;",
"/** #### #######",
"*/",
"class Foo",
"{",
"}"});
}
public void test3B()
{
assertAnon(new String[] {
"import bar;",
"/** Some comment == something + blah - 6",
"*/",
"class Foo",
"{",
"}"},
new String[] {
"import bar;",
"/** #### ####### == ######### + #### - #",
"*/",
"class Foo",
"{",
"}"});
}
public void test4()
{
assertAnon(new String[] {
"/* Blah */ import bar;",
"/** Some comment",
"*/",
"class Foo",
"{",
"}"},
new String[] {
"/* #### */ import bar;",
"/** #### #######",
"*/",
"class Foo",
"{",
"}"});
}
public void test5()
{
assertAnon(new String[] {
"/* Blah */ import bar;",
"/** Some comment",
"*/",
"Foo"
},
new String[] {
"/* #### */ import bar;",
"/** #### #######",
"*/",
"Foo"});
}
public void test6()
{
assertAnon(new String[] {
"/* Blah */ /** Fiver */ import bar;",
"/** Some comment",
"*/",
"Foo"
},
new String[] {
"/* #### */ /** ##### */ import bar;",
"/** #### #######",
"*/",
"Foo"});
}
}
top,
use,
map,
class TestAnonymisation
. combineLines
. assertAutoAnon
. assertAnon
. test1
. test2
. test3
. test3B
. test4
. test5
. test6
161 neLoCode
+ 0 LoComm