File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\tasks\test\TestObjectTest.java.html

1 package hudson.tasks.test;
2
3 import java.lang.ref.Reference;
4 import java.lang.ref.WeakReference;
5 import java.util.ArrayList;
6 import java.util.List;
7 import org.junit.Assert;
8 import org.junit.Test;
9
10 public class TestObjectTest {
11
12 @Test
13 public void testSafe() {
14 String name = "Foo#approve! is called by approve_on_foo?xyz/\\:";
15 String encoded = TestObject.safe(name);
16
17 Assert.assertFalse(encoded.contains("#"));
18 Assert.assertFalse(encoded.contains("?"));
19 Assert.assertFalse(encoded.contains("\\"));
20 Assert.assertFalse(encoded.contains("/"));
21 Assert.assertFalse(encoded.contains(":"));
22 }
23
24 @Test public void uniquifyName() {
25 for (int i = 0; i < 2; i++) { // different parents
26 final List<TestObject> ts = new ArrayList<TestObject>();
27 for (int j = 0; j < 10; j++) {
28 final String name = "t" + (int) Math.sqrt(j); // partly unique names
29 ts.add(new SimpleCaseResult() {
30 @Override public String getSafeName() {
31 return uniquifyName(ts, name);
32 }
33 });
34 }
35 List<String> names = new ArrayList<String>();
36 for (TestObject t : ts) {
37 names.add(t.getSafeName());
38 }
39 Assert.assertEquals("[t0, t1, t1_2, t1_3, t2, t2_2, t2_3, t2_4, t2_5, t3]", names.toString());
40 Reference<?> r = new WeakReference<Object>(ts.get(4)); // arbitrarily
41 ts.clear();
42 System.gc();
43 Assert.assertNull(r.get());
44 }
45 }
46
47 }
48