Skip to content

Commit 125842b

Browse files
authored
Clean up imports in tests (jenkinsci#1193)
1 parent 0d15a88 commit 125842b

File tree

46 files changed

+491
-516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+491
-516
lines changed

src/test/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionConfigAsCodeTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.dabsquared.gitlabjenkins.connection;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
37
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
48
import com.cloudbees.plugins.credentials.domains.Domain;
59
import com.cloudbees.plugins.credentials.domains.DomainCredentials;
@@ -8,21 +12,15 @@
812
import io.jenkins.plugins.casc.ConfiguratorRegistry;
913
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
1014
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
15+
import io.jenkins.plugins.casc.misc.Util;
1116
import io.jenkins.plugins.casc.model.CNode;
12-
import io.jenkins.plugins.casc.model.Mapping;
1317
import java.util.List;
1418
import jenkins.model.Jenkins;
1519
import org.junit.Rule;
1620
import org.junit.Test;
1721
import org.junit.contrib.java.lang.system.EnvironmentVariables;
1822
import org.junit.rules.RuleChain;
1923

20-
import static io.jenkins.plugins.casc.misc.Util.toStringFromYamlFile;
21-
import static io.jenkins.plugins.casc.misc.Util.toYamlString;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertNotNull;
24-
import static org.junit.Assert.assertTrue;
25-
2624
public class GitLabConnectionConfigAsCodeTest {
2725
@Rule
2826
public RuleChain chain = RuleChain.outerRule(new EnvironmentVariables()
@@ -72,8 +70,8 @@ public void export_configuration() throws Exception {
7270
@SuppressWarnings("unchecked")
7371
CNode node = c.describe(globalConfiguration, context);
7472
assertNotNull(node);
75-
String exported = toYamlString(node);
76-
String expected = toStringFromYamlFile(this, "global-config-expected.yml");
73+
String exported = Util.toYamlString(node);
74+
String expected = Util.toStringFromYamlFile(this, "global-config-expected.yml");
7775
assertEquals(expected, exported);
7876
}
7977
}

src/test/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionConfigSSLTest.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.dabsquared.gitlabjenkins.connection;
22

3+
import static org.hamcrest.CoreMatchers.containsString;
4+
import static org.hamcrest.CoreMatchers.is;
5+
import static org.hamcrest.MatcherAssert.assertThat;
36

47
import com.cloudbees.plugins.credentials.CredentialsProvider;
58
import com.cloudbees.plugins.credentials.CredentialsScope;
@@ -9,9 +12,22 @@
912
import com.dabsquared.gitlabjenkins.connection.GitLabConnection.DescriptorImpl;
1013
import hudson.util.FormValidation;
1114
import hudson.util.Secret;
15+
import java.io.IOException;
16+
import java.util.List;
17+
import javax.servlet.ServletException;
18+
import javax.servlet.http.HttpServletRequest;
19+
import javax.servlet.http.HttpServletResponse;
1220
import jenkins.model.Jenkins;
1321
import org.eclipse.jetty.http.HttpVersion;
14-
import org.eclipse.jetty.server.*;
22+
import org.eclipse.jetty.server.Connector;
23+
import org.eclipse.jetty.server.Handler;
24+
import org.eclipse.jetty.server.HttpConfiguration;
25+
import org.eclipse.jetty.server.HttpConnectionFactory;
26+
import org.eclipse.jetty.server.Request;
27+
import org.eclipse.jetty.server.SecureRequestCustomizer;
28+
import org.eclipse.jetty.server.Server;
29+
import org.eclipse.jetty.server.ServerConnector;
30+
import org.eclipse.jetty.server.SslConnectionFactory;
1531
import org.eclipse.jetty.server.handler.AbstractHandler;
1632
import org.eclipse.jetty.server.handler.HandlerCollection;
1733
import org.eclipse.jetty.util.ssl.SslContextFactory;
@@ -24,17 +40,6 @@
2440
import org.jvnet.hudson.test.JenkinsRule;
2541
import org.mockserver.socket.PortFactory;
2642

27-
import javax.servlet.ServletException;
28-
import javax.servlet.http.HttpServletRequest;
29-
import javax.servlet.http.HttpServletResponse;
30-
import java.io.IOException;
31-
import java.util.List;
32-
33-
import static java.lang.Thread.sleep;
34-
import static org.hamcrest.CoreMatchers.containsString;
35-
import static org.hamcrest.CoreMatchers.is;
36-
import static org.junit.Assert.assertThat;
37-
3843
/**
3944
* @author Robin Müller
4045
*/

src/test/java/com/dabsquared/gitlabjenkins/connection/GitLabConnectionConfigTest.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package com.dabsquared.gitlabjenkins.connection;
22

3+
import static com.dabsquared.gitlabjenkins.connection.Messages.connection_error;
4+
import static com.dabsquared.gitlabjenkins.connection.Messages.connection_success;
5+
import static org.hamcrest.CoreMatchers.containsString;
6+
import static org.hamcrest.CoreMatchers.is;
7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.junit.Assert.assertNotNull;
9+
import static org.junit.Assert.assertSame;
10+
import static org.junit.Assert.assertTrue;
11+
import static org.mockito.Mockito.mock;
12+
import static org.mockserver.model.HttpRequest.request;
13+
import static org.mockserver.model.HttpResponse.response;
314

415
import com.cloudbees.plugins.credentials.CredentialsProvider;
516
import com.cloudbees.plugins.credentials.CredentialsScope;
@@ -16,6 +27,14 @@
1627
import hudson.security.GlobalMatrixAuthorizationStrategy;
1728
import hudson.util.FormValidation;
1829
import hudson.util.Secret;
30+
import java.io.IOException;
31+
import java.net.URISyntaxException;
32+
import java.net.URL;
33+
import java.nio.charset.Charset;
34+
import java.util.ArrayList;
35+
import java.util.Base64;
36+
import java.util.List;
37+
import javax.ws.rs.core.Response;
1938
import jenkins.model.Jenkins;
2039
import org.apache.http.HttpHeaders;
2140
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -32,28 +51,6 @@
3251
import org.mockserver.junit.MockServerRule;
3352
import org.mockserver.model.HttpRequest;
3453

35-
import javax.ws.rs.core.Response;
36-
import java.io.IOException;
37-
import java.net.URISyntaxException;
38-
import java.net.URL;
39-
import java.nio.charset.Charset;
40-
import java.util.ArrayList;
41-
import java.util.Base64;
42-
import java.util.List;
43-
import java.util.Map;
44-
45-
import static com.dabsquared.gitlabjenkins.connection.Messages.connection_error;
46-
import static com.dabsquared.gitlabjenkins.connection.Messages.connection_success;
47-
import static junit.framework.TestCase.assertNotNull;
48-
import static junit.framework.TestCase.assertSame;
49-
import static org.hamcrest.CoreMatchers.containsString;
50-
import static org.hamcrest.CoreMatchers.is;
51-
import static org.junit.Assert.assertThat;
52-
import static org.junit.Assert.assertTrue;
53-
import static org.mockito.Mockito.mock;
54-
import static org.mockserver.model.HttpRequest.request;
55-
import static org.mockserver.model.HttpResponse.response;
56-
5754
/**
5855
* @author Robin Müller
5956
*/

src/test/java/com/dabsquared/gitlabjenkins/environment/GitLabEnvironmentContributorTest.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.dabsquared.gitlabjenkins.environment;
22

3+
import static com.dabsquared.gitlabjenkins.cause.CauseDataBuilder.causeData;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertNotNull;
6+
37
import com.dabsquared.gitlabjenkins.cause.CauseData;
48
import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause;
59
import hudson.EnvVars;
@@ -9,36 +13,18 @@
913
import hudson.matrix.MatrixRun;
1014
import hudson.matrix.TextAxis;
1115
import hudson.model.BuildListener;
12-
import hudson.model.FreeStyleProject;
1316
import hudson.model.FreeStyleBuild;
17+
import hudson.model.FreeStyleProject;
1418
import hudson.model.StreamBuildListener;
15-
import jenkins.model.Jenkins;
16-
import org.junit.After;
19+
import java.io.IOException;
20+
import java.nio.charset.Charset;
21+
import java.util.List;
22+
import java.util.concurrent.ExecutionException;
1723
import org.junit.Before;
18-
import org.junit.BeforeClass;
1924
import org.junit.ClassRule;
2025
import org.junit.Test;
2126
import org.jvnet.hudson.test.JenkinsRule;
2227

23-
import java.io.IOException;
24-
import java.nio.charset.Charset;
25-
import java.text.MessageFormat;
26-
import java.util.Arrays;
27-
import java.util.concurrent.ExecutionException;
28-
import java.util.HashSet;
29-
import java.util.List;
30-
import java.util.logging.Level;
31-
import java.util.logging.Logger;
32-
33-
import static com.dabsquared.gitlabjenkins.cause.CauseDataBuilder.causeData;
34-
import static org.junit.Assert.assertEquals;
35-
import static org.junit.Assert.assertNotNull;
36-
import static org.mockito.Matchers.any;
37-
import static org.mockito.Mockito.doReturn;
38-
import static org.mockito.Mockito.mock;
39-
import static org.mockito.Mockito.spy;
40-
import static org.mockito.Mockito.when;
41-
4228
/**
4329
* @author Evgeni Golov
4430
*/
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
package com.dabsquared.gitlabjenkins.gitlab.api;
22

3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
35

46
import com.dabsquared.gitlabjenkins.gitlab.api.impl.AutodetectGitLabClientBuilder;
57
import com.dabsquared.gitlabjenkins.gitlab.api.impl.V3GitLabClientBuilder;
68
import com.dabsquared.gitlabjenkins.gitlab.api.impl.V4GitLabClientBuilder;
9+
import java.util.List;
10+
import java.util.NoSuchElementException;
711
import org.junit.Rule;
812
import org.junit.Test;
913
import org.jvnet.hudson.test.JenkinsRule;
1014

11-
import java.util.List;
12-
import java.util.NoSuchElementException;
13-
14-
import static com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder.getAllGitLabClientBuilders;
15-
import static com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder.getGitLabClientBuilderById;
16-
import static org.hamcrest.MatcherAssert.assertThat;
17-
import static org.hamcrest.core.IsInstanceOf.instanceOf;
18-
19-
2015
public class GitLabClientBuilderTest {
2116
@Rule
2217
public JenkinsRule jenkins = new JenkinsRule();
2318

2419
@Test
2520
public void getAllGitLabClientBuilders_list_is_sorted_by_ordinal() {
26-
List<GitLabClientBuilder> builders = getAllGitLabClientBuilders();
21+
List<GitLabClientBuilder> builders = GitLabClientBuilder.getAllGitLabClientBuilders();
2722
assertThat(builders.get(0), instanceOf(AutodetectGitLabClientBuilder.class));
2823
assertThat(builders.get(1), instanceOf(V4GitLabClientBuilder.class));
2924
assertThat(builders.get(2), instanceOf(V3GitLabClientBuilder.class));
3025
}
3126

3227
@Test
3328
public void getGitLabClientBuilderById_success() {
34-
assertThat(getGitLabClientBuilderById(new V3GitLabClientBuilder().id()), instanceOf(V3GitLabClientBuilder.class));
29+
assertThat(GitLabClientBuilder.getGitLabClientBuilderById(new V3GitLabClientBuilder().id()), instanceOf(V3GitLabClientBuilder.class));
3530
}
3631

3732
@Test(expected = NoSuchElementException.class)
3833
public void getGitLabClientBuilderById_no_match() {
39-
getGitLabClientBuilderById("unknown");
34+
GitLabClientBuilder.getGitLabClientBuilderById("unknown");
4035
}
4136
}

src/test/java/com/dabsquared/gitlabjenkins/gitlab/api/impl/AutodetectingGitLabClientTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
22

3+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.API_TOKEN;
4+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.addGitLabApiToken;
5+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.assertApiImpl;
6+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.responseNotFound;
7+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.responseOk;
8+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.versionRequest;
9+
import static org.junit.Assert.fail;
10+
import static org.mockserver.matchers.Times.exactly;
11+
import static org.mockserver.matchers.Times.once;
12+
313
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
14+
import java.io.IOException;
15+
import java.util.Arrays;
16+
import java.util.List;
17+
import java.util.NoSuchElementException;
418
import org.junit.Before;
519
import org.junit.Rule;
620
import org.junit.Test;
@@ -9,16 +23,6 @@
923
import org.mockserver.junit.MockServerRule;
1024
import org.mockserver.model.HttpRequest;
1125

12-
import java.io.IOException;
13-
import java.util.Arrays;
14-
import java.util.List;
15-
import java.util.NoSuchElementException;
16-
17-
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.*;
18-
import static org.junit.Assert.fail;
19-
import static org.mockserver.matchers.Times.exactly;
20-
import static org.mockserver.matchers.Times.once;
21-
2226
public class AutodetectingGitLabClientTest {
2327
@Rule
2428
public MockServerRule mockServer = new MockServerRule(this);

src/test/java/com/dabsquared/gitlabjenkins/gitlab/api/impl/ResteasyGitLabClientBuilderTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
22

3+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.assertApiImpl;
4+
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.buildClientWithDefaults;
5+
import static org.junit.Assert.assertNotNull;
36

47
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
58
import hudson.ProxyConfiguration;
@@ -8,11 +11,6 @@
811
import org.jvnet.hudson.test.JenkinsRule;
912
import org.mockserver.junit.MockServerRule;
1013

11-
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.assertApiImpl;
12-
import static com.dabsquared.gitlabjenkins.gitlab.api.impl.TestUtility.buildClientWithDefaults;
13-
import static junit.framework.TestCase.assertNotNull;
14-
15-
1614
public class ResteasyGitLabClientBuilderTest {
1715
@Rule
1816
public MockServerRule mockServer = new MockServerRule(this);

src/test/java/com/dabsquared/gitlabjenkins/gitlab/api/impl/TestUtility.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.dabsquared.gitlabjenkins.gitlab.api.impl;
22

3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.instanceOf;
5+
import static org.mockserver.model.HttpRequest.request;
6+
import static org.mockserver.model.HttpResponse.response;
37

48
import com.cloudbees.plugins.credentials.CredentialsProvider;
59
import com.cloudbees.plugins.credentials.CredentialsScope;
@@ -9,25 +13,16 @@
913
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClient;
1014
import com.dabsquared.gitlabjenkins.gitlab.api.GitLabClientBuilder;
1115
import hudson.util.Secret;
16+
import java.io.IOException;
17+
import java.lang.reflect.Field;
18+
import java.util.List;
19+
import javax.ws.rs.HttpMethod;
20+
import javax.ws.rs.core.Response;
1221
import jenkins.model.Jenkins;
1322
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
1423
import org.mockserver.model.HttpRequest;
1524
import org.mockserver.model.HttpResponse;
1625

17-
import javax.ws.rs.core.Response.Status;
18-
import java.io.IOException;
19-
import java.lang.reflect.Field;
20-
import java.util.List;
21-
22-
import static javax.ws.rs.HttpMethod.GET;
23-
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
24-
import static javax.ws.rs.core.Response.Status.OK;
25-
import static org.hamcrest.MatcherAssert.assertThat;
26-
import static org.hamcrest.Matchers.instanceOf;
27-
import static org.mockserver.model.HttpRequest.request;
28-
import static org.mockserver.model.HttpResponse.response;
29-
30-
3126
class TestUtility {
3227
static final String API_TOKEN = "secret";
3328
private static final String API_TOKEN_ID = "apiTokenId";
@@ -46,18 +41,18 @@ static void addGitLabApiToken() throws IOException {
4641
}
4742

4843
static HttpRequest versionRequest(String id) {
49-
return request().withMethod(GET).withPath("/gitlab/api/" + id + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
44+
return request().withMethod(HttpMethod.GET).withPath("/gitlab/api/" + id + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
5045
}
5146

5247
static HttpResponse responseOk() {
53-
return responseWithStatus(OK);
48+
return responseWithStatus(Response.Status.OK);
5449
}
5550

5651
static HttpResponse responseNotFound() {
57-
return responseWithStatus(NOT_FOUND);
52+
return responseWithStatus(Response.Status.NOT_FOUND);
5853
}
5954

60-
private static HttpResponse responseWithStatus(Status status) {
55+
private static HttpResponse responseWithStatus(Response.Status status) {
6156
return response().withStatusCode(status.getStatusCode());
6257
}
6358

0 commit comments

Comments
 (0)