From a9ebf5f2de5c9b0bbf084695e3165f39cad7ae6e Mon Sep 17 00:00:00 2001 From: Stephane Bouchet Date: Mon, 22 Jul 2024 15:03:08 +0200 Subject: [PATCH] fix telemetry extension name Signed-off-by: Stephane Bouchet --- .../openshift/telemetry/TelemetryService.java | 9 +++++++-- .../tree/application/ApplicationRootNodeOdoTest.java | 12 ++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/tools/intellij/openshift/telemetry/TelemetryService.java b/src/main/java/org/jboss/tools/intellij/openshift/telemetry/TelemetryService.java index 5f784967c..f7582ed65 100644 --- a/src/main/java/org/jboss/tools/intellij/openshift/telemetry/TelemetryService.java +++ b/src/main/java/org/jboss/tools/intellij/openshift/telemetry/TelemetryService.java @@ -12,6 +12,7 @@ import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.extensions.DefaultPluginDescriptor; import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder; import com.redhat.devtools.intellij.telemetry.core.util.Lazy; @@ -49,10 +50,14 @@ public enum TelemetryResult { private static TelemetryService instance; - private final Lazy builder = new Lazy<>(() -> new TelemetryMessageBuilder(PluginManager.getPluginByClass(this.getClass()))); + private Lazy builder = null; private TelemetryService() { - // prevent instantiation + if (!ApplicationManager.getApplication().isUnitTestMode()) { + builder = new Lazy<>(() -> new TelemetryMessageBuilder(PluginManager.getPluginByClass(this.getClass()))); + } else { + builder = new Lazy<>(() -> new TelemetryMessageBuilder(new DefaultPluginDescriptor(""))); + } } public static TelemetryService instance() { diff --git a/src/test/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdoTest.java b/src/test/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdoTest.java index d78decd6c..03646216f 100644 --- a/src/test/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdoTest.java +++ b/src/test/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationRootNodeOdoTest.java @@ -59,7 +59,7 @@ public class ApplicationRootNodeOdoTest { public void before() throws IOException { this.odo = mock(OdoDelegate.class); this.rootNode = mock(ApplicationsRootNode.class); - this.fileOperations = mockFileOperations(tempDir, destinationDir); + this.fileOperations = mockFileOperations(); OdoProcessHelper processHelper = mock(OdoProcessHelper.class); this.rootNodeOdo = new ApplicationRootNodeOdo(odo, false, processHelper, rootNode, fileOperations); } @@ -193,12 +193,12 @@ private void mockGetComponents(ComponentDescriptor descriptor, ApplicationsRootN .when(rootNode).getLocalComponents(); } - private ApplicationRootNodeOdo.FileOperations mockFileOperations(File tempDir, File destinationDir) throws IOException { - ApplicationRootNodeOdo.FileOperations fileOperations = mock(ApplicationRootNodeOdo.FileOperations.class); + private ApplicationRootNodeOdo.FileOperations mockFileOperations() throws IOException { + ApplicationRootNodeOdo.FileOperations newFileOperations = mock(ApplicationRootNodeOdo.FileOperations.class); doReturn(tempDir) - .when(fileOperations).createTempDir(any()); + .when(newFileOperations).createTempDir(any()); doReturn(destinationDir) - .when(fileOperations).copyTo(any(), any()); - return fileOperations; + .when(newFileOperations).copyTo(any(), any()); + return newFileOperations; } }