diff --git a/Jenkinsfile b/Jenkinsfile
index 154d6ae64..8a2983d11 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,11 +1,11 @@
-def latestSupported = "2.407"
-def recentLTS = "2.361.4"
-def configurations = [
- [ platform: "linux", jdk: "11", jenkins: null ],
- [ platform: "windows", jdk: "11", jenkins: latestSupported ],
- [ platform: "linux", jdk: "11", jenkins: latestSupported ],
- [ platform: "windows", jdk: "11", jenkins: recentLTS ],
- [ platform: "linux", jdk: "11", jenkins: recentLTS ],
-]
-
-buildPlugin(configurations: configurations)
\ No newline at end of file
+/*
+ See the documentation for more options:
+ https://github.com/jenkins-infra/pipeline-library/
+*/
+buildPlugin(
+ forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores
+ useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests
+ configurations: [
+ [platform: 'linux', jdk: 21],
+ [platform: 'windows', jdk: 17],
+])
\ No newline at end of file
diff --git a/README.md b/README.md
index 9fe934268..d1e1a3d00 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ A Jenkins plugin for automatically forwarding metrics, events, and service check
### Installation
-_This plugin requires [Jenkins 2.361.4][2] and Java 11._
+_This plugin requires [Jenkins 2.479.3][2] and Java 17._
_For older versions of Jenkins (i.e 1.632+), you can find the 1.2.0 version of the plugin [here](https://updates.jenkins.io/download/plugins/datadog/)._
@@ -77,7 +77,7 @@ import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntak
import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite
import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKey
-def jenkins = Jenkins.getInstance()
+def jenkins = Jenkins.getInstanceOrNull()
def datadog = jenkins.getDescriptorByType(DatadogGlobalConfiguration)
def site = new DatadogIntakeSite(DatadogSite.US1) // pick your Datadog site
@@ -102,7 +102,7 @@ import jenkins.model.Jenkins
import org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration
import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration
-def jenkins = Jenkins.getInstance()
+def jenkins = Jenkins.getInstanceOrNull()
def datadog = jenkins.getDescriptorByType(DatadogGlobalConfiguration)
def agentHost = 'localhost'
diff --git a/docker/controller-node/10-create-admin-user.groovy b/docker/controller-node/10-create-admin-user.groovy
index 3e4f43f12..0aba34949 100644
--- a/docker/controller-node/10-create-admin-user.groovy
+++ b/docker/controller-node/10-create-admin-user.groovy
@@ -1,7 +1,7 @@
import hudson.security.HudsonPrivateSecurityRealm
import jenkins.model.Jenkins
-def instance = Jenkins.getInstance()
+def instance = Jenkins.getInstanceOrNull()
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
instance.setSecurityRealm(hudsonRealm)
diff --git a/pom.xml b/pom.xml
index ea16e1c19..915c4ae96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.jenkins-ci.plugins
plugin
- 4.52
+ 5.10
@@ -20,11 +20,9 @@
- 2.361
- ${jenkins.baseline}.4
+ 2.479
+ ${jenkins.baseline}.3
1.0.0
-
- 1.12.14
true
@@ -69,7 +67,7 @@
io.jenkins.tools.bom
bom-${jenkins.baseline}.x
- 2102.v854b_fec19c92
+ 4890.vfca_82c6741a_d
import
pom
@@ -77,60 +75,59 @@
-
- io.jenkins.plugins
- jnr-posix-api
- 3.1.7-1
-
com.datadoghq
java-dogstatsd-client
- 2.9.0
+ 4.4.3
+
+
+ com.github.jnr
+ *
+
+
-
- io.jenkins
- configuration-as-code
- test
+ io.dropwizard.metrics
+ metrics-core
+ 4.2.30
- io.jenkins.configuration-as-code
- test-harness
- test
+ io.dropwizard.metrics
+ metrics-json
+ 4.2.30
+
+
+ com.fasterxml.jackson.core
+ *
+
+
- org.json
- json
- 20240303
+ io.jenkins.lib
+ support-log-formatter
+ 1.2
- com.github.stefanbirkner
- system-lambda
- 1.2.1
- test
+ io.jenkins.plugins
+ jnr-posix-api
-
-
- org.mockito
- mockito-core
- test
+ io.jenkins.plugins
+ json-api
- com.github.stefanbirkner
- system-rules
- 1.19.0
- test
+ org.jenkins-ci.plugins
+ bouncycastle-api
- net.bytebuddy
- byte-buddy-agent
- ${byte-buddy.version}
- test
+ org.eclipse.jetty
+ jetty-client
+ 12.0.19
- org.jenkins-ci.plugins.workflow
- workflow-job
+ org.eclipse.jetty
+ jetty-util
+ 12.0.19
org.jenkins-ci.plugins
@@ -138,110 +135,91 @@
org.jenkins-ci.plugins
- plain-credentials
+ git-client
- org.jenkins-ci.plugins.pipeline-stage-view
- pipeline-rest-api
- 2.12
+ org.jenkins-ci.plugins
+ jackson2-api
+
- org.jenkins-ci.plugins.workflow
- workflow-cps
+ org.jenkins-ci.plugins
+ matrix-project
+
+
+ org.jenkinsci.plugins
+ pipeline-model-definition
org.jenkins-ci.plugins
- git-client
+ plain-credentials
- org.jenkins-ci.plugins.workflow
- workflow-basic-steps
- test
+ org.jenkins-ci.plugins.pipeline-stage-view
+ pipeline-rest-api
+ 2.12
- org.jenkins-ci.plugins
- git
- test
+ org.jenkins-ci.plugins.workflow
+ workflow-cps
org.jenkins-ci.plugins.workflow
workflow-durable-task-step
-
- org.jenkins-ci.plugins
- matrix-project
+ org.jenkins-ci.plugins.workflow
+ workflow-job
- org.jenkinsci.plugins
- pipeline-model-definition
- 1.4.0
-
-
- com.fasterxml.jackson.core
- jackson-core
-
-
- com.fasterxml.jackson.core
- jackson-databind
-
-
- org.jenkins-ci.plugins
- jackson2-api
-
-
+ org.kohsuke
+ access-modifier-suppressions
+ ${access-modifier-checker.version}
+ provided
+
+
- org.jenkins-ci.plugins
- jackson2-api
- 2.15.0-334.v317a_165f9b_7c
+ com.github.stefanbirkner
+ system-lambda
+ 1.2.1
test
- org.eclipse.jetty
- jetty-client
- 9.4.51.v20230217
+ com.github.stefanbirkner
+ system-rules
+ 1.19.0
+ test
- org.bouncycastle
- bcpg-jdk18on
- 1.72
+ io.jenkins
+ configuration-as-code
+ test
- io.jenkins.lib
- support-log-formatter
- 1.2
+ io.jenkins.configuration-as-code
+ test-harness
+ test
- org.kohsuke
- access-modifier-suppressions
- ${access-modifier-checker.version}
+ org.jenkins-ci.plugins
+ git
+ test
- io.dropwizard.metrics
- metrics-core
- 4.2.28
+ org.jenkins-ci.plugins.workflow
+ workflow-basic-steps
+ test
- io.dropwizard.metrics
- metrics-json
- 4.2.28
+ org.mockito
+ mockito-core
+ test
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- -javaagent:/tmp/byte-buddy/byte-buddy-agent-${byte-buddy.version}.jar
-
- **/*Test
- **/*IT
-
-
-
org.apache.maven.plugins
maven-jar-plugin
@@ -254,30 +232,6 @@
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy
- process-resources
-
- copy
-
-
-
-
- net.bytebuddy
- byte-buddy-agent
- /tmp/byte-buddy
-
-
-
-
-
-
-
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogEvent.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogEvent.java
index d80d3ceaf..76ff937d4 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogEvent.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogEvent.java
@@ -35,17 +35,17 @@ of this software and associated documentation files (the "Software"), to deal
*/
public interface DatadogEvent {
- public static final String DEFAULT_EVENT_TYPE = "default";
- public static final String SECURITY_EVENT_TYPE = "security";
- public static final String SYSTEM_EVENT_TYPE = "system";
+ String DEFAULT_EVENT_TYPE = "default";
+ String SECURITY_EVENT_TYPE = "security";
+ String SYSTEM_EVENT_TYPE = "system";
- public static enum AlertType {
+ enum AlertType {
ERROR,
WARNING,
INFO,
SUCCESS;
- private AlertType() {
+ AlertType() {
}
public Event.AlertType toEventAlertType(){
@@ -53,11 +53,11 @@ public Event.AlertType toEventAlertType(){
}
}
- public static enum Priority {
+ enum Priority {
LOW,
NORMAL;
- private Priority() {
+ Priority() {
}
public Event.Priority toEventPriority(){
@@ -65,22 +65,22 @@ public Event.Priority toEventPriority(){
}
}
- public String getTitle();
+ String getTitle();
- public String getText();
+ String getText();
- public String getHost();
+ String getHost();
- public String getJenkinsUrl();
+ String getJenkinsUrl();
- public Priority getPriority();
+ Priority getPriority();
- public AlertType getAlertType();
+ AlertType getAlertType();
- public String getAggregationKey();
+ String getAggregationKey();
- public Long getDate();
+ Long getDate();
- public Map> getTags();
+ Map> getTags();
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
index 42a423481..22aa02cbd 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java
@@ -26,11 +26,6 @@ of this software and associated documentation files (the "Software"), to deal
package org.datadog.jenkins.plugins.datadog;
import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.*;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentHost;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentLogCollectionPort;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentPort;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentTraceCollectionPort;
-import static org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeSite.DatadogIntakeSiteDescriptor.getSite;
import static org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogTextApiKey.DatadogTextApiKeyDescriptor.getDefaultKey;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@@ -47,11 +42,6 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.File;
import java.io.IOException;
import java.util.*;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@@ -76,9 +66,6 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.util.conversion.PatternListConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.PolymorphicReflectionConverter;
import org.kohsuke.stapler.*;
-import org.kohsuke.stapler.DataBoundConstructor;
-import org.kohsuke.stapler.QueryParameter;
-import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.interceptor.RequirePOST;
@Extension
@@ -431,7 +418,7 @@ public String getDisplayName() {
/**
* Indicates if this builder can be used with all kinds of project types.
*
- * @param req - A StaplerRequest object
+ * @param req - A StaplerRequest2 object
* @param formData - A JSONObject containing the submitted form data from the configuration
* screen.
* @return a boolean signifying the success or failure of configuration.
@@ -439,7 +426,7 @@ public String getDisplayName() {
*/
@Override
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
- public boolean configure(final StaplerRequest req, final JSONObject formData) throws FormException {
+ public boolean configure(final StaplerRequest2 req, final JSONObject formData) throws FormException {
try {
if(!super.configure(req, formData)){
return false;
@@ -913,10 +900,10 @@ private FormValidation validateEventFilteringConfig(boolean emitSecurityEvents,
List allEvents = Arrays.asList(
String.format("%s,%s,%s", SYSTEM_EVENTS, SECURITY_EVENTS, DEFAULT_EVENTS).split(","));
- if (!includedEventsList.stream().allMatch(allEvents::contains)) {
+ if (!allEvents.containsAll(includedEventsList)) {
return FormValidation.error("The included events list contains one or more unrecognized events.");
}
- if (!excludedEventsList.stream().allMatch(allEvents::contains)) {
+ if (!allEvents.containsAll(excludedEventsList)) {
return FormValidation.error("The excluded events list contains one or more unrecognized events.");
}
@@ -1155,8 +1142,7 @@ public String getReportWith() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public String getTargetApiURL() {
- if (datadogClientConfiguration instanceof DatadogApiConfiguration) {
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogApiConfiguration apiConfiguration) {
DatadogIntake intake = apiConfiguration.getIntake();
return intake.getApiUrl();
}
@@ -1166,8 +1152,7 @@ public String getTargetApiURL() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public String getTargetLogIntakeURL() {
- if (datadogClientConfiguration instanceof DatadogApiConfiguration) {
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogApiConfiguration apiConfiguration) {
DatadogIntake intake = apiConfiguration.getIntake();
return intake.getLogsUrl();
}
@@ -1177,8 +1162,7 @@ public String getTargetLogIntakeURL() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public String getTargetWebhookIntakeURL() {
- if (datadogClientConfiguration instanceof DatadogApiConfiguration) {
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogApiConfiguration apiConfiguration) {
DatadogIntake intake = apiConfiguration.getIntake();
return intake.getWebhooksUrl();
}
@@ -1188,11 +1172,9 @@ public String getTargetWebhookIntakeURL() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public Secret getTargetApiKey() {
- if (datadogClientConfiguration instanceof DatadogApiConfiguration) {
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogApiConfiguration apiConfiguration) {
DatadogApiKey apiKey = apiConfiguration.getApiKey();
- if (apiKey instanceof DatadogTextApiKey) {
- DatadogTextApiKey textApiKey = (DatadogTextApiKey) apiKey;
+ if (apiKey instanceof DatadogTextApiKey textApiKey) {
return textApiKey.getKey();
}
}
@@ -1202,11 +1184,9 @@ public Secret getTargetApiKey() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public String getTargetCredentialsApiKey() {
- if (datadogClientConfiguration instanceof DatadogApiConfiguration) {
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogApiConfiguration apiConfiguration) {
DatadogApiKey apiKey = apiConfiguration.getApiKey();
- if (apiKey instanceof DatadogCredentialsApiKey) {
- DatadogCredentialsApiKey credentialsApiKey = (DatadogCredentialsApiKey) apiKey;
+ if (apiKey instanceof DatadogCredentialsApiKey credentialsApiKey) {
return credentialsApiKey.getCredentialsId();
}
}
@@ -1216,8 +1196,7 @@ public String getTargetCredentialsApiKey() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public String getTargetHost() {
- if (datadogClientConfiguration instanceof DatadogAgentConfiguration) {
- DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogAgentConfiguration agentConfiguration) {
return agentConfiguration.getAgentHost();
}
return null;
@@ -1226,8 +1205,7 @@ public String getTargetHost() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public Integer getTargetPort() {
- if (datadogClientConfiguration instanceof DatadogAgentConfiguration) {
- DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogAgentConfiguration agentConfiguration) {
return agentConfiguration.getAgentPort();
}
return null;
@@ -1236,8 +1214,7 @@ public Integer getTargetPort() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public Integer getTargetLogCollectionPort() {
- if (datadogClientConfiguration instanceof DatadogAgentConfiguration) {
- DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogAgentConfiguration agentConfiguration) {
return agentConfiguration.getAgentLogCollectionPort();
}
return null;
@@ -1246,8 +1223,7 @@ public Integer getTargetLogCollectionPort() {
/** @deprecated use {@link #getDatadogClientConfiguration()} */
@Deprecated
public Integer getTargetTraceCollectionPort() {
- if (datadogClientConfiguration instanceof DatadogAgentConfiguration) {
- DatadogAgentConfiguration agentConfiguration = (DatadogAgentConfiguration) datadogClientConfiguration;
+ if (datadogClientConfiguration instanceof DatadogAgentConfiguration agentConfiguration) {
return agentConfiguration.getAgentTraceCollectionPort();
}
return null;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java
index 04e5f6e5e..06712fbfe 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogPluginManagement.java
@@ -11,12 +11,12 @@
import net.sf.json.JSONObject;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.datadog.jenkins.plugins.datadog.flare.FlareContributor;
-import org.kohsuke.stapler.StaplerRequest;
-import org.kohsuke.stapler.StaplerResponse;
+import org.kohsuke.stapler.StaplerRequest2;
+import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.interceptor.RequirePOST;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
@@ -82,7 +82,7 @@ public Permission getRequiredPermission() {
}
@RequirePOST
- public void doDownloadDiagnosticFlare(StaplerRequest request, StaplerResponse response) throws Exception {
+ public void doDownloadDiagnosticFlare(StaplerRequest2 request, StaplerResponse2 response) throws Exception {
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
@@ -111,7 +111,7 @@ public void doDownloadDiagnosticFlare(StaplerRequest request, StaplerResponse re
}
}
- private List getSelectedContributors(StaplerRequest request) throws ServletException {
+ private List getSelectedContributors(StaplerRequest2 request) throws ServletException {
JSONObject form = request.getSubmittedForm();
JSONArray selectedUiControls = form.getJSONArray("selectedContributors");
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogUtilities.java b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogUtilities.java
index 5969546fd..190fdb03a 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogUtilities.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/DatadogUtilities.java
@@ -33,7 +33,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.*;
import java.net.Inet4Address;
import java.net.UnknownHostException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -283,12 +283,12 @@ private static Map> getTagsFromGlobalJobTags(String jobName,
}
}
}
- Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet();
+ Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<>();
tagValues.add(tagValue.toLowerCase());
tags.put(tagName, tagValues);
} else if (tagItem.length == 1) {
String tagName = tagItem[0];
- Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet();
+ Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<>();
tagValues.add(""); // no values
tags.put(tagName, tagValues);
} else {
@@ -324,12 +324,12 @@ public static Map> getTagsFromGlobalTags() {
continue;
}
- for (int i = 0; i < tagList.size(); i++) {
- String[] tagItem = tagList.get(i).replaceAll(" ", "").split(":", 2);
+ for (String s : tagList) {
+ String[] tagItem = s.replaceAll(" ", "").split(":", 2);
if (tagItem.length == 2) {
String tagName = tagItem[0];
String tagValue = tagItem[1];
- Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet();
+ Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<>();
// Apply environment variables if specified. ie (custom_tag:$ENV_VAR)
if (tagValue.startsWith("$") && EnvVars.masterEnvVars.containsKey(tagValue.substring(1))) {
tagValue = EnvVars.masterEnvVars.get(tagValue.substring(1));
@@ -342,7 +342,7 @@ public static Map> getTagsFromGlobalTags() {
tags.put(tagName, tagValues);
} else if (tagItem.length == 1) {
String tagName = tagItem[0];
- Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet();
+ Set tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<>();
tagValues.add(""); // no values
tags.put(tagName, tagValues);
} else {
@@ -446,19 +446,19 @@ public static Map> computeTagListFromVarList(EnvVars envVars
if (tagList.isEmpty()) {
continue;
}
- for (int i = 0; i < tagList.size(); i++) {
- String tag = tagList.get(i).replaceAll(" ", "");
+ for (String s : tagList) {
+ String tag = s.replaceAll(" ", "");
String[] expanded = envVars.expand(tag).split("=", 2);
if (expanded.length == 2) {
String name = expanded[0];
String value = expanded[1];
- Set values = result.containsKey(name) ? result.get(name) : new HashSet();
+ Set values = result.containsKey(name) ? result.get(name) : new HashSet<>();
values.add(value);
result.put(name, values);
logger.fine(String.format("Emitted tag %s:%s", name, value));
} else if (expanded.length == 1) {
String name = expanded[0];
- Set values = result.containsKey(name) ? result.get(name) : new HashSet();
+ Set values = result.containsKey(name) ? result.get(name) : new HashSet<>();
values.add(""); // no values
result.put(name, values);
} else {
@@ -556,7 +556,7 @@ public static String getHostname(EnvVars envVars) {
String[] cmd = {"/bin/hostname", "-f"};
Process proc = Runtime.getRuntime().exec(cmd);
InputStream in = proc.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
@@ -591,7 +591,7 @@ public static String getHostname(EnvVars envVars) {
}
// Never found the hostname
- if (hostname == null || "".equals(hostname)) {
+ if (hostname == null || hostname.isEmpty()) {
logger.warning("Unable to reliably determine host name. You can define one in "
+ "the 'Manage Plugins' section under the 'Datadog Plugin' section.");
}
@@ -833,6 +833,7 @@ private static boolean isUnix(FilePath filePath) throws IOException, Interrupted
// copied from hudson.FilePath.IsUnix
private static final class IsUnix extends MasterToSlaveCallable {
+ @Serial
private static final long serialVersionUID = 1L;
@Override
@@ -887,7 +888,7 @@ public static long currentTimeMillis() {
}
public static String getJenkinsUrl() {
- Jenkins jenkins = Jenkins.getInstance();
+ Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
return "unknown";
} else {
@@ -984,16 +985,12 @@ public static BlockStartNode getEnclosingStageNode(FlowNode node) {
*/
public static String statusFromResult(String result) {
String resultLowercase = result == null ? "error" : result.toLowerCase();
- switch (resultLowercase) {
- case "failure":
- return "error";
- case "aborted":
- return "canceled";
- case "not_built":
- return "skipped";
- default:
- return resultLowercase;
- }
+ return switch (resultLowercase) {
+ case "failure" -> "error";
+ case "aborted" -> "canceled";
+ case "not_built" -> "skipped";
+ default -> resultLowercase;
+ };
}
public static void severe(Logger logger, Throwable e, String message) {
@@ -1199,7 +1196,7 @@ public static boolean shouldSendEvent(String eventName) {
* @return list of event name strings that can be sent
*/
private static List createIncludeLists() {
- List includedEvents = new ArrayList(Arrays.asList(
+ List includedEvents = new ArrayList<>(Arrays.asList(
DatadogGlobalConfiguration.DEFAULT_EVENTS.split(",")));
DatadogGlobalConfiguration cfg = getDatadogGlobalDescriptor();
@@ -1211,13 +1208,13 @@ private static List createIncludeLists() {
}
if (cfg.isEmitSystemEvents()) {
- includedEvents.addAll(new ArrayList(
+ includedEvents.addAll(new ArrayList<>(
Arrays.asList(DatadogGlobalConfiguration.SYSTEM_EVENTS.split(","))
));
}
if (cfg.isEmitSecurityEvents()) {
- includedEvents.addAll(new ArrayList(
+ includedEvents.addAll(new ArrayList<>(
Arrays.asList(DatadogGlobalConfiguration.SECURITY_EVENTS.split(","))
));
}
@@ -1242,8 +1239,7 @@ public static Throwable getErrorObj(FlowNode flowNode) {
@Nullable
public static TaskListener getTaskListener(Run run) throws IOException {
- if (run instanceof WorkflowRun) {
- WorkflowRun workflowRun = (WorkflowRun) run;
+ if (run instanceof WorkflowRun workflowRun) {
FlowExecution execution = workflowRun.getExecution();
if (execution != null) {
FlowExecutionOwner owner = execution.getOwner();
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerConfigurator.java b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerConfigurator.java
index 847999ef4..8ad7ee836 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerConfigurator.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerConfigurator.java
@@ -118,8 +118,7 @@ public Map configure(Run, ?> run, Computer computer, Node node
}
private static TopLevelItem getTopLevelItem(Run, ?> run) {
- if (run instanceof AbstractBuild) {
- AbstractBuild, ?> build = (AbstractBuild, ?>) run;
+ if (run instanceof AbstractBuild, ?> build) {
AbstractProject, ?> project = build.getProject();
if (project instanceof TopLevelItem) {
return (TopLevelItem) project;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerJobProperty.java b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerJobProperty.java
index 4908ee8c7..af93c0cc0 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerJobProperty.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/DatadogTracerJobProperty.java
@@ -18,7 +18,7 @@
import net.sf.json.JSONObject;
import org.datadog.jenkins.plugins.datadog.steps.TestOptimization;
import org.kohsuke.stapler.DataBoundConstructor;
-import org.kohsuke.stapler.StaplerRequest;
+import org.kohsuke.stapler.StaplerRequest2;
public class DatadogTracerJobProperty> extends JobProperty {
@@ -79,7 +79,7 @@ public boolean isApplicable(Class extends Job> jobType) {
}
@Override
- public DatadogTracerJobProperty> newInstance(StaplerRequest req, JSONObject formData) {
+ public DatadogTracerJobProperty> newInstance(StaplerRequest2 req, JSONObject formData) {
if (!formData.optBoolean("on")) {
return null;
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/ShellCommandCallable.java b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/ShellCommandCallable.java
index 0dfb17256..c37963755 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/ShellCommandCallable.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/ShellCommandCallable.java
@@ -4,7 +4,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Map;
import jenkins.MasterToSlaveFileCallable;
import org.datadog.jenkins.plugins.datadog.util.ShellCommandExecutor;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/signature/SignatureVerifier.java b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/signature/SignatureVerifier.java
index f7b8e2238..4c3b2d492 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/signature/SignatureVerifier.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/signature/SignatureVerifier.java
@@ -16,38 +16,39 @@
public class SignatureVerifier {
public static final String DATADOG_PUBLIC_KEY = (
- "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
- "Version: Hockeypuck 2.1.0-222-g25248d4\n" +
- "Comment: Hostname:\n" +
- "\n" +
- "xsFNBGBbo2cBEAC16RsAMkhlN1YYzmihO//AwHRQ+n33bnmXsGkXgp2vKPcM7bty\n" +
- "oiZxdz3FAM6fBlBKG0RNn7DBEmkiu2EdxFCp7zLzLa2NC3KW89D0GnmkvX9Uebgf\n" +
- "Iv8a4QcMHsWl3sAINnbiy2uNnJqmDzA5ofsAkJyL9fEMVdagLASC/CsxckxPDPgg\n" +
- "RBp8Et625lMdIA4Owf5ZPibYVMR5xOdoucsH3KFGJNVyvX+xwx8hQDyLMg7hbI0T\n" +
- "9nu840oZR+CQqndu6sFxqxGNzbwRYoJO/zZKttwnfDQnruJjkGL8dptHxuBJ7c+8\n" +
- "TAabUzvbhNltuJDnt3+qKbV9hg1+tNgbA6oo1E5xONzg4mm/IG9TzejU1uFGNRC2\n" +
- "2PSzwG8ps9saB61+Px3/1VmYFisdpaGssQJHbSFylQcgWJx4gVo0EBZER/i+JLn6\n" +
- "g8AiNf2RQoFKkliHMHgR0UXek+5vxiPYCF5fqMvpDqPjKq0TgbVZyfPz50LrNEy/\n" +
- "HA/a3hdJbYyMThNQ1LTKQVW7JJnIO/87P3/XV0wSpwt4JBJHXNFk+w1YY/DbAHyS\n" +
- "OGDxYUvJ8AOz1gvt8MBf/pDoV/kbY8b+PsX41eCe0uQ58tmbXhAXBZss2P2AcuZq\n" +
- "BwNho0CnfXWp04g5I3FlaWb+/ZMQ+/AsXgbTWCRldC+P2Cou5zPVrGrgMQARAQAB\n" +
- "zWdEYXRhZG9nIGRkLXRyYWNlLWphdmEgUGFja2FnaW5nIChEYXRhZG9nIGRkLXRy\n" +
- "YWNlLWphdmEgUGFja2FnaW5nKSA8cGFja2FnZStkZC10cmFjZS1qYXZhQGRhdGFk\n" +
- "b2docS5jb20+wsGTBBMBCAA9FiEE2O7camr/v79OPdjRyiBgiJT0O00FAmBbo2cC\n" +
- "GwMFCQICKQAECwkIBwUVCgkICwUWAwIBAAIeAQIXgAAKCRDKIGCIlPQ7TV2RD/4w\n" +
- "wypKpk4GFYoxnfpsNT7g3U1ZSy3qGwabo4FxXN0mH0i92AI2bREWKjkvQQcQUmfR\n" +
- "+vG05nyF0MJ3Vpre/Qzt7TOcy2sBIOpFzo4pMJpRHp5W9Pqm+PCUpzs+X5LBz04i\n" +
- "6DRhNWT0kBJI9U5mQCdZETEHQZ8iUC/UAfNkXRrUMNF6OcjkPhWUPZB2OtH07bZl\n" +
- "GZkX9iwxUcM7nsAbj/qnqcVAxSnr3ylYSBo8ctgEIY/YsQsMzq6JasxtBCaMMz10\n" +
- "TflGD0bNV0zd8xjY4OfF42C9W+o0lDlTPq3HkxOUC/uUmaX/gSniJOyAp9wtD3Al\n" +
- "P9oi3RWXEAdbIQ/D38smTYZD/0VopeoX0M7QrH6ifsCCRiMj/rbw3M/KDheWDk6w\n" +
- "5CKpYDqJVmsVvWm+h7H51nQTM5CZLXHkasWmhOkj48SU3p+NSAnvQywaVW9drU79\n" +
- "wxjUgCXSwl8IHmTDSEbrBRbLSXWLiGGeqw+EmLZckJE6BQNDFYflkVLuObhNJtRi\n" +
- "pZtYi8gqyelflomEN6YBJ8dOk6SCcnU6SEzua/2YpYsHakGld0/uyux2MfXwCiJ9\n" +
- "Wf37KG6e1eegDQWy8BPg6iRoIaEyyeEWQ8CpG8ZG2zfMxUOe4pqsRfUT5k2LE5kx\n" +
- "IPdMz7WGf1S8iuZcBwF6PhAqJJv41pJ0mO4ewnZbnQ==\n" +
- "=7erW\n" +
- "-----END PGP PUBLIC KEY BLOCK-----"
+ """
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
+ Version: Hockeypuck 2.1.0-222-g25248d4
+ Comment: Hostname:
+
+ xsFNBGBbo2cBEAC16RsAMkhlN1YYzmihO//AwHRQ+n33bnmXsGkXgp2vKPcM7bty
+ oiZxdz3FAM6fBlBKG0RNn7DBEmkiu2EdxFCp7zLzLa2NC3KW89D0GnmkvX9Uebgf
+ Iv8a4QcMHsWl3sAINnbiy2uNnJqmDzA5ofsAkJyL9fEMVdagLASC/CsxckxPDPgg
+ RBp8Et625lMdIA4Owf5ZPibYVMR5xOdoucsH3KFGJNVyvX+xwx8hQDyLMg7hbI0T
+ 9nu840oZR+CQqndu6sFxqxGNzbwRYoJO/zZKttwnfDQnruJjkGL8dptHxuBJ7c+8
+ TAabUzvbhNltuJDnt3+qKbV9hg1+tNgbA6oo1E5xONzg4mm/IG9TzejU1uFGNRC2
+ 2PSzwG8ps9saB61+Px3/1VmYFisdpaGssQJHbSFylQcgWJx4gVo0EBZER/i+JLn6
+ g8AiNf2RQoFKkliHMHgR0UXek+5vxiPYCF5fqMvpDqPjKq0TgbVZyfPz50LrNEy/
+ HA/a3hdJbYyMThNQ1LTKQVW7JJnIO/87P3/XV0wSpwt4JBJHXNFk+w1YY/DbAHyS
+ OGDxYUvJ8AOz1gvt8MBf/pDoV/kbY8b+PsX41eCe0uQ58tmbXhAXBZss2P2AcuZq
+ BwNho0CnfXWp04g5I3FlaWb+/ZMQ+/AsXgbTWCRldC+P2Cou5zPVrGrgMQARAQAB
+ zWdEYXRhZG9nIGRkLXRyYWNlLWphdmEgUGFja2FnaW5nIChEYXRhZG9nIGRkLXRy
+ YWNlLWphdmEgUGFja2FnaW5nKSA8cGFja2FnZStkZC10cmFjZS1qYXZhQGRhdGFk
+ b2docS5jb20+wsGTBBMBCAA9FiEE2O7camr/v79OPdjRyiBgiJT0O00FAmBbo2cC
+ GwMFCQICKQAECwkIBwUVCgkICwUWAwIBAAIeAQIXgAAKCRDKIGCIlPQ7TV2RD/4w
+ wypKpk4GFYoxnfpsNT7g3U1ZSy3qGwabo4FxXN0mH0i92AI2bREWKjkvQQcQUmfR
+ +vG05nyF0MJ3Vpre/Qzt7TOcy2sBIOpFzo4pMJpRHp5W9Pqm+PCUpzs+X5LBz04i
+ 6DRhNWT0kBJI9U5mQCdZETEHQZ8iUC/UAfNkXRrUMNF6OcjkPhWUPZB2OtH07bZl
+ GZkX9iwxUcM7nsAbj/qnqcVAxSnr3ylYSBo8ctgEIY/YsQsMzq6JasxtBCaMMz10
+ TflGD0bNV0zd8xjY4OfF42C9W+o0lDlTPq3HkxOUC/uUmaX/gSniJOyAp9wtD3Al
+ P9oi3RWXEAdbIQ/D38smTYZD/0VopeoX0M7QrH6ifsCCRiMj/rbw3M/KDheWDk6w
+ 5CKpYDqJVmsVvWm+h7H51nQTM5CZLXHkasWmhOkj48SU3p+NSAnvQywaVW9drU79
+ wxjUgCXSwl8IHmTDSEbrBRbLSXWLiGGeqw+EmLZckJE6BQNDFYflkVLuObhNJtRi
+ pZtYi8gqyelflomEN6YBJ8dOk6SCcnU6SEzua/2YpYsHakGld0/uyux2MfXwCiJ9
+ Wf37KG6e1eegDQWy8BPg6iRoIaEyyeEWQ8CpG8ZG2zfMxUOe4pqsRfUT5k2LE5kx
+ IPdMz7WGf1S8iuZcBwF6PhAqJJv41pJ0mO4ewnZbnQ==
+ =7erW
+ -----END PGP PUBLIC KEY BLOCK-----"""
);
public static boolean verifySignature(InputStream artifactStream, InputStream signatureStream, InputStream publicKeyStream) throws Exception {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/audit/DatadogAudit.java b/src/main/java/org/datadog/jenkins/plugins/datadog/audit/DatadogAudit.java
index f1a77fb2b..8dfb41d56 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/audit/DatadogAudit.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/audit/DatadogAudit.java
@@ -10,7 +10,7 @@
*/
public class DatadogAudit {
- private static transient final Logger LOGGER = Logger.getLogger(DatadogAudit.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(DatadogAudit.class.getName());
static {
log("## DatadogAudit enabled ##");
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java
index 06af9246c..73958bfcd 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
import com.timgroup.statsd.Event;
import com.timgroup.statsd.NonBlockingStatsDClient;
+import com.timgroup.statsd.NonBlockingStatsDClientBuilder;
import com.timgroup.statsd.ServiceCheck;
import com.timgroup.statsd.StatsDClient;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -39,13 +40,6 @@ of this software and associated documentation files (the "Software"), to deal
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.*;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
import java.util.function.Function;
import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy;
@@ -230,7 +224,7 @@ private boolean reinitializeStatsDClient(boolean force) {
stopStatsDClient();
logger.info("Re/Initialize DogStatsD Client: hostname = " + this.hostname + ", port = " + this.port);
- this.statsd = new NonBlockingStatsDClient(null, this.hostname, this.port);
+ this.statsd = new NonBlockingStatsDClient(new NonBlockingStatsDClientBuilder().prefix(null).hostname(this.hostname).port(this.port));
return true;
} catch (Exception e){
@@ -361,7 +355,7 @@ public TraceWriteStrategy createTraceWriteStrategy() {
"DD-CI-PROVIDER-NAME", "jenkins");
boolean evpProxySupportsGzip = agentEndpoints.contains("/evp_proxy/v4/");
- JsonPayloadSender payloadSender = new BatchSender<>(client, url, headers, PAYLOAD_SIZE_LIMIT, p -> p.getJson(), evpProxySupportsGzip);
+ JsonPayloadSender payloadSender = new BatchSender<>(client, url, headers, PAYLOAD_SIZE_LIMIT, Payload::getJson, evpProxySupportsGzip);
return new TraceWriteStrategyImpl(Track.WEBHOOK, payloadSender::send);
} else {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java
index 29b4e2e5b..5e071e2c6 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java
@@ -30,14 +30,10 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.logging.Logger;
-import net.sf.json.JSON;
+
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.datadog.jenkins.plugins.datadog.DatadogClient;
@@ -301,7 +297,7 @@ public TraceWriteStrategy createTraceWriteStrategy() {
Map headers = Map.of(
"DD-API-KEY", Secret.toString(apiKey),
"DD-CI-PROVIDER-NAME", "jenkins");
- JsonPayloadSender payloadSender = new BatchSender<>(httpClient, url, headers, PAYLOAD_SIZE_LIMIT, p -> p.getJson(), COMPRESS_REQUEST);
+ JsonPayloadSender payloadSender = new BatchSender<>(httpClient, url, headers, PAYLOAD_SIZE_LIMIT, Payload::getJson, COMPRESS_REQUEST);
return new TraceWriteStrategyImpl(Track.WEBHOOK, payloadSender::send);
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpClient.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpClient.java
index 0b8a3d595..0abcdf2c9 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpClient.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpClient.java
@@ -21,13 +21,13 @@
import org.eclipse.jetty.client.HttpProxy;
import org.eclipse.jetty.client.Origin;
import org.eclipse.jetty.client.ProxyConfiguration;
-import org.eclipse.jetty.client.api.ContentResponse;
-import org.eclipse.jetty.client.api.Request;
-import org.eclipse.jetty.client.api.Response;
-import org.eclipse.jetty.client.api.Result;
-import org.eclipse.jetty.client.util.BufferingResponseListener;
-import org.eclipse.jetty.client.util.BytesContentProvider;
-import org.eclipse.jetty.client.util.InputStreamResponseListener;
+import org.eclipse.jetty.client.ContentResponse;
+import org.eclipse.jetty.client.Request;
+import org.eclipse.jetty.client.Response;
+import org.eclipse.jetty.client.Result;
+import org.eclipse.jetty.client.BufferingResponseListener;
+import org.eclipse.jetty.client.BytesRequestContent;
+import org.eclipse.jetty.client.InputStreamResponseListener;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
@@ -117,7 +117,8 @@ public Thread newThread(final Runnable r) {
threadPool.setName("dd-http-client-thread-pool");
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
- org.eclipse.jetty.client.HttpClient httpClient = new org.eclipse.jetty.client.HttpClient(sslContextFactory);
+ org.eclipse.jetty.client.HttpClient httpClient = new org.eclipse.jetty.client.HttpClient();
+ httpClient.setSslContextFactory(sslContextFactory);
configureProxies(jenkinsProxyConfiguration, httpClient);
@@ -235,13 +236,13 @@ private Supplier requestSupplier(String url, HttpMethod method, Map e : headers.entrySet()) {
- request.header(e.getKey(), e.getValue());
+ request.headers(h -> h.add(e.getKey(), e.getValue()));
}
if (contentType != null) {
- request.header(HttpHeader.CONTENT_TYPE, contentType);
+ request.headers(h -> h.add(HttpHeader.CONTENT_TYPE, contentType));
}
if (body != null) {
- request.content(new BytesContentProvider(contentType, body));
+ request.body(new BytesRequestContent(contentType, body));
}
return request;
};
@@ -280,19 +281,12 @@ private static T executeSynchronously(Supplier requestSupplier, Htt
continue;
}
- String additionalHint;
- switch (status) {
- case HttpStatus.FORBIDDEN_403:
- additionalHint = "API key might be invalid, please check your config";
- break;
- case HttpStatus.NOT_FOUND_404:
- case HttpStatus.BAD_REQUEST_400:
- additionalHint = "Request URL might be invalid, please check your config";
- break;
- default:
- additionalHint = "";
- break;
- }
+ String additionalHint = switch (status) {
+ case HttpStatus.FORBIDDEN_403 -> "API key might be invalid, please check your config";
+ case HttpStatus.NOT_FOUND_404, HttpStatus.BAD_REQUEST_400 ->
+ "Request URL might be invalid, please check your config";
+ default -> "";
+ };
throw new ResponseProcessingException("Received erroneous response " + response + ". " + additionalHint);
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpRetryPolicy.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpRetryPolicy.java
index 6f9622ac5..fbca1b82c 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpRetryPolicy.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/HttpRetryPolicy.java
@@ -6,7 +6,7 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
-import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.client.Response;
/**
* A policy which encapsulates retry rules for HTTP calls. Whether to retry and how long to wait
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration.java b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration.java
index f395fc0b8..2df5c2093 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/DatadogAgentConfiguration.java
@@ -5,6 +5,8 @@
import hudson.model.Descriptor;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
+
+import java.io.Serial;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
@@ -65,6 +67,7 @@ public DatadogAgentConfiguration(String agentHost, Integer agentPort, Integer ag
* Invoked by XStream when this object is deserialized.
* Ensures environment variables have higher priority than configuration persisted on disk
*/
+ @Serial
protected Object readResolve() {
String agentHost = DatadogAgentConfigurationDescriptor.getAgentHostFromEnvVars(this.agentHost);
Integer agentPort = DatadogAgentConfigurationDescriptor.getAgentPortFromEnvVars(this.agentPort);
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite.java b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite.java
index bf75c63a7..c66adf072 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeSite.java
@@ -8,6 +8,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import java.io.Serial;
import java.util.Arrays;
import java.util.Objects;
@@ -29,6 +30,7 @@ public DatadogIntakeSite(DatadogSite site) {
* Invoked by XStream when this object is deserialized.
* Ensures environment variables have higher priority than configuration persisted on disk
*/
+ @Serial
protected Object readResolve() {
DatadogSite site = DatadogIntakeSiteDescriptor.getSite();
if (site != null) {
@@ -107,11 +109,7 @@ public static DatadogSite getSite() {
public static DatadogSite getDefaultSite() {
DatadogSite site = getSite();
- if (site != null) {
- return site;
- } else {
- return DEFAULT_DATADOG_SITE_VALUE;
- }
+ return Objects.requireNonNullElse(site, DEFAULT_DATADOG_SITE_VALUE);
}
@Override
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls.java b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls.java
index cf4060c81..881f3085a 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/intake/DatadogIntakeUrls.java
@@ -4,6 +4,8 @@
import hudson.RelativePath;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
+
+import java.io.Serial;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -13,7 +15,6 @@
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
-import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
@@ -45,6 +46,7 @@ public DatadogIntakeUrls(String apiUrl, String logsUrl, String webhooksUrl) {
* Invoked by XStream when this object is deserialized.
* Ensures environment variables have higher priority than configuration persisted on disk
*/
+ @Serial
protected Object readResolve() {
Map env = System.getenv();
String apiUrl = env.getOrDefault(TARGET_API_URL_PROPERTY, this.apiUrl);
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey.java b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey.java
index 10a32fc1b..fc2477ac6 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogCredentialsApiKey.java
@@ -54,10 +54,10 @@ static StringCredentials getCredentialFromId(String credentialId) {
return null;
}
return CredentialsMatchers.firstOrNull(
- CredentialsProvider.lookupCredentials(
+ CredentialsProvider.lookupCredentialsInItemGroup(
StringCredentials.class,
Jenkins.get(),
- ACL.SYSTEM,
+ ACL.SYSTEM2,
URIRequirementBuilder.fromUri(null).build()),
CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialId))
);
@@ -114,7 +114,7 @@ public ListBoxModel doFillCredentialsIdItems(
}
}
return result.includeEmptyValue()
- .includeMatchingAs(ACL.SYSTEM,
+ .includeMatchingAs(ACL.SYSTEM2,
Jenkins.get(),
StringCredentials.class,
Collections.emptyList(),
@@ -144,9 +144,9 @@ public FormValidation doCheckCredentialsId(
if (credentialsId.startsWith("${") && credentialsId.endsWith("}")) {
return FormValidation.warning("Cannot validate expression based credentials");
}
- if (CredentialsProvider.listCredentials(StringCredentials.class,
+ if (CredentialsProvider.listCredentialsInItem(StringCredentials.class,
item,
- ACL.SYSTEM,
+ ACL.SYSTEM2,
Collections.emptyList(),
CredentialsMatchers.withId(credentialsId)).isEmpty()) {
return FormValidation.error("Cannot find currently selected credentials");
@@ -159,7 +159,7 @@ public FormValidation doCheckConnectivity(@QueryParameter("credentialsId") final
@QueryParameter("intake") final int intakeIdx,
@QueryParameter("site") final String site,
@QueryParameter("apiUrl") final String apiUrl) {
- Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
+ Jenkins.getInstanceOrNull().checkPermission(Jenkins.ADMINISTER);
StringCredentials credentialFromId = getCredentialFromId(credentialsId);
if (credentialFromId == null) {
return FormValidation.error("Could not find credentials with the given ID");
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey.java b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey.java
index ffd59d407..cafc5abef 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/configuration/api/key/DatadogTextApiKey.java
@@ -1,6 +1,5 @@
package org.datadog.jenkins.plugins.datadog.configuration.api.key;
-import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.util.FormValidation;
@@ -8,15 +7,12 @@
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
-import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntake;
-import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeSite;
-import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls;
-import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
+import java.io.Serial;
import java.util.Objects;
@Symbol("datadogTextApiKey")
@@ -35,6 +31,7 @@ public DatadogTextApiKey(Secret key) {
* Invoked by XStream when this object is deserialized.
* Ensures environment variables have higher priority than configuration persisted on disk
*/
+ @Serial
protected Object readResolve() {
Secret defaultKey = DatadogTextApiKeyDescriptor.getDefaultKey();
if (defaultKey != null){
@@ -90,7 +87,7 @@ public FormValidation doCheckConnectivity(@QueryParameter("key") final String ke
@QueryParameter("intake") final int intakeIdx,
@QueryParameter("site") final String site,
@QueryParameter("apiUrl") final String apiUrl) {
- Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
+ Jenkins.getInstanceOrNull().checkPermission(Jenkins.ADMINISTER);
Secret apiKeyValue = Secret.fromString(key);
return checkConnectivity(apiKeyValue, intakeIdx, site, apiUrl);
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ConnectivityChecksFlare.java b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ConnectivityChecksFlare.java
index e51e119b6..655aa87be 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ConnectivityChecksFlare.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/flare/ConnectivityChecksFlare.java
@@ -40,8 +40,7 @@ public void writeFileContents(OutputStream out) throws IOException {
payload.put("traces-connectivity", validateConnectivity(clientConfiguration::validateTracesConnection));
payload.put("logs-connectivity", validateConnectivity(clientConfiguration::validateLogsConnection));
- if (clientConfiguration instanceof DatadogApiConfiguration){
- DatadogApiConfiguration apiConfiguration = (DatadogApiConfiguration) clientConfiguration;
+ if (clientConfiguration instanceof DatadogApiConfiguration apiConfiguration){
payload.put("api-connectivity", validateConnectivity(apiConfiguration::validateApiConnection));
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListener.java b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListener.java
index 4c802d27e..b6a7d5883 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListener.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListener.java
@@ -53,9 +53,6 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.metrics.Metrics;
import org.datadog.jenkins.plugins.datadog.metrics.MetricsClient;
import org.datadog.jenkins.plugins.datadog.model.*;
-import org.datadog.jenkins.plugins.datadog.model.BuildData;
-import org.datadog.jenkins.plugins.datadog.model.PipelineQueueInfoAction;
-import org.datadog.jenkins.plugins.datadog.model.TraceInfoAction;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanAction;
import org.datadog.jenkins.plugins.datadog.traces.BuildSpanManager;
import org.datadog.jenkins.plugins.datadog.traces.message.TraceSpan;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListener.java b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListener.java
index ba58f79a9..2ad8042c9 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListener.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListener.java
@@ -29,7 +29,6 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.Extension;
import hudson.model.Queue;
import java.io.IOException;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -294,8 +293,7 @@ private PipelineStepData buildStepData(WorkflowRun run, FlowNode node, FlowNode
try {
if (node instanceof StepAtomNode) {
return new PipelineStepData(run, (StepAtomNode) node, nextNode);
- } else if (node instanceof BlockEndNode) {
- BlockEndNode> endNode = (BlockEndNode>) node;
+ } else if (node instanceof BlockEndNode> endNode) {
return new PipelineStepData(run, endNode.getStartNode(), endNode);
} else {
throw new IllegalArgumentException("Unexpected flow node type: " + node);
@@ -313,13 +311,10 @@ private long getPauseDurationMillis(@Nonnull FlowNode startNode) {
long pauseDuration = 0;
FlowGraphWalker walker = new FlowGraphWalker(startNode.getExecution());
- Iterator it = walker.iterator();
-
// Iterates on the execution nodes to sum pause duration of sub-stages.
// Walks through all the execution graph of startNode, and considers the sub-nodes that are not active
// anymore. A sub-node is a node for which startNode is a parent (is part of its enclosing blocks).
- while (it.hasNext()) {
- FlowNode node = it.next();
+ for (FlowNode node : walker) {
if (!node.isActive()) {
// Lists node parents genealogy, and sees if startNode is one of them.
for (BlockStartNode parent : node.iterateEnclosingBlocks()) {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogQueueListener.java b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogQueueListener.java
index 2d489634c..f518e2c2f 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogQueueListener.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogQueueListener.java
@@ -10,7 +10,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
@@ -46,12 +45,11 @@ public void onEnterBuildable(Queue.BuildableItem item) {
return;
}
- if(!(task instanceof ExecutorStepExecution.PlaceholderTask)) {
+ if(!(task instanceof ExecutorStepExecution.PlaceholderTask placeholderTask)) {
logger.fine("onEnterBuildable: item: " + item + ", task:" + task + " is not ExecutorStepExecution.PlaceholderTask: " + task.getClass() );
return;
}
- final ExecutorStepExecution.PlaceholderTask placeholderTask = (ExecutorStepExecution.PlaceholderTask) task;
// Use async method to avoid deadlock.
// It fixes https://github.com/jenkinsci/datadog-plugin/issues/170
final FlowNode flowNode = getNodeAsync(placeholderTask, 5000);
@@ -82,12 +80,11 @@ public void onLeaveBuildable(Queue.BuildableItem item) {
return;
}
- if(!(task instanceof ExecutorStepExecution.PlaceholderTask)) {
+ if(!(task instanceof ExecutorStepExecution.PlaceholderTask placeholderTask)) {
logger.fine("onLeaveBuildable: item: " + item + ", task:" + task + " is not ExecutorStepExecution.PlaceholderTask: " + task.getClass() );
return;
}
- final ExecutorStepExecution.PlaceholderTask placeholderTask = (ExecutorStepExecution.PlaceholderTask) task;
// Use async method to avoid deadlock.
// It fixes https://github.com/jenkinsci/datadog-plugin/issues/170
final FlowNode flowNode = getNodeAsync(placeholderTask, 5000);
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogConsoleLogFilter.java b/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogConsoleLogFilter.java
index c8f9909a1..0ae32cc53 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogConsoleLogFilter.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogConsoleLogFilter.java
@@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.Serial;
import java.io.Serializable;
import java.util.logging.Logger;
@@ -43,6 +44,7 @@ public class DatadogConsoleLogFilter extends ConsoleLogFilter implements Seriali
private static final Logger logger = Logger.getLogger(DatadogConsoleLogFilter.class.getName());
public transient Run, ?> run;
+ @Serial
private static final long serialVersionUID = 1L;
public DatadogConsoleLogFilter() {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogTaskListenerDecorator.java b/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogTaskListenerDecorator.java
index c43e84f24..59e3d0a29 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogTaskListenerDecorator.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogTaskListenerDecorator.java
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.model.Queue;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.Serial;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
@@ -39,6 +40,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.jenkinsci.plugins.workflow.log.TaskListenerDecorator;
public class DatadogTaskListenerDecorator extends TaskListenerDecorator {
+ @Serial
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger(DatadogTaskListenerDecorator.class.getName());
@@ -74,8 +76,7 @@ public TaskListenerDecorator of(@Nonnull FlowExecutionOwner owner) {
}
try {
Queue.Executable executable = owner.getExecutable();
- if (executable instanceof WorkflowRun) {
- WorkflowRun run = (WorkflowRun) executable;
+ if (executable instanceof WorkflowRun run) {
if (DatadogUtilities.isJobTracked(run)) {
return new DatadogTaskListenerDecorator(run);
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/BuildData.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/BuildData.java
index 384defea5..f407a6628 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/BuildData.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/BuildData.java
@@ -50,6 +50,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.triggers.TimerTrigger;
import hudson.util.LogTaskListener;
import java.io.IOException;
+import java.io.Serial;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Collections;
@@ -57,6 +58,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -143,9 +145,10 @@ public static BuildData create(@Nullable Run, ?> run, @Nullable TaskListener l
}
}
+ @Serial
private static final long serialVersionUID = 1L;
- private static transient final Logger LOGGER = Logger.getLogger(BuildData.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(BuildData.class.getName());
private String buildNumber;
private String buildId;
private String buildUrl;
@@ -327,8 +330,7 @@ private BuildData(Run, ?> run, @Nullable TaskListener listener) throws IOExcep
// the job is run on the master node, checking plugin config and locally available info.
// (nodeName == null) condition is there to preserve existing behavior
this.hostname = DatadogUtilities.getHostname(envVars);
- } else if (run instanceof AbstractBuild) {
- AbstractBuild, ?> build = (AbstractBuild, ?>) run;
+ } else if (run instanceof AbstractBuild, ?> build) {
Node node = build.getBuiltOn();
Computer computer = node != null ? node.toComputer() : null;
this.hostname = DatadogUtilities.getNodeHostname(envVars, computer);
@@ -434,11 +436,7 @@ private static EnvVars getEnvVars(Run run, TaskListener listener) throws IOExcep
}
Map envVars;
- if(listener != null){
- envVars = run.getEnvironment(listener);
- }else{
- envVars = run.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));
- }
+ envVars = run.getEnvironment(Objects.requireNonNullElseGet(listener, () -> new LogTaskListener(LOGGER, Level.INFO)));
mergedVars.putAll(envVars);
return mergedVars;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitCommitAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitCommitAction.java
index 3d1ef6f0f..8aeefc01f 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitCommitAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitCommitAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;
@@ -19,6 +21,7 @@
@Deprecated
public class GitCommitAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private volatile String tag;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitRepositoryAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitRepositoryAction.java
index 3f1f8fb42..b1bc66acc 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitRepositoryAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/GitRepositoryAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import javax.annotation.Nullable;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogConverter;
@@ -20,6 +22,7 @@
@Deprecated
public class GitRepositoryAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private volatile String repositoryURL;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineQueueInfoAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineQueueInfoAction.java
index ff2e5b509..53963c326 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineQueueInfoAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineQueueInfoAction.java
@@ -7,12 +7,15 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogConverter;
import org.datadog.jenkins.plugins.datadog.util.conversion.VersionedConverter;
public class PipelineQueueInfoAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private volatile long queueTimeMillis = -1;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineStepData.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineStepData.java
index 68a690802..ab74dd1f7 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineStepData.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PipelineStepData.java
@@ -74,7 +74,7 @@ public String getBuildLevel() {
private final Map> tags;
public PipelineStepData(final Run, ?> run, final BlockStartNode startNode, final BlockEndNode> endNode) {
- this(run, (FlowNode) startNode, (FlowNode) endNode);
+ this(run, startNode, (FlowNode) endNode);
this.type = StepType.STAGE;
@@ -94,7 +94,7 @@ public PipelineStepData(final Run, ?> run, final BlockStartNode startNode, fin
}
public PipelineStepData(final Run, ?> run, final StepAtomNode stepNode, final FlowNode nextNode) {
- this(run, (FlowNode) stepNode, (FlowNode) nextNode);
+ this(run, (FlowNode) stepNode, nextNode);
this.type = StepType.STEP;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PluginData.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PluginData.java
index 908231248..2f214c1bd 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/PluginData.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/PluginData.java
@@ -1,9 +1,11 @@
package org.datadog.jenkins.plugins.datadog.model;
import javax.annotation.Nullable;
+import java.io.Serial;
import java.io.Serializable;
public class PluginData implements Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
private long count = 0;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/StageData.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/StageData.java
index 80ea95a29..179165835 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/StageData.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/StageData.java
@@ -3,6 +3,7 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.datadog.jenkins.plugins.datadog.util.json.ToJson;
+import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import java.util.logging.Logger;
@@ -12,8 +13,9 @@
*/
public class StageData implements Serializable, Comparable, ToJson {
+ @Serial
private static final long serialVersionUID = 1L;
- private static final transient Logger logger = Logger.getLogger(StageData.class.getName());
+ private static final Logger logger = Logger.getLogger(StageData.class.getName());
private final String name;
private final long startTimeInMicros;
@@ -49,13 +51,7 @@ public static Builder builder() {
@Override
public int compareTo(StageData other) {
- if(this.startTimeInMicros < other.getStartTimeInMicros()) {
- return -1;
- } else if(this.startTimeInMicros > other.getStartTimeInMicros()) {
- return 1;
- } else {
- return 0;
- }
+ return Long.compare(this.startTimeInMicros, other.getStartTimeInMicros());
}
@Override
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/TraceInfoAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/TraceInfoAction.java
index 10d7ba51b..5fde45d07 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/TraceInfoAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/TraceInfoAction.java
@@ -54,11 +54,7 @@ public Long getOrCreate(String flowNodeId) {
public Long removeOrCreate(String flowNodeId) {
Long existingId = spanIdByNodeId.remove(flowNodeId);
- if (existingId != null) {
- return existingId;
- } else {
- return IdGenerator.generate();
- }
+ return Objects.requireNonNullElseGet(existingId, IdGenerator::generate);
}
@Override
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/DequeueAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/DequeueAction.java
index 013158752..4c0bdfa53 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/DequeueAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/DequeueAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogConverter;
@@ -14,6 +16,7 @@
public class DequeueAction extends QueueInfoAction {
+ @Serial
private static final long serialVersionUID = 1L;
private final long queueTimeMillis;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/EnqueueAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/EnqueueAction.java
index 5d9066430..41f66831c 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/EnqueueAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/EnqueueAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.datadog.jenkins.plugins.datadog.util.conversion.DatadogConverter;
@@ -14,6 +16,7 @@
public class EnqueueAction extends QueueInfoAction {
+ @Serial
private static final long serialVersionUID = 1L;
private final long timestampMillis;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/NodeInfoAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/NodeInfoAction.java
index 5b49bfc5d..8a6baea86 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/NodeInfoAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/NodeInfoAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
@@ -16,6 +18,7 @@
public class NodeInfoAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private final String nodeName;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/StatusAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/StatusAction.java
index 950677e18..4fe50b860 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/StatusAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/model/node/StatusAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import org.datadog.jenkins.plugins.datadog.model.DatadogPluginAction;
import org.datadog.jenkins.plugins.datadog.model.Status;
@@ -15,6 +17,7 @@
public class StatusAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private final Status status;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogComputerPublisher.java b/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogComputerPublisher.java
index 4f9308630..708183e06 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogComputerPublisher.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogComputerPublisher.java
@@ -78,7 +78,7 @@ public static void publishMetrics(DatadogClient client) {
long nodeCount = 0;
long nodeOffline = 0;
long nodeOnline = 0;
- Jenkins jenkins = Jenkins.getInstance();
+ Jenkins jenkins = Jenkins.getInstanceOrNull();
Computer[] computers = new Computer[0];
if(jenkins != null){
computers = jenkins.getComputers();
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogQueuePublisher.java b/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogQueuePublisher.java
index a492250e7..cdfd4aa85 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogQueuePublisher.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/publishers/DatadogQueuePublisher.java
@@ -54,7 +54,7 @@ public class DatadogQueuePublisher extends PeriodicWork {
private static final long RECURRENCE_PERIOD = TimeUnit.MINUTES.toMillis(1);
private final Queue queue = Queue.getInstance();
-
+
@Override
public long getRecurrencePeriod() {
return RECURRENCE_PERIOD;
@@ -96,7 +96,7 @@ protected void doRun() throws Exception {
boolean isBuildable = false;
boolean isBlocked = false;
boolean isPending = false;
-
+
size++;
if(item.isStuck()){
isStuck = true;
@@ -143,8 +143,7 @@ private static String getJobName(Task task) {
return run.getParent().getFullName();
}
}
- if (task instanceof WorkflowJob) {
- WorkflowJob workflowJob = (WorkflowJob) task;
+ if (task instanceof WorkflowJob workflowJob) {
return workflowJob.getFullName();
}
return "unknown";
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogOptions.java b/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogOptions.java
index f81a7295f..7627fb45f 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogOptions.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogOptions.java
@@ -4,10 +4,12 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.PrintStream;
+import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import jenkins.YesNoMaybe;
@@ -31,6 +33,7 @@
*/
public class DatadogOptions extends Step implements Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
private boolean collectLogs = false;
private List tags = new ArrayList<>();
@@ -93,6 +96,7 @@ public StepExecution start(StepContext context) {
private static class ExecutionImpl extends StepExecution {
+ @Serial
private static final long serialVersionUID = 1L;
private DatadogPipelineAction action;
@@ -109,19 +113,14 @@ public boolean start() throws Exception {
assert listener != null;
PrintStream taskLogger = listener.getLogger();
Run, ?> run = context.get(Run.class);
- if (!(run instanceof WorkflowRun)) {
+ if (!(run instanceof WorkflowRun workflowRun)) {
// Really not expected
return false;
}
- WorkflowRun workflowRun = (WorkflowRun) run;
FlowNode optionsNode = context.get(FlowNode.class);
BlockStartNode stageNode = DatadogUtilities.getEnclosingStageNode(optionsNode);
- if (stageNode != null) {
- stageNode.addOrReplaceAction(action);
- } else {
- run.addOrReplaceAction(action);
- }
+ Objects.requireNonNullElse(stageNode, run).addOrReplaceAction(action);
BodyInvoker invoker = context.newBodyInvoker().withCallback(BodyExecutionCallback.wrap(context));
if (this.action.isCollectLogs()) {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogPipelineAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogPipelineAction.java
index e446f6394..d726bb473 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogPipelineAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/steps/DatadogPipelineAction.java
@@ -1,11 +1,14 @@
package org.datadog.jenkins.plugins.datadog.steps;
import hudson.model.Action;
+
+import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import javax.annotation.CheckForNull;
public class DatadogPipelineAction implements Action, Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
private final boolean collectLogs;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/BuildSpanAction.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/BuildSpanAction.java
index aaf66cf7d..12e325e67 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/BuildSpanAction.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/BuildSpanAction.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
@@ -20,6 +22,7 @@
*/
public class BuildSpanAction extends DatadogPluginAction {
+ @Serial
private static final long serialVersionUID = 1L;
private final TraceSpan.TraceSpanContext buildSpanContext;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBaseBuildLogic.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBaseBuildLogic.java
index 11e6d15db..1b90bfaf9 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBaseBuildLogic.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBaseBuildLogic.java
@@ -74,11 +74,10 @@ protected Set getNodeLabels(Run,?> run, final String nodeName) {
}
protected String getStageBreakdown(Run run) {
- if (!(run instanceof WorkflowRun)) {
+ if (!(run instanceof WorkflowRun workflowRun)) {
return null;
}
- WorkflowRun workflowRun = (WorkflowRun) run;
FlowExecution execution = workflowRun.getExecution();
if (execution == null) {
return null;
@@ -125,11 +124,10 @@ private List traverseStages(List heads, int limit) {
}
}
- if (!(node instanceof BlockEndNode)) {
+ if (!(node instanceof BlockEndNode> endNode)) {
continue;
}
- BlockEndNode> endNode = (BlockEndNode>) node;
BlockStartNode startNode = endNode.getStartNode();
if (!DatadogUtilities.isStageNode(startNode)) {
continue;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/message/TraceSpan.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/message/TraceSpan.java
index 23cc4d24c..c70ddc039 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/message/TraceSpan.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/message/TraceSpan.java
@@ -7,6 +7,8 @@
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -132,6 +134,7 @@ public String toString() {
public static class TraceSpanContext implements Serializable {
+ @Serial
private static final long serialVersionUID = 1L;
private final long traceId;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java
index 1e656fd9d..8fad5cd9c 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java
@@ -3,7 +3,6 @@
import hudson.model.Run;
import java.io.IOException;
import java.util.Collection;
-import java.util.function.Consumer;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import net.sf.json.JSONObject;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/ShellCommandExecutor.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/ShellCommandExecutor.java
index b7094082c..705c207a8 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/ShellCommandExecutor.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/ShellCommandExecutor.java
@@ -208,7 +208,7 @@ public String parse(InputStream inputStream) throws IOException {
while ((count = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, count);
}
- return new String(output.toByteArray(), Charset.defaultCharset());
+ return output.toString(Charset.defaultCharset());
}
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/TagsUtil.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/TagsUtil.java
index 4ad154618..77d3c9266 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/TagsUtil.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/TagsUtil.java
@@ -38,7 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
public class TagsUtil {
- private static transient final Logger LOGGER = Logger.getLogger(TagsUtil.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(TagsUtil.class.getName());
public static Map> merge(Map> dest, Map> orig) {
if (dest == null) {
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitMetadataBuilderCallback.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitMetadataBuilderCallback.java
index 61d1460bf..6baf98e13 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitMetadataBuilderCallback.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitMetadataBuilderCallback.java
@@ -4,17 +4,15 @@
import hudson.remoting.VirtualChannel;
import java.io.IOException;
+import java.io.Serial;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.eclipse.jgit.lib.*;
import org.jenkinsci.plugins.gitclient.RepositoryCallback;
-import javax.annotation.Nonnull;
+
import javax.annotation.Nullable;
/**
@@ -26,7 +24,8 @@
*/
public final class GitMetadataBuilderCallback implements RepositoryCallback {
- private static transient final Logger LOGGER = Logger.getLogger(GitMetadataBuilderCallback.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(GitMetadataBuilderCallback.class.getName());
+ @Serial
private static final long serialVersionUID = 1L;
private final String branchHint;
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java
index b9970791b..cea330104 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java
@@ -53,8 +53,8 @@ public final class GitUtils {
*/
public static final String CHANGE_BRANCH = "CHANGE_BRANCH";
- private static transient final Logger LOGGER = Logger.getLogger(GitUtils.class.getName());
- private static transient final Pattern SCP_REPO_URI_REGEX = Pattern.compile("^([\\w.~-]+@)?(?[\\w.-]+):(?[\\w./-]+)(?:\\?|$)(.*)$");
+ private static final Logger LOGGER = Logger.getLogger(GitUtils.class.getName());
+ private static final Pattern SCP_REPO_URI_REGEX = Pattern.compile("^([\\w.~-]+@)?(?[\\w.-]+):(?[\\w./-]+)(?:\\?|$)(.*)$");
private GitUtils() {
}
diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/RevCommitRepositoryCallback.java b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/RevCommitRepositoryCallback.java
index 4f38209ea..2d9421562 100644
--- a/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/RevCommitRepositoryCallback.java
+++ b/src/main/java/org/datadog/jenkins/plugins/datadog/util/git/RevCommitRepositoryCallback.java
@@ -7,6 +7,7 @@
import org.jenkinsci.plugins.gitclient.RepositoryCallback;
import java.io.IOException;
+import java.io.Serial;
/**
* Returns the RevCommit instance for a certain commit
@@ -16,6 +17,7 @@
* See GitUtils.
*/
public final class RevCommitRepositoryCallback implements RepositoryCallback {
+ @Serial
private static final long serialVersionUID = 1L;
private final String commit;
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java
index f904c5a78..c10643c79 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationEnvVariablesTest.java
@@ -63,7 +63,7 @@ public void testAgentDefaultValues() throws Exception {
assertEquals("localhost", datadogClientConfiguration.getAgentHost());
assertEquals((Integer) 8125, datadogClientConfiguration.getAgentPort());
assertEquals((Integer) 8126, datadogClientConfiguration.getAgentTraceCollectionPort());
- assertEquals((Integer) null, datadogClientConfiguration.getAgentLogCollectionPort());
+ assertNull(datadogClientConfiguration.getAgentLogCollectionPort());
}
@Test
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
index eab89e797..7bc79e886 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfigurationTest.java
@@ -13,7 +13,6 @@
import org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration;
import org.datadog.jenkins.plugins.datadog.configuration.DatadogApiConfiguration;
import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntake;
-import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeSite;
import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogIntakeUrls;
import org.datadog.jenkins.plugins.datadog.configuration.api.intake.DatadogSite;
import org.datadog.jenkins.plugins.datadog.configuration.api.key.DatadogCredentialsApiKey;
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalTagsTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalTagsTest.java
index f6e9e5ace..21caea71d 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalTagsTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalTagsTest.java
@@ -129,7 +129,7 @@ public void testGlobalJobTagsPipeline() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pipeline_job");
String definition = IOUtils.toString(
this.getClass().getResourceAsStream("testPipeline.txt"),
- "UTF-8"
+ StandardCharsets.UTF_8
);
job.setDefinition(new CpsFlowDefinition(definition, true));
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogUtilitiesTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogUtilitiesTest.java
index 81f5dcdbc..0893e6553 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogUtilitiesTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/DatadogUtilitiesTest.java
@@ -41,7 +41,6 @@ of this software and associated documentation files (the "Software"), to deal
import org.mockito.MockedStatic;
import org.mockito.Mockito;
-import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.*;
@@ -69,16 +68,16 @@ public void testCstrToList(){
List items = new ArrayList<>();
items.add("item1");
- assertTrue(DatadogUtilities.cstrToList("item1").equals(items));
- assertTrue(DatadogUtilities.cstrToList(" item1 ").equals(items));
- assertTrue(DatadogUtilities.cstrToList(" , item1 , ").equals(items));
+ assertEquals(DatadogUtilities.cstrToList("item1"), items);
+ assertEquals(DatadogUtilities.cstrToList(" item1 "), items);
+ assertEquals(DatadogUtilities.cstrToList(" , item1 , "), items);
items = new ArrayList<>();
items.add("item1");
items.add("item2");
- assertTrue(DatadogUtilities.cstrToList("item1,item2").equals(items));
- assertTrue(DatadogUtilities.cstrToList(" item1 , item2 ").equals(items));
- assertTrue(DatadogUtilities.cstrToList(" , item1 , item2 , ").equals(items));
+ assertEquals(DatadogUtilities.cstrToList("item1,item2"), items);
+ assertEquals(DatadogUtilities.cstrToList(" item1 , item2 "), items);
+ assertEquals(DatadogUtilities.cstrToList(" , item1 , item2 , "), items);
}
@Test
@@ -88,16 +87,16 @@ public void testLinesToList(){
List items = new ArrayList<>();
items.add("item1");
- assertTrue(DatadogUtilities.linesToList("item1").equals(items));
- assertTrue(DatadogUtilities.linesToList(" item1 ").equals(items));
- assertTrue(DatadogUtilities.linesToList(" \n item1 \n ").equals(items));
+ assertEquals(DatadogUtilities.linesToList("item1"), items);
+ assertEquals(DatadogUtilities.linesToList(" item1 "), items);
+ assertEquals(DatadogUtilities.linesToList(" \n item1 \n "), items);
items = new ArrayList<>();
items.add("item1");
items.add("item2");
- assertTrue(DatadogUtilities.linesToList("item1\nitem2").equals(items));
- assertTrue(DatadogUtilities.linesToList(" item1 \n item2 ").equals(items));
- assertTrue(DatadogUtilities.linesToList(" \n item1 \n item2 \n ").equals(items));
+ assertEquals(DatadogUtilities.linesToList("item1\nitem2"), items);
+ assertEquals(DatadogUtilities.linesToList(" item1 \n item2 "), items);
+ assertEquals(DatadogUtilities.linesToList(" \n item1 \n item2 \n "), items);
}
@@ -117,39 +116,37 @@ public void isStageNodeTest() {
@Test
public void getResultTagTest(){
// passed with null
- Assert.assertThrows(NullPointerException.class, () -> {
- DatadogUtilities.getResultTag(null);
- });
+ Assert.assertThrows(NullPointerException.class, () -> DatadogUtilities.getResultTag(null));
FlowNode node = mock(FlowNode.class);
// when getError returns an error
when(node.getError()).thenReturn(new ErrorAction(new NullArgumentException()));
- assertEquals(DatadogUtilities.getResultTag(node), "ERROR");
+ assertEquals("ERROR", DatadogUtilities.getResultTag(node));
// when there's a warning action
when(node.getError()).thenReturn(null);
when(node.getPersistentAction(WarningAction.class)).thenReturn(new WarningAction(Result.SUCCESS));
- assertEquals(DatadogUtilities.getResultTag(node), "SUCCESS");
+ assertEquals("SUCCESS", DatadogUtilities.getResultTag(node));
when(node.getPersistentAction(WarningAction.class)).thenReturn(new WarningAction(Result.NOT_BUILT));
- assertEquals(DatadogUtilities.getResultTag(node), "NOT_BUILT");
+ assertEquals("NOT_BUILT", DatadogUtilities.getResultTag(node));
// when the result is unknown
when(node.getPersistentAction(WarningAction.class)).thenReturn(null);
- assertEquals(DatadogUtilities.getResultTag(node), "SUCCESS");
+ assertEquals("SUCCESS", DatadogUtilities.getResultTag(node));
// when the node is a Stage node and the stage is skipped
BlockStartNode startNode = mock(BlockStartNode.class);
TagsAction tagsAction = new TagsAction();
tagsAction.addTag("STAGE_STATUS", "SKIPPED_FOR_UNSTABLE");
when(startNode.getPersistentAction(TagsAction.class)).thenReturn(tagsAction);
- assertEquals(DatadogUtilities.getResultTag(startNode), "SKIPPED");
+ assertEquals("SKIPPED", DatadogUtilities.getResultTag(startNode));
// when the node is a BlockEndNode and the stage containing it was skipped
BlockEndNode endNode = mock(BlockEndNode.class);
when(endNode.getStartNode()).thenReturn(startNode);
- assertEquals(DatadogUtilities.getResultTag(endNode), "SKIPPED");
+ assertEquals("SKIPPED", DatadogUtilities.getResultTag(endNode));
}
@@ -187,12 +184,12 @@ public void testToJsonMap() {
}
@Test
- public void testGetHostname() throws IOException {
+ public void testGetHostname() {
try (MockedStatic datadogUtilities = Mockito.mockStatic(DatadogUtilities.class)) {
- datadogUtilities.when(() -> DatadogUtilities.getDatadogGlobalDescriptor()).thenReturn(cfg);
+ datadogUtilities.when(DatadogUtilities::getDatadogGlobalDescriptor).thenReturn(cfg);
HttpURLConnection mockHTTP = mock(HttpURLConnection.class);
- datadogUtilities.when(() -> DatadogUtilities.getAwsInstanceID()).thenReturn("test");
+ datadogUtilities.when(DatadogUtilities::getAwsInstanceID).thenReturn("test");
datadogUtilities.when(() -> DatadogUtilities.getHostname(null)).thenCallRealMethod();
String hostname = DatadogUtilities.getHostname(null);
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/SemverTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/SemverTest.java
index 3ee9f6f4b..f7d62721d 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/SemverTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/SemverTest.java
@@ -47,8 +47,8 @@ public void testCompareTo() {
assertTrue(version1.compareTo(version2) < 0);
assertTrue(version2.compareTo(version1) > 0);
- assertEquals(version1.compareTo(version1), 0);
- assertEquals(version1.compareTo(version5), 0);
+ assertEquals(0, version1.compareTo(version1));
+ assertEquals(0, version1.compareTo(version5));
assertEquals(version1, version5);
assertTrue(version2.compareTo(version3) < 0);
@@ -63,7 +63,7 @@ public void testCompareToWithPreRelease() {
assertTrue(version1.compareTo(version2) < 0);
assertTrue(version2.compareTo(version1) > 0);
- assertEquals(version1.compareTo(version1), 0);
+ assertEquals(0, version1.compareTo(version1));
}
@Test
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
index 6532ff7a0..6b9e741e1 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/apm/TracerInjectionIT.java
@@ -1,10 +1,6 @@
package org.datadog.jenkins.plugins.datadog.apm;
import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.*;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentHost;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentLogCollectionPort;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentPort;
-import static org.datadog.jenkins.plugins.datadog.configuration.DatadogAgentConfiguration.DatadogAgentConfigurationDescriptor.getDefaultAgentTraceCollectionPort;
import static org.junit.Assume.assumeTrue;
import hudson.FilePath;
@@ -238,7 +234,7 @@ private WorkflowJob givenPipelineProjectWithTracerConfigMissing() throws Excepti
private static String buildPipelineDefinition(String pipelineName, Map replacements) throws IOException {
String pipelineDefinition;
try (InputStream is = TracerInjectionIT.class.getResourceAsStream(pipelineName)) {
- StringBuffer pipelineBuilder = new StringBuffer();
+ StringBuilder pipelineBuilder = new StringBuilder();
String pipelineTemplate = IOUtils.toString(is, Charset.defaultCharset());
Matcher m = PLACEHOLDER_PATTERN.matcher(pipelineTemplate);
while (m.find()) {
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/BatchSenderTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/BatchSenderTest.java
index 541c9de6d..fd9dbef6c 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/BatchSenderTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/BatchSenderTest.java
@@ -63,7 +63,7 @@ public void testOneElementBatch() throws Exception{
List>> batches = whenSending(map("a", "b"));
assertEquals(1, batches.size());
- assertEquals(Arrays.asList(map("a", "b")), batches.get(0));
+ assertEquals(List.of(map("a", "b")), batches.get(0));
}
@Test
@@ -88,9 +88,9 @@ public void testBigElement() throws Exception{
List>> batches = whenSending(map("a", "b"), map("abcdefghijk", "1234567890"), map("e", "f"));
assertEquals(3, batches.size());
- assertEquals(Arrays.asList(map("a", "b")), batches.get(0));
- assertEquals(Arrays.asList(map("abcdefghijk", "1234567890")), batches.get(1));
- assertEquals(Arrays.asList(map("e", "f")), batches.get(2));
+ assertEquals(List.of(map("a", "b")), batches.get(0));
+ assertEquals(List.of(map("abcdefghijk", "1234567890")), batches.get(1));
+ assertEquals(List.of(map("e", "f")), batches.get(2));
}
@Test
@@ -116,10 +116,11 @@ public void testTwoBatchesEdgeCase() throws Exception {
List>> batches = whenSending(map("a", "b"), map("cd", "1234567890"));
assertEquals(2, batches.size());
- assertEquals(Arrays.asList(map("a", "b")), batches.get(0));
- assertEquals(Arrays.asList(map("cd", "1234567890")), batches.get(1));
+ assertEquals(List.of(map("a", "b")), batches.get(0));
+ assertEquals(List.of(map("cd", "1234567890")), batches.get(1));
}
+ @SafeVarargs
private List>> whenSending(Map... payloads) throws Exception {
sender.send(Arrays.asList(payloads));
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java
index bde0ad85e..a3261924f 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java
@@ -51,7 +51,6 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
public class DatadogClientStub implements DatadogClient {
@@ -105,7 +104,7 @@ public boolean assertMetric(String name, double value, String hostname, String[]
this.metrics.remove(m);
return true;
}
- Assert.fail("metric { " + m.toString() + " does not exist. " +
+ Assert.fail("metric { " + m + " does not exist. " +
"metrics: {" + this.metrics.toString() + " }");
return false;
}
@@ -122,7 +121,7 @@ public double assertMetricGetValue(String name, String hostname, String[] tags)
this.metrics.remove(match.get());
return value;
}
- Assert.fail("metric { " + m.toString() + " does not exist (ignoring value). " +
+ Assert.fail("metric { " + m + " does not exist (ignoring value). " +
"metrics: {" + this.metrics.toString() + " }");
return value;
}
@@ -138,7 +137,7 @@ public boolean assertMetricValues(String name, double value, String hostname, in
if (timesSeen == count) {
return true;
}
- Assert.fail("metric { " + m.toString() + " found " + timesSeen + " times, not " + count);
+ Assert.fail("metric { " + m + " found " + timesSeen + " times, not " + count);
return false;
}
@@ -153,7 +152,7 @@ public boolean assertMetricValuesMin(String name, double value, String hostname,
if (timesSeen >= min) {
return true;
}
- Assert.fail("metric { " + m.toString() + " found " + timesSeen + " times, not more than" + min);
+ Assert.fail("metric { " + m + " found " + timesSeen + " times, not more than" + min);
return false;
}
@@ -170,13 +169,13 @@ public boolean assertMetric(String name, String hostname, String[] tags) {
return true;
}
- List sameMetricsNoTags = metrics.stream().filter(t -> t.sameNoTags(m)).collect(Collectors.toList());
+ List sameMetricsNoTags = metrics.stream().filter(t -> t.sameNoTags(m)).toList();
if (!sameMetricsNoTags.isEmpty()) {
Assert.fail("metric { " + m + " does not exist (ignoring value).\n" +
"Same metrics ignoring tags: {" + sameMetricsNoTags + " }");
}
- List metricsWithSameName = metrics.stream().filter(t -> Objects.equal(t.getName(), m.getName())).collect(Collectors.toList());
+ List metricsWithSameName = metrics.stream().filter(t -> Objects.equal(t.getName(), m.getName())).toList();
if (!metricsWithSameName.isEmpty()) {
Assert.fail("metric { " + m + " does not exist (ignoring value).\n" +
"Metrics with same name: {" + metricsWithSameName + " }");
@@ -193,7 +192,7 @@ public boolean assertServiceCheck(String name, int code, String hostname, String
this.serviceChecks.remove(m);
return true;
}
- Assert.fail("serviceCheck { " + m.toString() + " does not exist. " +
+ Assert.fail("serviceCheck { " + m + " does not exist. " +
"serviceChecks: {" + this.serviceChecks.toString() + "}");
return false;
}
@@ -203,7 +202,7 @@ public boolean assertedAllMetricsAndServiceChecks() {
return true;
}
- Assert.fail("metrics: {" + this.metrics.toString() + " }, serviceChecks : {" +
+ Assert.fail("metrics: {" + this.metrics + " }, serviceChecks : {" +
this.serviceChecks.toString() + "}");
return false;
}
@@ -246,7 +245,7 @@ public static List convertTagMapToList(Map> tags) {
}
public static Map> addTagToMap(Map> tags, String name, String value) {
- Set v = tags.containsKey(name) ? tags.get(name) : new HashSet();
+ Set v = tags.containsKey(name) ? tags.get(name) : new HashSet<>();
v.add(value);
tags.put(name, v);
return tags;
@@ -388,7 +387,7 @@ public List getWebhooks() {
public List getSpans() {
ArrayList spans = new ArrayList<>(traceWriteStrategy.traces);
- Collections.sort(spans, (span1, span2) -> {
+ spans.sort((span1, span2) -> {
if (span1.getStartNano() < span2.getStartNano()) {
return -1;
} else if (span1.getStartNano() > span2.getStartNano()) {
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogMetric.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogMetric.java
index 9ebd51f23..b527e82ec 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogMetric.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogMetric.java
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
public class DatadogMetric {
private String name = null;
@@ -44,9 +45,7 @@ public class DatadogMetric {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (!(o instanceof DatadogMetric)) return false;
-
- DatadogMetric that = (DatadogMetric) o;
+ if (!(o instanceof DatadogMetric that)) return false;
if (Double.compare(that.value, value) != 0) return false;
return this.same(that);
@@ -60,29 +59,27 @@ public boolean equals(Object o) {
public boolean same(DatadogMetric m) {
if (this == m) return true;
if (m == null) return false;
- if (name != null ? !name.equals(m.name) : m.name != null) return false;
- if (hostname != null ? !hostname.equals(m.hostname) : m.hostname != null) return false;
+ if (!Objects.equals(name, m.name)) return false;
+ if (!Objects.equals(hostname, m.hostname)) return false;
if (tags != null && m.tags == null) return false;
Collections.sort(tags);
Collections.sort(m.tags);
return tags != null ? tags.toString().equals(m.tags.toString()) : m.tags == null;
}
-
+
public boolean sameNoTags(DatadogMetric m) {
if (this == m) return true;
if (m == null) return false;
- if (name != null ? !name.equals(m.name) : m.name != null) return false;
- if (hostname != null ? !hostname.equals(m.hostname) : m.hostname != null) return false;
+ if (!Objects.equals(name, m.name)) return false;
+ if (!Objects.equals(hostname, m.hostname)) return false;
return value == m.value;
}
@Override
public int hashCode() {
int result;
- long temp;
result = name != null ? name.hashCode() : 0;
- temp = Double.doubleToLongBits(value);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
+ result = 31 * result + Double.hashCode(value);
result = 31 * result + (hostname != null ? hostname.hashCode() : 0);
result = 31 * result + (tags != null ? tags.hashCode() : 0);
return result;
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildAbortedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildAbortedEventTest.java
index cb7e24209..7b1f464f6 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildAbortedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildAbortedEventTest.java
@@ -48,7 +48,7 @@ of this software and associated documentation files (the "Software"), to deal
public class BuildAbortedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("");
@@ -63,24 +63,24 @@ public void testWithNothingSet() throws IOException, InterruptedException {
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("unknown"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job unknown build #0 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job unknown build #0 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job unknown build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -96,24 +96,24 @@ public void testWithNothingSet_parentFullName() throws IOException, InterruptedE
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/null build #0 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/null build #0 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job parentFullName/null build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName_2() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName_2() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parent»Full Name");
@@ -128,24 +128,24 @@ public void testWithNothingSet_parentFullName_2() throws IOException, Interrupte
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parent/FullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parent/FullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parent/FullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parent/FullName/null build #0 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parent/FullName/null build #0 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job parent/FullName/null build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_jobName() throws IOException, InterruptedException {
+ public void testWithNothingSet_jobName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -160,24 +160,24 @@ public void testWithNothingSet_jobName() throws IOException, InterruptedExceptio
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey(), event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals(event.getAggregationKey(), "parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job parentFullName/jobName build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_result() throws IOException, InterruptedException {
+ public void testWithNothingSet_result() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -191,25 +191,25 @@ public void testWithNothingSet_result() throws IOException, InterruptedException
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 5);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(5, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("result").contains("FAILURE"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job parentFullName/jobName build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -230,27 +230,27 @@ public void testWithEverythingSet() throws IOException, InterruptedException {
bd.setJenkinsUrl("https://jenkins.com");
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals("test-hostname-2"));
+ Assert.assertEquals("test-hostname-2", event.getHost());
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 6);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(6, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("node").contains("test-node"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("https://jenkins.com"));
Assert.assertTrue(event.getTags().get("branch").contains("test-branch"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 aborted on test-hostname-2"));
+ Assert.assertEquals("Job ParentFullName/JobName build #2 aborted on test-hostname-2", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job ParentFullName/JobName build #2](http://build_url.com) (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: test-hostname-2, Jenkins URL: [instance](https://jenkins.com)"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("https://jenkins.com"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("https://jenkins.com", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet_envVarsAndTags() throws IOException, InterruptedException {
+ public void testWithEverythingSet_envVarsAndTags() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -273,10 +273,10 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
bd.setHostname(hostname);
DatadogEvent event = new BuildAbortedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 7);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(7, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("tag1").contains("value1"));
Assert.assertTrue(event.getTags().get("tag2").contains("value2"));
@@ -284,11 +284,11 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("branch").contains("git-branch"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 aborted on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job ParentFullName/JobName build #2 aborted on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous aborted the [job ParentFullName/JobName build #2](http://build_url.com) (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildFinishedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildFinishedEventTest.java
index 97aa73b55..37e1eef33 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildFinishedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildFinishedEventTest.java
@@ -46,7 +46,7 @@ of this software and associated documentation files (the "Software"), to deal
public class BuildFinishedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("");
@@ -59,24 +59,24 @@ public void testWithNothingSet() throws IOException, InterruptedException {
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
+ Assert.assertEquals(event.getHost(), hostname);
+ Assert.assertEquals("unknown", event.getAggregationKey());
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("unknown"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job unknown build #0 unknown on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job unknown build #0 unknown on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job unknown build #0](unknown) finished with status unknown (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -89,20 +89,20 @@ public void testWithNothingSet_parentFullName() throws IOException, InterruptedE
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals(event.getHost(), hostname);
+ Assert.assertEquals("parentFullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/null build #0 unknown on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/null build #0 unknown on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName_2() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName_2() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parent»Full Name");
@@ -115,20 +115,20 @@ public void testWithNothingSet_parentFullName_2() throws IOException, Interrupte
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
- Assert.assertTrue(event.getAggregationKey().equals("parent/FullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals(event.getHost(), hostname);
+ Assert.assertEquals("parent/FullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parent/FullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parent/FullName/null build #0 unknown on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parent/FullName/null build #0 unknown on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_jobName() throws IOException, InterruptedException {
+ public void testWithNothingSet_jobName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -141,21 +141,21 @@ public void testWithNothingSet_jobName() throws IOException, InterruptedExceptio
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getText(), event.getTitle().equals("Job parentFullName/jobName build #0 unknown on " + hostname));
+ Assert.assertEquals(event.getText(), event.getTitle(), "Job parentFullName/jobName build #0 unknown on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_result_failure() throws IOException, InterruptedException {
+ public void testWithNothingSet_result_failure() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -168,25 +168,25 @@ public void testWithNothingSet_result_failure() throws IOException, InterruptedE
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 5);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(5, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("result").contains("FAILURE"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 failure on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 failure on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parentFullName/jobName build #0](unknown) finished with status failure (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_result_unstable() throws IOException, InterruptedException {
+ public void testWithNothingSet_result_unstable() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -199,25 +199,25 @@ public void testWithNothingSet_result_unstable() throws IOException, Interrupted
DatadogEvent event = new BuildFinishedEventImpl(bd);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 5);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(5, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("result").contains("UNSTABLE"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 unstable on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 unstable on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parentFullName/jobName build #0](unknown) finished with status unstable (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -238,10 +238,10 @@ public void testWithEverythingSet() throws IOException, InterruptedException {
bd.setJenkinsUrl("https://jenkins.com");
DatadogEvent event = new BuildFinishedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals("test-hostname-2"));
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
+ Assert.assertEquals("test-hostname-2", event.getHost());
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getTags().size() == 7);
+ Assert.assertEquals(7, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("result").contains("SUCCESS"));
Assert.assertTrue(event.getTags().get("node").contains("test-node"));
@@ -249,16 +249,16 @@ public void testWithEverythingSet() throws IOException, InterruptedException {
Assert.assertTrue(event.getTags().get("jenkins_url").contains("https://jenkins.com"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("test-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 success on test-hostname-2"));
+ Assert.assertEquals("Job ParentFullName/JobName build #2 success on test-hostname-2", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("[Job ParentFullName/JobName build #2](http://build_url.com) finished with status success (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: test-hostname-2, Jenkins URL: [instance](https://jenkins.com)"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("https://jenkins.com"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("https://jenkins.com", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet_envVarsAndTags() throws IOException, InterruptedException {
+ public void testWithEverythingSet_envVarsAndTags() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -281,10 +281,10 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
bd.setHostname(hostname);
DatadogEvent event = new BuildFinishedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 8);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(8, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("result").contains("SUCCESS"));
Assert.assertTrue(event.getTags().get("tag1").contains("value1"));
@@ -293,11 +293,11 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("git-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 success on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job ParentFullName/JobName build #2 success on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job ParentFullName/JobName build #2](http://build_url.com) finished with status success (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildStartedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildStartedEventTest.java
index 5523c09d1..e0029c53b 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildStartedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/BuildStartedEventTest.java
@@ -46,7 +46,7 @@ of this software and associated documentation files (the "Software"), to deal
public class BuildStartedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("");
@@ -61,24 +61,24 @@ public void testWithNothingSet() throws IOException, InterruptedException {
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("unknown"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job unknown build #0 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job unknown build #0 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job unknown build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -93,24 +93,24 @@ public void testWithNothingSet_parentFullName() throws IOException, InterruptedE
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/null build #0 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/null build #0 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job parentFullName/null build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName_2() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName_2() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parent»Full Name");
@@ -125,24 +125,24 @@ public void testWithNothingSet_parentFullName_2() throws IOException, Interrupte
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parent/FullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parent/FullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parent/FullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parent/FullName/null build #0 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parent/FullName/null build #0 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job parent/FullName/null build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_jobName() throws IOException, InterruptedException {
+ public void testWithNothingSet_jobName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -157,24 +157,24 @@ public void testWithNothingSet_jobName() throws IOException, InterruptedExceptio
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job parentFullName/jobName build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_result() throws IOException, InterruptedException {
+ public void testWithNothingSet_result() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -189,25 +189,25 @@ public void testWithNothingSet_result() throws IOException, InterruptedException
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 5);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(5, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("result").contains("FAILURE"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job parentFullName/jobName build #0](unknown) (0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -228,26 +228,26 @@ public void testWithEverythingSet() throws IOException, InterruptedException {
bd.setJenkinsUrl("https://jenkins.com");
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals("test-hostname-2"));
+ Assert.assertEquals("test-hostname-2", event.getHost());
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 6);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(6, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("node").contains("test-node"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("https://jenkins.com"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("test-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 started on test-hostname-2"));
+ Assert.assertEquals("Job ParentFullName/JobName build #2 started on test-hostname-2", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job ParentFullName/JobName build #2](http://build_url.com) (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: test-hostname-2, Jenkins URL: [instance](https://jenkins.com)"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("https://jenkins.com"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("https://jenkins.com", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet_envVarsAndTags() throws IOException, InterruptedException {
+ public void testWithEverythingSet_envVarsAndTags() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -270,10 +270,10 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
bd.setHostname(hostname);
DatadogEvent event = new BuildStartedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 7);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(7, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("tag1").contains("value1"));
Assert.assertTrue(event.getTags().get("tag2").contains("value2"));
@@ -281,11 +281,11 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("git-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 started on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job ParentFullName/JobName build #2 started on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous started the [job ParentFullName/JobName build #2](http://build_url.com) (0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerLaunchFailedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerLaunchFailedEventTest.java
index 717bc47e0..13a1fb4a5 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerLaunchFailedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerLaunchFailedEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,42 +39,42 @@ of this software and associated documentation files (the "Software"), to deal
public class ComputerLaunchFailedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ComputerLaunchFailedEventImpl(null, null, null);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey() == null);
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertNull(event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node null failed to launch"));
+ Assert.assertEquals("Jenkins node null failed to launch", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node null failed to launch"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
Computer computer = mock(Computer.class);
when(computer.getName()).thenReturn("computer");
DatadogEvent event = new ComputerLaunchFailedEventImpl(computer, null,
- new HashMap>());
+ new HashMap<>());
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("computer"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("computer", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node computer failed to launch"));
+ Assert.assertEquals("Jenkins node computer failed to launch", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node computer failed to launch"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOfflineEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOfflineEventTest.java
index 2851facd6..d2a5441ab 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOfflineEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOfflineEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,71 +39,71 @@ of this software and associated documentation files (the "Software"), to deal
public class ComputerOfflineEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ComputerOfflineEventImpl(null, null, null, false);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey() == null);
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertNull(event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node null is offline"));
+ Assert.assertEquals("Jenkins node null is offline", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node null is offline"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new ComputerOfflineEventImpl(null, null, null, true);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey() == null);
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertNull(event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node null is temporarily offline"));
+ Assert.assertEquals("Jenkins node null is temporarily offline", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node null is temporarily offline"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
Computer computer = mock(Computer.class);
when(computer.getName()).thenReturn("computer");
DatadogEvent event = new ComputerOfflineEventImpl(computer, null,
- new HashMap>(), false);
+ new HashMap<>(), false);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("computer"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("computer", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node computer is offline"));
+ Assert.assertEquals("Jenkins node computer is offline", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node computer is offline"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new ComputerOfflineEventImpl(computer, null,
- new HashMap>(), true);
+ new HashMap<>(), true);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("computer"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("computer", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node computer is temporarily offline"));
+ Assert.assertEquals("Jenkins node computer is temporarily offline", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node computer is temporarily offline"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.WARNING));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.WARNING, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOnlineEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOnlineEventTest.java
index dff906daf..da313ccba 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOnlineEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ComputerOnlineEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,71 +39,71 @@ of this software and associated documentation files (the "Software"), to deal
public class ComputerOnlineEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ComputerOnlineEventImpl(null, null, null, false);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey() == null);
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertNull(event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node null is online"));
+ Assert.assertEquals("Jenkins node null is online", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node null is online"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new ComputerOnlineEventImpl(null, null, null, true);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey() == null);
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertNull(event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node null is temporarily online"));
+ Assert.assertEquals("Jenkins node null is temporarily online", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node null is temporarily online"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
Computer computer = mock(Computer.class);
when(computer.getName()).thenReturn("computer");
DatadogEvent event = new ComputerOnlineEventImpl(computer, null,
- new HashMap>(), false);
+ new HashMap<>(), false);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("computer"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("computer", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node computer is online"));
+ Assert.assertEquals("Jenkins node computer is online", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node computer is online"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new ComputerOnlineEventImpl(computer, null,
- new HashMap>(), true);
+ new HashMap<>(), true);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("computer"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("computer", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("Jenkins node computer is temporarily online"));
+ Assert.assertEquals("Jenkins node computer is temporarily online", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("Jenkins node computer is temporarily online"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCRUDEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCRUDEventTest.java
index 878ecb4fe..e0126e0eb 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCRUDEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCRUDEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,84 +39,84 @@ of this software and associated documentation files (the "Software"), to deal
public class ItemCRUDEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ItemCRUDEventImpl(null, null, null);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous did something with the item unknown"));
+ Assert.assertEquals("User anonymous did something with the item unknown", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous did something with the item unknown"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new ItemCRUDEventImpl(null, "something", null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous something the item unknown"));
+ Assert.assertEquals("User anonymous something the item unknown", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous something the item unknown"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
FreeStyleProject item = mock(FreeStyleProject.class);
when(item.getName()).thenReturn("itemname");
- DatadogEvent event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.CREATED, new HashMap>());
+ DatadogEvent event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.CREATED, new HashMap<>());
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("itemname"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("itemname", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous created the item itemname"));
+ Assert.assertEquals("User anonymous created the item itemname", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous created the item itemname"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
- event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.UPDATED, new HashMap>());
+ event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.UPDATED, new HashMap<>());
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("itemname"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("itemname", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous updated the item itemname"));
+ Assert.assertEquals("User anonymous updated the item itemname", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous updated the item itemname"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
- event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.DELETED, new HashMap>());
+ event = new ItemCRUDEventImpl(item, ItemCRUDEventImpl.DELETED, new HashMap<>());
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("itemname"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("itemname", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous deleted the item itemname"));
+ Assert.assertEquals("User anonymous deleted the item itemname", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous deleted the item itemname"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCopiedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCopiedEventTest.java
index 7e1b5fd4b..158c0ef01 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCopiedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemCopiedEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,44 +39,44 @@ of this software and associated documentation files (the "Software"), to deal
public class ItemCopiedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ItemCopiedEventImpl(null, null, null);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous copied the item unknown from unknown"));
+ Assert.assertEquals("User anonymous copied the item unknown from unknown", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous copied the item unknown from unknown"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
FreeStyleProject src = mock(FreeStyleProject.class);
when(src.getName()).thenReturn("srcname");
FreeStyleProject item = mock(FreeStyleProject.class);
when(item.getName()).thenReturn("itemname");
- DatadogEvent event = new ItemCopiedEventImpl(src, item, new HashMap>());
+ DatadogEvent event = new ItemCopiedEventImpl(src, item, new HashMap<>());
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("itemname"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("itemname", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous copied the item itemname from srcname"));
+ Assert.assertEquals("User anonymous copied the item itemname from srcname", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous copied the item itemname from srcname"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemLocationChangedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemLocationChangedEventTest.java
index 26c8981fe..c3c0ce478 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemLocationChangedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/ItemLocationChangedEventTest.java
@@ -31,9 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,43 +39,43 @@ of this software and associated documentation files (the "Software"), to deal
public class ItemLocationChangedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new ItemLocationChangedEventImpl(null, null, null, null);
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous changed the location of the item unknown"));
+ Assert.assertEquals("User anonymous changed the location of the item unknown", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous changed the location of the item unknown from null to null"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() {
FreeStyleProject item = mock(FreeStyleProject.class);
when(item.getName()).thenReturn("itemname");
DatadogEvent event = new ItemLocationChangedEventImpl(item, "from_loc", "to_loc",
- new HashMap>());
+ new HashMap<>());
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("itemname"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("itemname", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("system"));
- Assert.assertTrue(event.getTitle().equals("User anonymous changed the location of the item itemname"));
+ Assert.assertEquals("User anonymous changed the location of the item itemname", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User anonymous changed the location of the item itemname from from_loc to to_loc"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.INFO));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.INFO, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/SCMCheckoutCompletedEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/SCMCheckoutCompletedEventTest.java
index 0299d0c70..4226c0d4a 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/SCMCheckoutCompletedEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/SCMCheckoutCompletedEventTest.java
@@ -46,7 +46,7 @@ of this software and associated documentation files (the "Software"), to deal
public class SCMCheckoutCompletedEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("");
@@ -61,24 +61,24 @@ public void testWithNothingSet() throws IOException, InterruptedException {
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("unknown"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("unknown", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("unknown"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job unknown build #0 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job unknown build #0 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job unknown build #0](unknown) checkout (branch: unknown ) finished successfully on host " + hostname + " (node: unknown )(0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -93,24 +93,24 @@ public void testWithNothingSet_parentFullName() throws IOException, InterruptedE
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/null build #0 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/null build #0 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parentFullName/null build #0](unknown) checkout (branch: unknown ) finished successfully on host " + hostname + " (node: unknown )(0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_parentFullName_2() throws IOException, InterruptedException {
+ public void testWithNothingSet_parentFullName_2() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parent»Full Name");
@@ -125,24 +125,24 @@ public void testWithNothingSet_parentFullName_2() throws IOException, Interrupte
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parent/FullName/null"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parent/FullName/null", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parent/FullName/null"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parent/FullName/null build #0 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parent/FullName/null build #0 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parent/FullName/null build #0](unknown) checkout (branch: unknown ) finished successfully on host " + hostname + " (node: unknown )(0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_jobName() throws IOException, InterruptedException {
+ public void testWithNothingSet_jobName() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -157,24 +157,24 @@ public void testWithNothingSet_jobName() throws IOException, InterruptedExceptio
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 4);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(4, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parentFullName/jobName build #0](unknown) checkout (branch: unknown ) finished successfully on host " + hostname + " (node: unknown )(0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithNothingSet_result() throws IOException, InterruptedException {
+ public void testWithNothingSet_result() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("parentFullName");
@@ -189,25 +189,25 @@ public void testWithNothingSet_result() throws IOException, InterruptedException
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("parentFullName/jobName"));
- Assert.assertTrue(event.getTags().size() == 5);
+ Assert.assertEquals("parentFullName/jobName", event.getAggregationKey());
+ Assert.assertEquals(5, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("parentFullName/jobName"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("result").contains("FAILURE"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
- Assert.assertTrue(event.getTitle().equals("Job parentFullName/jobName build #0 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job parentFullName/jobName build #0 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job parentFullName/jobName build #0](unknown) checkout (branch: unknown ) finished successfully on host " + hostname + " (node: unknown )(0.00 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
+ public void testWithEverythingSet() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -228,26 +228,26 @@ public void testWithEverythingSet() throws IOException, InterruptedException {
bd.setJenkinsUrl("https://jenkins.com");
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals("test-hostname-2"));
+ Assert.assertEquals("test-hostname-2", event.getHost());
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 6);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(6, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("node").contains("test-node"));
Assert.assertTrue(event.getTags().get("user_id").contains("anonymous"));
Assert.assertTrue(event.getTags().get("jenkins_url").contains("https://jenkins.com"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("test-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 checkout finished on test-hostname-2"));
+ Assert.assertEquals("Job ParentFullName/JobName build #2 checkout finished on test-hostname-2", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("[Job ParentFullName/JobName build #2](http://build_url.com) checkout (branch: test-branch ) finished successfully on host test-hostname-2 (node: test-node )(0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: test-hostname-2, Jenkins URL: [instance](https://jenkins.com)"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("https://jenkins.com"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("https://jenkins.com", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet_envVarsAndTags() throws IOException, InterruptedException {
+ public void testWithEverythingSet_envVarsAndTags() throws IOException {
Jenkins jenkins = mock(Jenkins.class);
when(jenkins.getFullName()).thenReturn("ParentFullName");
@@ -270,10 +270,10 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
bd.setHostname(hostname);
DatadogEvent event = new SCMCheckoutCompletedEventImpl(bd);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("ParentFullName/JobName"));
- Assert.assertTrue(event.getTags().size() == 7);
+ Assert.assertEquals("ParentFullName/JobName", event.getAggregationKey());
+ Assert.assertEquals(7, event.getTags().size());
Assert.assertTrue(event.getTags().get("job").contains("ParentFullName/JobName"));
Assert.assertTrue(event.getTags().get("tag1").contains("value1"));
Assert.assertTrue(event.getTags().get("tag2").contains("value2"));
@@ -281,11 +281,11 @@ public void testWithEverythingSet_envVarsAndTags() throws IOException, Interrupt
Assert.assertTrue(event.getTags().get("jenkins_url").contains("unknown"));
Assert.assertTrue(event.getTags().get("event_type").contains("default"));
Assert.assertTrue(event.getTags().get("branch").contains("git-branch"));
- Assert.assertTrue(event.getTitle().equals("Job ParentFullName/JobName build #2 checkout finished on " + hostname));
+ Assert.assertEquals(event.getTitle(), "Job ParentFullName/JobName build #2 checkout finished on " + hostname);
Assert.assertTrue(event.getText(), event.getText().contains("[Job ParentFullName/JobName build #2](http://build_url.com) checkout (branch: git-branch ) finished successfully on host " + hostname + " (node: unknown )(0.01 secs)"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/events/UserAuthenticationEventTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/events/UserAuthenticationEventTest.java
index bcf5ddd48..00516f1f6 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/events/UserAuthenticationEventTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/events/UserAuthenticationEventTest.java
@@ -30,85 +30,83 @@ of this software and associated documentation files (the "Software"), to deal
import org.junit.Assert;
import org.junit.Test;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
public class UserAuthenticationEventTest {
@Test
- public void testWithNothingSet() throws IOException, InterruptedException {
+ public void testWithNothingSet() {
DatadogEvent event = new UserAuthenticationEventImpl(null, null, null);
- Assert.assertTrue(event.getHost().equals(DatadogUtilities.getHostname(null)));
+ Assert.assertEquals(event.getHost(), DatadogUtilities.getHostname(null));
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("anonymous"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("anonymous", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("security"));
- Assert.assertTrue(event.getTitle().equals("User anonymous did something"));
+ Assert.assertEquals("User anonymous did something", event.getTitle());
Assert.assertTrue(event.getText().contains("User anonymous did something"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
event = new UserAuthenticationEventImpl(null, "something", null);
- Assert.assertTrue(event.getHost().equals(DatadogUtilities.getHostname(null)));
+ Assert.assertEquals(event.getHost(), DatadogUtilities.getHostname(null));
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("anonymous"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("anonymous", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("security"));
- Assert.assertTrue(event.getTitle().equals("User anonymous something"));
+ Assert.assertEquals("User anonymous something", event.getTitle());
Assert.assertTrue(event.getText().contains("User anonymous something"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
@Test
- public void testWithEverythingSet() throws IOException, InterruptedException {
- DatadogEvent event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE, new HashMap>());
+ public void testWithEverythingSet() {
+ DatadogEvent event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE, new HashMap<>());
String hostname = DatadogUtilities.getHostname(null);
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("username"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("username", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("security"));
- Assert.assertTrue(event.getTitle().equals("User username failed to authenticate"));
+ Assert.assertEquals("User username failed to authenticate", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User username failed to authenticate"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.ERROR));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.NORMAL));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.ERROR, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.NORMAL, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
- event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE, new HashMap>());
+ event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE, new HashMap<>());
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("username"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("username", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("security"));
- Assert.assertTrue(event.getTitle().equals("User username logout"));
+ Assert.assertEquals("User username logout", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User username logout"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
- event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_LOGIN_MESSAGE, new HashMap>());
+ event = new UserAuthenticationEventImpl("username", UserAuthenticationEventImpl.USER_LOGIN_MESSAGE, new HashMap<>());
- Assert.assertTrue(event.getHost().equals(hostname));
+ Assert.assertEquals(event.getHost(), hostname);
Assert.assertTrue(event.getDate() != 0);
- Assert.assertTrue(event.getAggregationKey().equals("username"));
- Assert.assertTrue(event.getTags().size() == 1);
+ Assert.assertEquals("username", event.getAggregationKey());
+ Assert.assertEquals(1, event.getTags().size());
Assert.assertTrue(event.getTags().get("event_type").contains("security"));
- Assert.assertTrue(event.getTitle().equals("User username authenticated"));
+ Assert.assertEquals("User username authenticated", event.getTitle());
Assert.assertTrue(event.getText(), event.getText().contains("User username authenticated"));
Assert.assertTrue(event.getText(), event.getText().contains("Host: " + hostname + ", Jenkins URL: unknown"));
- Assert.assertTrue(event.getAlertType().equals(DatadogEvent.AlertType.SUCCESS));
- Assert.assertTrue(event.getPriority().equals(DatadogEvent.Priority.LOW));
- Assert.assertTrue(event.getJenkinsUrl().equals("unknown"));
+ Assert.assertEquals(DatadogEvent.AlertType.SUCCESS, event.getAlertType());
+ Assert.assertEquals(DatadogEvent.Priority.LOW, event.getPriority());
+ Assert.assertEquals("unknown", event.getJenkinsUrl());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerIT.java b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerIT.java
index 607b64b3b..3143c2953 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerIT.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerIT.java
@@ -20,7 +20,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import com.github.stefanbirkner.systemlambda.SystemLambda;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.model.FreeStyleBuild;
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerTest.java
index 26f376c8f..4b4c1db59 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerTest.java
@@ -32,7 +32,6 @@ of this software and associated documentation files (the "Software"), to deal
import jenkins.model.Jenkins;
import org.datadog.jenkins.plugins.datadog.DatadogEvent.AlertType;
import org.datadog.jenkins.plugins.datadog.DatadogEvent.Priority;
-import org.datadog.jenkins.plugins.datadog.metrics.Metrics;
import org.datadog.jenkins.plugins.datadog.publishers.DatadogCountersPublisher;
import org.datadog.jenkins.plugins.datadog.stubs.BuildStub;
import org.datadog.jenkins.plugins.datadog.stubs.ProjectStub;
@@ -59,7 +58,7 @@ public class DatadogBuildListenerTest {
private Queue queue;
private WorkflowRun workflowRun;
EnvVars envVars;
-
+
@Before
public void setUpMocks() {
this.client = new DatadogClientStub();
@@ -316,11 +315,11 @@ public void testOnStarted() throws Exception {
expectedTags[4] = "jenkins_url:unknown";
expectedTags[5] = "branch:test-branch";
client.assertMetric("jenkins.job.started", 1, "test-hostname-2", expectedTags);
- Assert.assertTrue(client.metrics.size() == 1);
+ Assert.assertEquals(1, client.metrics.size());
DatadogMetric metric = client.metrics.get(0);
- Assert.assertTrue(metric.getName().equals("jenkins.job.waiting"));
+ Assert.assertEquals("jenkins.job.waiting", metric.getName());
Assert.assertTrue(metric.getValue() > 0);
- Assert.assertTrue(metric.getHostname().equals("test-hostname-2"));
+ Assert.assertEquals("test-hostname-2", metric.getHostname());
Assert.assertTrue(metric.getTags().containsAll(Arrays.asList(expectedTags)));
client.metrics.clear();
client.assertedAllMetricsAndServiceChecks();
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogFilteringEventsTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogFilteringEventsTest.java
index bf3a7cbe7..40c84be4c 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogFilteringEventsTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogFilteringEventsTest.java
@@ -2,7 +2,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -73,7 +72,7 @@ public void setUp() throws Exception {
public void includeAllEventsViaToggle() throws Exception {
this.assertAllIncludedEvents();
- assertTrue(this.client.events.size() == 17);
+ assertEquals(17, this.client.events.size());
}
@Test
@@ -81,11 +80,11 @@ public void includeAllEventsViaStringInput() throws Exception {
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
cfg.setEmitSecurityEvents(false);
cfg.setEmitSystemEvents(false);
- cfg.setIncludeEvents(String.format("%s,%s", DatadogGlobalConfiguration.SYSTEM_EVENTS,
+ cfg.setIncludeEvents(String.format("%s,%s", DatadogGlobalConfiguration.SYSTEM_EVENTS,
DatadogGlobalConfiguration.SECURITY_EVENTS));
this.assertAllIncludedEvents();
- assertTrue(this.client.events.size() == 17);
+ assertEquals(17, this.client.events.size());
}
@Test
@@ -96,7 +95,7 @@ public void excludeAllEventsViaToggle() throws Exception {
cfg.setExcludeEvents(DatadogGlobalConfiguration.DEFAULT_EVENTS);
this.runAllEvents();
- assertTrue(this.client.events.size() == 0);
+ assertEquals(0, this.client.events.size());
}
@Test
@@ -109,7 +108,7 @@ public void excludeAllEventsViaStringInput() throws Exception {
cfg.setExcludeEvents(allEvents);
this.runAllEvents();
- assertTrue(this.client.events.size() == 0);
+ assertEquals(0, this.client.events.size());
}
@Test
@@ -120,7 +119,7 @@ public void includeOnlySecurityEventsViaToggle() throws Exception {
this.runAllEvents();
this.assertSecurityEvents();
- assertTrue(this.client.events.size() == 3);
+ assertEquals(3, this.client.events.size());
}
@Test
@@ -134,7 +133,7 @@ public void includeOnlySecurityEventsViaStringInput() throws Exception {
this.runAllEvents();
this.assertSecurityEvents();
- assertTrue(this.client.events.size() == 3);
+ assertEquals(3, this.client.events.size());
}
@Test
@@ -145,7 +144,7 @@ public void includeOnlySystemEventsViaToggle() throws Exception {
this.runAllEvents();
this.assertSystemEvents();
- assertTrue(this.client.events.size() == 10);
+ assertEquals(10, this.client.events.size());
}
@Test
@@ -159,7 +158,7 @@ public void includeOnlySystemEventsViaStringInput() throws Exception {
this.runAllEvents();
this.assertSystemEvents();
- assertTrue(this.client.events.size() == 10);
+ assertEquals(10, this.client.events.size());
}
@Test
@@ -170,7 +169,7 @@ public void includeOnlyDefaultEventsViaStringInput() throws Exception {
this.runAllEvents();
this.assertDefaultEvents();
- assertTrue(this.client.events.size() == 4);
+ assertEquals(4, this.client.events.size());
}
@Test
@@ -186,7 +185,7 @@ public void excludeOnlySecurityEventsViaToggle() throws Exception {
this.runSecurityEvents();
- assertTrue(this.client.events.size() == 14);
+ assertEquals(14, this.client.events.size());
}
@Test
@@ -202,7 +201,7 @@ public void excludeOnlySecurityEventsViaStringInput() throws Exception {
this.runSecurityEvents();
- assertTrue(this.client.events.size() == 14);
+ assertEquals(14, this.client.events.size());
}
@Test
@@ -218,7 +217,7 @@ public void excludeOnlySystemEventsViaToggle() throws Exception {
this.runSecurityEvents();
this.assertSecurityEvents();
- assertTrue(this.client.events.size() == 7);
+ assertEquals(7, this.client.events.size());
}
@Test
@@ -234,7 +233,7 @@ public void excludeOnlySystemEventsViaStringInput() throws Exception {
this.runSecurityEvents();
this.assertSecurityEvents();
- assertTrue(this.client.events.size() == 7);
+ assertEquals(7, this.client.events.size());
}
@Test
@@ -249,7 +248,7 @@ public void excludeOnlyDefaultEventsViaStringInput() throws Exception {
this.runSecurityEvents();
this.assertSecurityEvents();
- assertTrue(this.client.events.size() == 13);
+ assertEquals(13, this.client.events.size());
}
@Test
@@ -269,9 +268,9 @@ public void includeMultipleEventsOfDifferentTypes() throws Exception {
DatadogEvent authEvent = this.client.events.get(2).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_LOGIN_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_LOGIN_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
- assertTrue(this.client.events.size() == 3);
+ assertEquals(3, this.client.events.size());
}
@Test
@@ -283,13 +282,13 @@ public void includeAllOneEventTypeExcludeOneByName() throws Exception {
this.runAllEvents();
DatadogEvent authEvent = this.client.events.get(0).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
authEvent = this.client.events.get(1).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
- assertTrue(this.client.events.size() == 2);
+ assertEquals(2, this.client.events.size());
}
@Test
@@ -305,7 +304,7 @@ public void excludeAllOneEventTypeIncludeOneByName() throws Exception {
assertTrue(computerEvent instanceof ComputerOnlineEventImpl);
assertFalse(((ComputerOnlineEventImpl) computerEvent).isTemporarily());
- assertTrue(this.client.events.size() == 1);
+ assertEquals(1, this.client.events.size());
}
@Test
@@ -327,7 +326,7 @@ public void includeSCMForJobIncludeGlobally() throws Exception {
this.datadogSCMListener.onCheckout(successRun, null, null, mock(TaskListener.class), null, null);
assertTrue(this.client.events.get(0).getEvent() instanceof SCMCheckoutCompletedEventImpl);
- assertTrue(this.client.events.size() == 1);
+ assertEquals(1, this.client.events.size());
}
@Test
@@ -417,7 +416,7 @@ public void testWithEnvVarsPart2() throws Exception {
}
@Test
- public void conflictingGlobalConfigsStrings() throws Exception {
+ public void conflictingGlobalConfigsStrings() {
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
environmentVariables.set("DATADOG_JENKINS_PLUGIN_EXCLUDE_EVENTS", "UserAuthenticated");
cfg.loadEnvVariables();
@@ -427,11 +426,11 @@ public void conflictingGlobalConfigsStrings() throws Exception {
FormValidation validation = cfg.doTestFilteringConfig(cfg.isEmitSecurityEvents(), cfg.isEmitSystemEvents(), cfg.getIncludeEvents(),
cfg.getExcludeEvents());
- assertEquals(validation.getMessage(), "The following events are in both the include and exclude lists: UserAuthenticated");
+ assertEquals("The following events are in both the include and exclude lists: UserAuthenticated", validation.getMessage());
}
@Test
- public void conflictingGlobalConfigsStrings2() throws Exception {
+ public void conflictingGlobalConfigsStrings2() {
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
environmentVariables.set("DATADOG_JENKINS_PLUGIN_INCLUDE_EVENTS", "BuildStarted,SCMCheckout");
cfg.loadEnvVariables();
@@ -442,11 +441,11 @@ public void conflictingGlobalConfigsStrings2() throws Exception {
FormValidation validation = cfg.doTestFilteringConfig(cfg.isEmitSecurityEvents(), cfg.isEmitSystemEvents(), cfg.getIncludeEvents(),
cfg.getExcludeEvents());
- assertEquals(validation.getMessage(), "The following events are in both the include and exclude lists: BuildStarted,SCMCheckout");
+ assertEquals("The following events are in both the include and exclude lists: BuildStarted,SCMCheckout", validation.getMessage());
}
@Test
- public void conflictingGlobalConfigsStringsGroovyOnly() throws Exception {
+ public void conflictingGlobalConfigsStringsGroovyOnly() {
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
cfg.setEmitSecurityEvents(false);
cfg.setIncludeEvents("UserAuthenticated");
@@ -454,11 +453,11 @@ public void conflictingGlobalConfigsStringsGroovyOnly() throws Exception {
FormValidation validation = cfg.doTestFilteringConfig(cfg.isEmitSecurityEvents(), cfg.isEmitSystemEvents(), cfg.getIncludeEvents(),
cfg.getExcludeEvents());
- assertEquals(validation.getMessage(), "The following events are in both the include and exclude lists: UserAuthenticated");
+ assertEquals("The following events are in both the include and exclude lists: UserAuthenticated", validation.getMessage());
}
@Test
- public void conflictingGlobalConfigsStrings2GroovyOnly() throws Exception {
+ public void conflictingGlobalConfigsStrings2GroovyOnly() {
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor();
cfg.setEmitSecurityEvents(false);
cfg.setEmitSystemEvents(false);
@@ -468,7 +467,7 @@ public void conflictingGlobalConfigsStrings2GroovyOnly() throws Exception {
FormValidation validation = cfg.doTestFilteringConfig(cfg.isEmitSecurityEvents(), cfg.isEmitSystemEvents(), cfg.getIncludeEvents(),
cfg.getExcludeEvents());
- assertEquals(validation.getMessage(), "The following events are in both the include and exclude lists: BuildStarted,SCMCheckout");
+ assertEquals("The following events are in both the include and exclude lists: BuildStarted,SCMCheckout", validation.getMessage());
}
@@ -508,7 +507,7 @@ private void runDefaultEvents() throws Exception {
this.datadogSCMListener.onCheckout(checkoutRun, null, null, mock(TaskListener.class), null, null);
}
- private void assertDefaultEvents() throws Exception {
+ private void assertDefaultEvents() {
int size = this.client.events.size();
assertTrue(this.client.events.get(size - 4).getEvent() instanceof BuildStartedEventImpl);
@@ -530,7 +529,7 @@ private void runSystemEvents() throws Exception {
this.datadogItemListener.onLocationChanged(job, null, null);
}
- private void assertSystemEvents() throws Exception {
+ private void assertSystemEvents() {
int size = this.client.events.size();
DatadogEvent computerEvent = this.client.events.get(size - 10).getEvent();
@@ -555,38 +554,38 @@ private void assertSystemEvents() throws Exception {
DatadogEvent itemEvent = this.client.events.get(size - 4).getEvent();
assertTrue(itemEvent instanceof ItemCRUDEventImpl);
- assertEquals(((ItemCRUDEventImpl) itemEvent).getAction(), ItemCRUDEventImpl.CREATED);
+ assertEquals(ItemCRUDEventImpl.CREATED, ((ItemCRUDEventImpl) itemEvent).getAction());
itemEvent = this.client.events.get(size - 3).getEvent();
assertTrue(itemEvent instanceof ItemCRUDEventImpl);
- assertEquals(((ItemCRUDEventImpl) itemEvent).getAction(), ItemCRUDEventImpl.UPDATED);
+ assertEquals(ItemCRUDEventImpl.UPDATED, ((ItemCRUDEventImpl) itemEvent).getAction());
itemEvent = this.client.events.get(size - 2).getEvent();
assertTrue(itemEvent instanceof ItemCRUDEventImpl);
- assertEquals(((ItemCRUDEventImpl) itemEvent).getAction(), ItemCRUDEventImpl.DELETED);
+ assertEquals(ItemCRUDEventImpl.DELETED, ((ItemCRUDEventImpl) itemEvent).getAction());
assertTrue(this.client.events.get(size - 1).getEvent() instanceof ItemLocationChangedEventImpl);
}
- private void runSecurityEvents() throws Exception {
+ private void runSecurityEvents() {
this.datadogSecurityListener.authenticated(mock(UserDetails.class));
this.datadogSecurityListener.failedToAuthenticate("testUser");
this.datadogSecurityListener.loggedOut("testUser");
}
- private void assertSecurityEvents() throws Exception {
+ private void assertSecurityEvents() {
int size = this.client.events.size();
DatadogEvent authEvent = this.client.events.get(size - 3).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_LOGIN_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_LOGIN_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
authEvent = this.client.events.get(size - 2).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_ACCESS_DENIED_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
authEvent = this.client.events.get(size - 1).getEvent();
assertTrue(authEvent instanceof UserAuthenticationEventImpl);
- assertEquals(((UserAuthenticationEventImpl) authEvent).getAction(), UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE);
+ assertEquals(UserAuthenticationEventImpl.USER_LOGOUT_MESSAGE, ((UserAuthenticationEventImpl) authEvent).getAction());
}
}
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListenerTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListenerTest.java
index 3acbd8921..9de3bff76 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListenerTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListenerTest.java
@@ -45,7 +45,6 @@
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jenkins.model.Jenkins;
@@ -494,7 +493,7 @@ private String getPipelineDefinition(String file) throws IOException {
String pipelineDefinition;
try (InputStream is = DatadogGraphListenerTest.class.getResourceAsStream(file)) {
- StringBuffer pipelineBuilder = new StringBuffer();
+ StringBuilder pipelineBuilder = new StringBuilder();
String pipelineTemplate = IOUtils.toString(is, StandardCharsets.UTF_8);
Matcher m = PLACEHOLDER_PATTERN.matcher(pipelineTemplate);
while (m.find()) {
@@ -1157,14 +1156,14 @@ public void getStageNameTest() {
// Regular stage with no thread
when(node.getAction(ThreadNameAction.class)).thenReturn(null);
- assertEquals(listener.getStageName(node), stageName);
+ assertEquals(stageName, listener.getStageName(node));
// Parallel stage
String stageNameThread = "Hello thread";
ThreadNameAction threadNameAction = mock(ThreadNameAction.class);
when(threadNameAction.getThreadName()).thenReturn(stageNameThread);
when(node.getAction(ThreadNameAction.class)).thenReturn(threadNameAction);
- assertEquals(listener.getStageName(node), stageNameThread);
+ assertEquals(stageNameThread, listener.getStageName(node));
}
@@ -1409,16 +1408,16 @@ public void testErrorPropagationOnStages() throws Exception {
assertEquals(3, spans.size());
final TraceSpan stepSpan = spans.get(2);
- assertEquals(true, stepSpan.isError());
+ assertTrue(stepSpan.isError());
assertEquals(CITags.STATUS_ERROR, stepSpan.getMeta().get(CITags.STATUS));
assertEquals(stepSpan.getMeta().get("error.stack"), "hudson.AbortException", stepSpan.getMeta().get(CITags.ERROR_TYPE));
final TraceSpan stageSpan = spans.get(1);
- assertEquals(true, stageSpan.isError());
+ assertTrue(stageSpan.isError());
assertEquals(CITags.STATUS_ERROR, stageSpan.getMeta().get(CITags.STATUS));
final TraceSpan buildSpan = spans.get(0);
- assertEquals(true, buildSpan.isError());
+ assertTrue(buildSpan.isError());
assertEquals(CITags.STATUS_ERROR, buildSpan.getMeta().get(CITags.STATUS));
}
@@ -1469,16 +1468,16 @@ public void testUnstablePropagationOnStages() throws Exception {
assertEquals(3, spans.size());
final TraceSpan stepSpan = spans.get(2);
- assertEquals(true, stepSpan.isError());
+ assertTrue(stepSpan.isError());
assertEquals(CITags.STATUS_UNSTABLE, stepSpan.getMeta().get(CITags.STATUS));
assertEquals("unstable", stepSpan.getMeta().get(CITags.ERROR_TYPE));
final TraceSpan stageSpan = spans.get(1);
- assertEquals(true, stageSpan.isError());
+ assertTrue(stageSpan.isError());
assertEquals(CITags.STATUS_UNSTABLE, stageSpan.getMeta().get(CITags.STATUS));
final TraceSpan buildSpan = spans.get(0);
- assertEquals(true, buildSpan.isError());
+ assertTrue(buildSpan.isError());
assertEquals(CITags.STATUS_UNSTABLE, buildSpan.getMeta().get(CITags.STATUS));
}
@@ -1679,7 +1678,7 @@ private void assertNodeNameParallelBlock(TraceSpan stageSpan, DumbSlave worker01
case "Prepare01":
case "Validate01":
assertEquals(worker01.getNodeName(), stageSpan.getMeta().get(CITags.NODE_NAME));
- assertTrue(((String) stageSpan.getMeta().get(CITags.NODE_LABELS)).contains(worker01.getNodeName()));
+ assertTrue(stageSpan.getMeta().get(CITags.NODE_LABELS).contains(worker01.getNodeName()));
break;
case "Prepare02":
case "Validate02":
@@ -1886,7 +1885,7 @@ private void givenPipeline(String name, String definitionPath) throws Exception
job.scheduleBuild2(0).get();
}
- private List whenExecuting(int expectedSpanCount) throws InterruptedException, TimeoutException {
+ private List whenExecuting(int expectedSpanCount) throws InterruptedException {
clientStub.waitForTraces(expectedSpanCount);
final List spans = clientStub.getSpans();
assertEquals(expectedSpanCount, spans.size());
diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/model/BuildDataTest.java b/src/test/java/org/datadog/jenkins/plugins/datadog/model/BuildDataTest.java
index d02c29b7a..003ccb459 100644
--- a/src/test/java/org/datadog/jenkins/plugins/datadog/model/BuildDataTest.java
+++ b/src/test/java/org/datadog/jenkins/plugins/datadog/model/BuildDataTest.java
@@ -18,7 +18,7 @@
import hudson.model.Node;
import hudson.model.Run;
import hudson.model.TaskListener;
-import java.io.IOException;
+
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
@@ -55,7 +55,7 @@ public void testJobNameIsTakenFromJobParentForMultibranchBuilds() throws Excepti
when(job.getParent()).thenAnswer((Answer>) (Answer