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

1 /**
2 *
3 */
4 package hudson.model;
5
6 import java.util.Collection;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10
11 /**
12 * @author kingfai
13 *
14 */
15 @SuppressWarnings("unchecked")
16 public class AbstractItemTest {
17
18 private class StubAbstractItem extends AbstractItem {
19
20 protected StubAbstractItem() {
21 // sending in null as parent as I don't care for my current tests
22 super(null, "StubAbatractItem");
23 }
24
25 @SuppressWarnings("rawtypes")
26 @Override
27 public Collection<? extends Job> getAllJobs() {
28 return null;
29 }
30
31 /**
32 * Override save so that nothig happens when setDisplayName() is called
33 */
34 @Override
35 public void save() {
36
37 }
38 }
39
40 @Test
41 public void testSetDisplayName() throws Exception {
42 final String displayName = "testDisplayName";
43 StubAbstractItem i = new StubAbstractItem();
44 i.setDisplayName(displayName);
45 Assert.assertEquals(displayName, i.getDisplayName());
46 }
47
48 @Test
49 public void testGetDefaultDisplayName() {
50 final String name = "the item name";
51 StubAbstractItem i = new StubAbstractItem();
52 i.doSetName(name);
53 // assert that if the displayname is not set, the name is actually returned
54 Assert.assertEquals(name, i.getDisplayName());
55
56 }
57
58 @Test
59 public void testSearchNameIsName() throws Exception {
60 final String name = "the item name jlrtlekjtekrjkjr";
61 StubAbstractItem i = new StubAbstractItem();
62 i.doSetName(name);
63
64 Assert.assertEquals(i.getName(), i.getSearchName());
65 }
66
67 @Test
68 public void testGetDisplayNameOrNull() throws Exception {
69 final String projectName = "projectName";
70 final String displayName = "displayName";
71 StubAbstractItem i = new StubAbstractItem();
72 i.doSetName(projectName);
73 Assert.assertEquals(projectName, i.getName());
74 Assert.assertNull(i.getDisplayNameOrNull());
75
76 i.setDisplayName(displayName);
77 Assert.assertEquals(displayName, i.getDisplayNameOrNull());
78 }
79
80 @Test
81 public void testSetDisplayNameOrNull() throws Exception {
82 final String projectName = "projectName";
83 final String displayName = "displayName";
84 StubAbstractItem i = new StubAbstractItem();
85 i.doSetName(projectName);
86 Assert.assertNull(i.getDisplayNameOrNull());
87
88 i.setDisplayNameOrNull(displayName);
89 Assert.assertEquals(displayName, i.getDisplayNameOrNull());
90 Assert.assertEquals(displayName, i.getDisplayName());
91 }
92 }
93