Skip to content

Commit

Permalink
Converting to JUnit 4 thus fixing [JENKINS-14641] and also fixing tes…
Browse files Browse the repository at this point in the history
…t(Html)Escape which didn't ran previously because of wrong case
  • Loading branch information
kutzi committed Aug 26, 2012
1 parent 9522c60 commit d501781
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/src/test/java/hudson/UtilTest.java
Expand Up @@ -24,24 +24,25 @@
*/
package hudson;

import junit.framework.TestCase;

import java.util.Map;
import java.util.HashMap;
import java.util.Locale;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;

import static org.junit.Assert.*;
import org.junit.Assume;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;

import hudson.util.StreamTaskListener;

/**
* @author Kohsuke Kawaguchi
*/
public class UtilTest extends TestCase {
public class UtilTest {
@Test
public void testReplaceMacro() {
Map<String,String> m = new HashMap<String,String>();
m.put("A","a");
Expand Down Expand Up @@ -71,7 +72,7 @@ public void testReplaceMacro() {
assertEquals("$$aa$Ba${A}$it", Util.replaceMacro("$$$DOLLAR${AA}$$B${ENCLOSED}$it",m));
}


@Test
public void testTimeSpanString() {
// Check that amounts less than 365 days are not rounded up to a whole year.
// In the previous implementation there were 360 days in a year.
Expand Down Expand Up @@ -115,6 +116,7 @@ public void testTimeSpanString() {
/**
* Test that Strings that contain spaces are correctly URL encoded.
*/
@Test
public void testEncodeSpaces() {
final String urlWithSpaces = "http://hudson/job/Hudson Job";
String encoded = Util.encode(urlWithSpaces);
Expand All @@ -124,6 +126,7 @@ public void testEncodeSpaces() {
/**
* Test that Strings that contain ampersand are correctly URL encoded.
*/
@Test
public void testEncodeAmpersand() {
final String urlWithAmpersand = "http://hudson/job/Hudson-job/label1&&label2";
String encoded = Util.encode(urlWithAmpersand);
Expand All @@ -133,6 +136,7 @@ public void testEncodeAmpersand() {
/**
* Test the rawEncode() method.
*/
@Test
public void testRawEncode() {
String[] data = { // Alternating raw,encoded
"abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz",
Expand All @@ -150,15 +154,17 @@ public void testRawEncode() {
/**
* Test the tryParseNumber() method.
*/
@Test
public void testTryParseNumber() {
assertEquals("Successful parse did not return the parsed value", 20, Util.tryParseNumber("20", 10).intValue());
assertEquals("Failed parse did not return the default value", 10, Util.tryParseNumber("ss", 10).intValue());
assertEquals("Parsing empty string did not return the default value", 10, Util.tryParseNumber("", 10).intValue());
assertEquals("Parsing null string did not return the default value", 10, Util.tryParseNumber(null, 10).intValue());
}

@Test
public void testSymlink() throws Exception {
if (Functions.isWindows()) return;
Assume.assumeTrue(!Functions.isWindows());

ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener l = new StreamTaskListener(baos);
Expand Down Expand Up @@ -195,6 +201,7 @@ public void testSymlink() throws Exception {
}
}

@Test
public void testIsSymlink() throws IOException, InterruptedException {
Assume.assumeTrue(!Functions.isWindows());

Expand Down Expand Up @@ -224,10 +231,11 @@ public void testIsSymlink() throws IOException, InterruptedException {
}
}

public void TestEscape() {
@Test
public void testHtmlEscape() {
assertEquals("<br>", Util.escape("\n"));
assertEquals("&lt;a>", Util.escape("<a>"));
assertEquals("&quot;&#039;", Util.escape("'\""));
assertEquals("&#039;&quot;", Util.escape("'\""));
assertEquals("&nbsp; ", Util.escape(" "));
}

Expand All @@ -236,6 +244,7 @@ public void TestEscape() {
* to another digest.
*/
@Bug(10346)
@Test
public void testDigestThreadSafety() throws InterruptedException {
String a = "abcdefgh";
String b = "123456789";
Expand Down

0 comments on commit d501781

Please sign in to comment.