Repository: apache/netbeans
Issue: Unit test on single file is converted to integration test

### Apache NetBeans version

Apache NetBeans 14

### What happened

I noticed that my Netesta plugin does not work anymore with Netbeans 14.
Each time it tries to apply `ActionProvider.COMMAND_TEST_SINGLE`, the action is replaced by the new `COMMAND_INTEGRATION_TEST_SINGLE`.

### How to reproduce

I use Netesta plugin to automatically trigger unit tests on a single file

### Did this work correctly in an earlier version?

Apache NetBeans 13

### Operating System

Ubuntu

### JDK

1.8, 11, 17 & 18

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

I have done some debugging, so I can tell where the problem occurs. 

In the class `DefaultReplaceTokenProvider`, in the method `isIntegrationTestTarget`, the variable `targetFiles` can be also empty (and not only `null`)

In this case, the `allMatch` method of the stream return `true` whereas there are no files.

### Are you willing to submit a pull request?

No

### Code of Conduct

Yes

Changed files:
java/maven/test/unit/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProviderTest.java
java/maven/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProvider.java

diff --git a/java/maven/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProvider.java b/java/maven/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProvider.java
index b6212bf21c..186a3bf618 100644
--- a/java/maven/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProvider.java
+++ b/java/maven/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProvider.java
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.api.java.project.JavaProjectConstants;
 import org.netbeans.api.java.queries.UnitTestForSourceQuery;
@@ -359,13 +360,9 @@ public class DefaultReplaceTokenProvider implements ReplaceTokenProvider, Action
     }
 
     private boolean isIntegrationTestTarget(Lookup lookup) {
-        final SingleMethod targetMethod = lookup.lookup(SingleMethod.class); //JavaDataObject
-        if (targetMethod != null) {
-            return isIntegrationTestFile(targetMethod.getFile());
-        } 
-        final Collection<? extends FileObject> targetFiles = lookup.lookupAll(FileObject.class);
-        if (targetFiles != null) {
-            return targetFiles.stream().allMatch(file -> isIntegrationTestFile(file));
+        FileObject[] targetFiles = extractFileObjectsfromLookup(lookup);
+        if (targetFiles.length > 0) {
+            return Stream.of(targetFiles).allMatch(file -> isIntegrationTestFile(file));
         }
         return false;
     }
diff --git a/java/maven/test/unit/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProviderTest.java b/java/maven/test/unit/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProviderTest.java
index 394a23f22d..f023b38b5f 100644
--- a/java/maven/test/unit/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProviderTest.java
+++ b/java/maven/test/unit/src/org/netbeans/modules/maven/execute/DefaultReplaceTokenProviderTest.java
@@ -28,6 +28,7 @@ import org.netbeans.spi.project.ActionProvider;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.test.TestFileUtils;
+import org.openide.loaders.DataObject;
 import org.openide.util.Lookup;
 import org.openide.util.lookup.Lookups;
 
@@ -73,6 +74,31 @@ public class DefaultReplaceTokenProviderTest extends NbTestCase {
         assertEquals(null, ActionProviderImpl.replacements(p, ActionProvider.COMMAND_RUN, Lookup.EMPTY).get(DefaultReplaceTokenProvider.CLASSNAME_EXT));
 
     }
+    
+    public void testTestNotIT_GH4587() throws Exception {
+        TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
+                + "<groupId>g</groupId><artifactId>a</artifactId><version>0</version></project>");
+        TestFileUtils.writeFile(d, "src/test/java/p1/FirstTest.java", "package p1; class FirstTest {}");
+        TestFileUtils.writeFile(d, "src/test/java/p1/FirstIT.java", "package p1; class FirstIT {}");
+        Project p = ProjectManager.getDefault().findProject(d);
+        DefaultReplaceTokenProvider instance = new DefaultReplaceTokenProvider(p);
+        FileObject file = d.getFileObject("src/test/java/p1/FirstTest.java");
+        String converted = instance.convert(ActionProvider.COMMAND_TEST_SINGLE, Lookups.singleton(file));
+        assertNull(converted);
+        converted = instance.convert(ActionProvider.COMMAND_DEBUG_TEST_SINGLE, Lookups.singleton(file));
+        assertNull(converted);
+        DataObject dob = DataObject.find(file);
+        converted = instance.convert(ActionProvider.COMMAND_TEST_SINGLE, Lookups.singleton(dob));
+        assertNull(converted);
+        converted = instance.convert(ActionProvider.COMMAND_DEBUG_TEST_SINGLE, Lookups.singleton(dob));
+        assertNull(converted);
+        file = d.getFileObject("src/test/java/p1/FirstIT.java");
+        converted = instance.convert(ActionProvider.COMMAND_TEST_SINGLE, Lookups.singleton(file));
+        assertEquals(ActionProviderImpl.COMMAND_INTEGRATION_TEST_SINGLE, converted);
+        dob = DataObject.find(file);
+        converted = instance.convert(ActionProvider.COMMAND_TEST_SINGLE, Lookups.singleton(dob));
+        assertEquals(ActionProviderImpl.COMMAND_INTEGRATION_TEST_SINGLE, converted);
+    }
 
     public void testNgSingle() throws Exception {
         TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"