From a22f04771da02f714abab78022efdb38c8bc1fe3 Mon Sep 17 00:00:00 2001 From: Tim Jacomb <21194782+timja@users.noreply.github.com> Date: Sun, 30 Jan 2022 13:08:12 +0000 Subject: [PATCH] Remove CustomJenkinsFacade (#100) --- pom.xml | 2 +- .../builders/AciDeploymentTemplateBuilder.java | 10 +++------- .../containeragents/util/CustomJenkinsFacade.java | 15 --------------- .../AciDeploymentTemplateBuilderTest.java | 7 +++---- 4 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/com/microsoft/jenkins/containeragents/util/CustomJenkinsFacade.java diff --git a/pom.xml b/pom.xml index a698a0a..b8be266 100644 --- a/pom.xml +++ b/pom.xml @@ -139,7 +139,7 @@ io.jenkins.tools.bom bom-2.289.x - 1090.v0a_33df40457a_ + 1135.va_4eeca_ea_21c1 import pom diff --git a/src/main/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilder.java b/src/main/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilder.java index fd09a3e..a611312 100644 --- a/src/main/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilder.java +++ b/src/main/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilder.java @@ -18,7 +18,6 @@ import com.microsoft.jenkins.containeragents.util.AzureContainerUtils; import com.microsoft.jenkins.containeragents.util.Constants; import com.microsoft.jenkins.containeragents.util.DockerRegistryUtils; -import com.microsoft.jenkins.containeragents.util.CustomJenkinsFacade; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.EnvVars; import hudson.model.ItemGroup; @@ -43,15 +42,13 @@ public final class AciDeploymentTemplateBuilder { = "/com/microsoft/jenkins/containeragents/aci/deployTemplate.json"; private final JenkinsFacade jenkins; - private final CustomJenkinsFacade customJenkinsFacade; public AciDeploymentTemplateBuilder() { - this(new JenkinsFacade(), new CustomJenkinsFacade()); + this(new JenkinsFacade()); } - AciDeploymentTemplateBuilder(JenkinsFacade jenkins, CustomJenkinsFacade customJenkinsFacade) { + AciDeploymentTemplateBuilder(JenkinsFacade jenkins) { this.jenkins = jenkins; - this.customJenkinsFacade = customJenkinsFacade; } @NonNull @@ -77,8 +74,7 @@ public AciDeploymentTemplate buildDeploymentTemplate(AciCloud cloud, AciContaine } variables.put("cpu", template.getCpu()); variables.put("memory", template.getMemory()); - variables.put("jenkinsInstance", - customJenkinsFacade.getLegacyInstanceId()); + variables.put("jenkinsInstance", jenkins.getLegacyInstanceId()); addLogAnalytics(tmp, parameters, mapper, cloud); addCommandNode(tmp, template.getCommand(), agent); diff --git a/src/main/java/com/microsoft/jenkins/containeragents/util/CustomJenkinsFacade.java b/src/main/java/com/microsoft/jenkins/containeragents/util/CustomJenkinsFacade.java deleted file mode 100644 index c5b2685..0000000 --- a/src/main/java/com/microsoft/jenkins/containeragents/util/CustomJenkinsFacade.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.microsoft.jenkins.containeragents.util; - -import jenkins.model.Jenkins; - -/** - * Facade to Jenkins instance . Encapsulates all calls to Jenkins instance so that tests can replace this facade - * with a stub. It is inspired by Jenkins Facade of plugin-util-api-plugin. - * - */ -public class CustomJenkinsFacade { - - public String getLegacyInstanceId() { - return Jenkins.get().getLegacyInstanceId(); - } -} diff --git a/src/test/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilderTest.java b/src/test/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilderTest.java index a1e951b..2794e8e 100644 --- a/src/test/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilderTest.java +++ b/src/test/java/com/microsoft/jenkins/containeragents/builders/AciDeploymentTemplateBuilderTest.java @@ -5,7 +5,6 @@ import com.microsoft.jenkins.containeragents.aci.AciCloud; import com.microsoft.jenkins.containeragents.aci.AciContainerTemplate; import com.microsoft.jenkins.containeragents.aci.AciPrivateIpAddress; -import com.microsoft.jenkins.containeragents.util.CustomJenkinsFacade; import hudson.slaves.RetentionStrategy; import hudson.slaves.SlaveComputer; import io.jenkins.plugins.util.JenkinsFacade; @@ -31,10 +30,10 @@ public void setup(){ SlaveComputer slaveMock = mock(SlaveComputer.class); when(agentMock.getComputer()).thenReturn(slaveMock); - CustomJenkinsFacade customJenkinsFacadeMock = mock(CustomJenkinsFacade.class); - when(customJenkinsFacadeMock.getLegacyInstanceId()).thenReturn("instanceId"); + JenkinsFacade jenkinsFacade = mock(JenkinsFacade.class); + when(jenkinsFacade.getLegacyInstanceId()).thenReturn("instanceId"); - builderUnderTest = new AciDeploymentTemplateBuilder(mock(JenkinsFacade.class), customJenkinsFacadeMock); + builderUnderTest = new AciDeploymentTemplateBuilder(jenkinsFacade); } @Test