Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/hudson/matrix/AxisDescriptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
*/
package hudson.matrix;

import static org.junit.Assert.*;
import hudson.util.FormValidation;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AxisDescriptorTest {
class AxisDescriptorTest {

TextAxis.DescriptorImpl descriptor = new TextAxis.DescriptorImpl();
private final TextAxis.DescriptorImpl descriptor = new TextAxis.DescriptorImpl();

@Test
public void combinationNameSpecialChars() {
void combinationNameSpecialChars() {
assertEquals(
FormValidation.Kind.ERROR,
descriptor.doCheckName("a=b").kind
Expand All @@ -51,7 +51,7 @@ public void combinationNameSpecialChars() {
}

@Test
public void combinationValueSpecialChars() {
void combinationValueSpecialChars() {
assertEquals(
FormValidation.Kind.OK,
descriptor.checkValue("a=b").kind
Expand Down
42 changes: 22 additions & 20 deletions src/test/java/hudson/matrix/AxisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import hudson.Util;
import hudson.model.JDK;
import hudson.util.VersionNumber;
import java.util.List;
import jenkins.model.Jenkins;
import org.hamcrest.collection.IsEmptyCollection;
import org.htmlunit.HttpMethod;
Expand All @@ -37,32 +36,34 @@
import org.htmlunit.html.HtmlInput;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.xml.XmlPage;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AxisTest {
@WithJenkins
class AxisTest {

public @Rule JenkinsRule j = new JenkinsRule();
private JenkinsRule j;

private MatrixProject p;
private WebClient wc;

@Before
public void setUp() throws Exception {
@BeforeEach
void setUp(JenkinsRule rule) throws Exception {
j = rule;
wc = j.createWebClient();
p = j.createProject(MatrixProject.class);

Expand All @@ -72,7 +73,7 @@ public void setUp() throws Exception {
}

@Test
public void submitEmptyAxisName() throws Exception {
void submitEmptyAxisName() throws Exception {
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);

final String expectedMsg = "Matrix axis name '' is invalid: Axis name can not be empty";
Expand All @@ -82,7 +83,7 @@ public void submitEmptyAxisName() throws Exception {
}

@Test
public void submitInvalidAxisName() throws Exception {
void submitInvalidAxisName() throws Exception {
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);

String expectedMsg = "Matrix axis name 'a,b' is invalid: ‘,’ is an unsafe character";
Expand Down Expand Up @@ -110,7 +111,7 @@ private void setName(HtmlForm form, String value) {
}

@Test
public void submitInvalidAxisValue() throws Exception {
void submitInvalidAxisValue() throws Exception {
wc.getOptions().setThrowExceptionOnFailingStatusCode(false);

HtmlForm form = addAxis("User-defined Axis");
Expand All @@ -125,23 +126,24 @@ public void submitInvalidAxisValue() throws Exception {
}

@Test
public void emptyAxisValueListResultInNoConfigurations() throws Exception {
void emptyAxisValueListResultInNoConfigurations() throws Exception {
emptyValue("User-defined Axis");
emptyValue("Agents");
emptyValue("Label expression");
emptyValue("JDK");

MatrixBuild build = j.buildAndAssertSuccess(p);
assertThat(build.getRuns(), new IsEmptyCollection<MatrixRun>());
assertThat(p.getItems(), new IsEmptyCollection<MatrixConfiguration>());
assertThat(build.getRuns(), new IsEmptyCollection<>());
assertThat(p.getItems(), new IsEmptyCollection<>());

for (Axis axis : p.getAxes()) {
assertEquals("", axis.getValueString());
}
}

@Test @Issue("SECURITY-3289")
public void testHaxorNameFromConfigXml() throws IOException, SAXException {
@Test
@Issue("SECURITY-3289")
void testHaxorNameFromConfigXml() throws IOException, SAXException {
p.getAxes().add(new TextAxis("CHANGEME", p.getName()));
p.save();
XmlPage xmlPage = wc.goToXml(p.getUrl() + "config.xml");
Expand Down Expand Up @@ -189,7 +191,7 @@ private HtmlPage emptyValue(String axis) throws Exception {
return ret;
}

private void assertFailedWith(String expected, HtmlPage res) {
private static void assertFailedWith(String expected, HtmlPage res) {
String actual = res.getWebResponse().getContentAsString();

assertThat(actual, res.getWebResponse().getStatusCode(), equalTo(400));
Expand All @@ -210,7 +212,7 @@ private HtmlForm addAxis(String axis) throws Exception {
return form;
}

private void waitForInput(HtmlForm form) throws InterruptedException {
private static void waitForInput(HtmlForm form) throws InterruptedException {
int numberInputs = form.getInputsByName("_.name").size();
int initialInputs = numberInputs;
int tries = 18; // 18 * 17 == 306
Expand Down
Loading