forked from jenkinsci/office-365-connector-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhookDescriptorImplTest.java
More file actions
140 lines (102 loc) · 3.23 KB
/
WebhookDescriptorImplTest.java
File metadata and controls
140 lines (102 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package jenkins.plugins.office365connector;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import java.io.File;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.kohsuke.stapler.StaplerRequest2;
import org.mockito.MockedStatic;
/**
* @author Damian Szczepanik (damianszczepanik@github)
*/
public class WebhookDescriptorImplTest {
private final WebhookStub.DescriptorImplStub descriptor = new WebhookStub.DescriptorImplStub();
private MockedStatic<Jenkins> staticJenkins;
@Before
public void setUp() {
staticJenkins = mockStatic(Jenkins.class);
Jenkins jenkins = mock(Jenkins.class);
File rootDir = new File(".");
when(jenkins.getRootDir()).thenReturn(rootDir);
staticJenkins.when(Jenkins::get).thenReturn(jenkins);
}
@After
public void tearDown() {
staticJenkins.close();
}
@Test
public void getDisplayName_ReturnsName() {
// given & when
String displayName = descriptor.getDisplayName();
// then
assertThat(displayName).isEqualTo("Webhook");
}
@Test
public void getDefaultTimeout_ReturnsDefaultTimeout() {
// given & when
int timeout = descriptor.getDefaultTimeout();
// then
assertThat(timeout).isEqualTo(Webhook.DEFAULT_TIMEOUT);
}
@Test
public void doCheckUrl_ValidatesUrl() {
// given
String validUrl = "http://myJenkins.abc";
// when
FormValidation result = descriptor.doCheckUrl(validUrl);
// then
assertThat(result).isEqualTo(FormValidation.ok());
}
@Test
public void getName_ReturnsName() {
// given
String name = "test";
// when
descriptor.setName(name);
// then
assertThat(descriptor.getName()).isEqualTo(name);
}
@Test
public void getUrl_ReturnsUrl() {
// given
String url = "test.com";
// when
descriptor.setUrl(url);
// then
assertThat(descriptor.getUrl()).isEqualTo(url);
}
@Test
public void configure_ReturnsTrue() {
// given
StaplerRequest2 staplerRequest = mock(StaplerRequest2.class);
when(staplerRequest.bindJSON(any(), any())).thenReturn("");
// when
boolean isConfigured = descriptor.configure(staplerRequest, null);
// then
assertThat(isConfigured).isTrue();
}
@Test
public void doCheckGlobalUrl_ValidatesUrl() {
// given
String validUrl = "http://myJenkins.abc";
// when
FormValidation result = descriptor.doCheckGlobalUrl(validUrl);
// then
assertThat(result).isEqualTo(FormValidation.ok());
}
@Test
public void doCheckGlobalUrl_ValidatesUrl_WhenBlank() {
// given
String validUrl = "";
// when
FormValidation result = descriptor.doCheckGlobalUrl(validUrl);
// then
assertThat(result).isEqualTo(FormValidation.ok());
}
}