Skip to content

Commit 66fae1b

Browse files
committed
add test case for branch filter
1 parent 6337d36 commit 66fae1b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/java/org/jenkinsci/plugins/gogs/GogsWebHookTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.PrintWriter;
2626

2727
import static org.junit.Assert.assertEquals;
28+
import static org.junit.Assert.assertSame;
2829
import static org.junit.Assert.fail;
2930
import static org.mockito.Mockito.verify;
3031
import static org.mockito.Mockito.when;
@@ -232,6 +233,33 @@ public void whenUriDoesNotContainUrlNameMustReturnError() throws Exception {
232233
log.info("Test succeeded.");
233234
}
234235

236+
@Test
237+
public void whenJobBranchNotMatchMustReturnError() throws Exception {
238+
String[][] test_vals = {
239+
{null, "master", "true"},
240+
{null, "dev", "true"},
241+
{"", "master", "true"},
242+
{"", "dev", "true"},
243+
{"*", "master", "true"},
244+
{"*", "dev", "true"},
245+
{"dev", "master", "false"},
246+
{"dev", "dev", "true"},
247+
{"master", "master", "true"},
248+
{"master", "dev", "false"},
249+
};
250+
251+
for (int i = 0; i < test_vals.length; ++i) {
252+
String filter = test_vals[i][0];
253+
String ref = test_vals[i][1];
254+
boolean ret = Boolean.parseBoolean(test_vals[i][2]);
255+
256+
GogsProjectProperty property = new GogsProjectProperty(null, false, filter);
257+
assertSame(String.format("branch filter check failed for [%s -> %s]", ref, filter), ret, property.filterBranch(ref));
258+
}
259+
260+
log.info("Test succeeded.");
261+
}
262+
235263
//
236264
// Helper methods
237265
//

0 commit comments

Comments
 (0)