提交 665c4985 编写于 作者: R René Scheibe

don't extend a test class from org.junit.Assert to use its static methods

* to simplify the static import and test use Hamcrest to compare arrays
* no need to box boolean[] to Boolean[] when using Hamcrest
上级 13ab787d
......@@ -23,6 +23,7 @@
*/
package hudson.util;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import java.io.IOException;
......@@ -30,23 +31,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
public class ArgumentListBuilderTest extends Assert {
public static void assertArrayEquals(String msg, boolean[] expected, boolean[] actual) {
assertArrayEquals(msg,box(expected),box(actual));
}
private static Boolean[] box(boolean[] a) {
if(a==null) return null;
Boolean[] r = new Boolean[a.length];
for (int i = 0; i < a.length; i++)
r[i] = a[i];
return r;
}
public class ArgumentListBuilderTest {
@Test
public void assertEmptyMask() {
......@@ -57,7 +44,7 @@ public class ArgumentListBuilderTest extends Assert {
assertFalse("There shouldnt be any masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,false,false}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, false, false }));
}
@Test
......@@ -69,7 +56,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,true}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, true }));
}
@Test
......@@ -83,7 +70,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,true, false, true}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, true, false, true }));
}
@Test
......@@ -96,7 +83,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,false,true,false}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, false, true, false }));
}
@Test
......@@ -109,7 +96,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,false,true,false}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, false, true, false }));
}
@Test
......@@ -123,21 +110,19 @@ public class ArgumentListBuilderTest extends Assert {
"-Dfoo8=% %QED% %comspec% %-%(%.%", // add quotes, and extra quotes for %Q and %c
"-Dfoo9=%'''%%@%"); // no quotes as none of the % are followed by a letter
// By default, does not escape %VAR%
assertArrayEquals(new String[] { "cmd.exe", "/C",
assertThat(builder.toWindowsCommand().toCommandArray(), is(new String[] { "cmd.exe", "/C",
"\"ant.bat -Dfoo1=abc \"-Dfoo2=foo bar\""
+ " \"-Dfoo3=/u*r\" \"-Dfoo4=/us?\" \"-Dfoo10=bar,baz\" \"-Dfoo5=foo;bar^baz\""
+ " \"-Dfoo6=<xml>&here;</xml>\" \"-Dfoo7=foo|bar\"\"baz\""
+ " \"-Dfoo8=% %QED% %comspec% %-%(%.%\""
+ " -Dfoo9=%'''%%@% && exit %%ERRORLEVEL%%\"" },
builder.toWindowsCommand().toCommandArray());
+ " -Dfoo9=%'''%%@% && exit %%ERRORLEVEL%%\"" }));
// Pass flag to escape %VAR%
assertArrayEquals(new String[] { "cmd.exe", "/C",
assertThat(builder.toWindowsCommand(true).toCommandArray(), is(new String[] { "cmd.exe", "/C",
"\"ant.bat -Dfoo1=abc \"-Dfoo2=foo bar\""
+ " \"-Dfoo3=/u*r\" \"-Dfoo4=/us?\" \"-Dfoo10=bar,baz\" \"-Dfoo5=foo;bar^baz\""
+ " \"-Dfoo6=<xml>&here;</xml>\" \"-Dfoo7=foo|bar\"\"baz\""
+ " \"-Dfoo8=% %\"Q\"ED% %\"c\"omspec% %-%(%.%\""
+ " -Dfoo9=%'''%%@% && exit %%ERRORLEVEL%%\"" },
builder.toWindowsCommand(true).toCommandArray());
+ " -Dfoo9=%'''%%@% && exit %%ERRORLEVEL%%\"" }));
}
@Test
......@@ -151,7 +136,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", clone.hasMaskedArguments());
boolean[] array = clone.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", builder.toMaskArray(), array);
assertThat("The mask array was incorrect", array, is(builder.toMaskArray()));
}
private static final Map<String, String> KEY_VALUES = new HashMap<String, String>() {{
......@@ -172,7 +157,7 @@ public class ArgumentListBuilderTest extends Assert {
assertTrue("There should be masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,true,false}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, true, false }));
}
......@@ -184,7 +169,7 @@ public class ArgumentListBuilderTest extends Assert {
assertFalse("There shouldnt be any masked arguments", builder.hasMaskedArguments());
boolean[] array = builder.toMaskArray();
assertNotNull("The mask array should not be null", array);
assertArrayEquals("The mask array was incorrect", new boolean[]{false,false,false}, array);
assertThat("The mask array was incorrect", array, is(new boolean[] { false, false, false }));
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册