[maven][IDEA-381874] add some tests

(cherry picked from commit 54b788d631b8ea827692437a3b89f1a215edc009)

IJ-CR-182728

GitOrigin-RevId: 2a564ed0a016da725aa795d9470e8dd85782eacb
This commit is contained in:
Alexander Bubenchikov
2025-11-18 15:22:00 +00:00
committed by intellij-monorepo-bot
parent 6d82e40650
commit 0a26a90684
3 changed files with 48 additions and 1 deletions
@@ -1982,7 +1982,7 @@ object MavenUtil {
fun isMaven410(xmlns: String?, schemaLocation: String?): Boolean {
if (xmlns == null || schemaLocation == null) return false
val schemaLocations = schemaLocation.split(' ')
val schemaLocations = schemaLocation.split(' ', '\n')
return (xmlns == MAVEN_4_XMLNS || xmlns == MAVEN_4_XMLNS_HTTPS)
&& schemaLocations.all {
it.isNullOrBlank() ||
@@ -69,6 +69,40 @@ class MavenNewModelVersionInOldSchemaInspectionTest: MavenDomTestCase() {
checkHighlighting()
}
@Test
fun testCheckNotHighlightingModel4_1_manySpaces() = runBlocking{
assumeModel_4_1_0("testing only for model 4.1.0")
setRawPomFile("""<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 http://maven.apache.org/xsd/maven-4.1.0.xsd">
<modelVersion>4.1.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
</project>
""".trimIndent())
checkHighlighting()
}
@Test
fun testCheckNotHighlightingModel4_1_newLine() = runBlocking{
assumeModel_4_1_0("testing only for model 4.1.0")
setRawPomFile("""<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0
http://maven.apache.org/xsd/maven-4.1.0.xsd">
<modelVersion>4.1.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
</project>
""".trimIndent())
checkHighlighting()
}
@Test
fun testCheckNotHighlightingModel4_1_underscore() = runBlocking{
assumeModel_4_1_0("testing only for model 4.1.0")
@@ -99,4 +99,17 @@ public class MavenUtilTest extends MavenTestCase {
Files.writeString(file.toNioPath(), str, StandardCharsets.ISO_8859_1);
assertEquals("mytestpath", MavenUtil.getRepositoryFromSettings(file.toNioPath()));
}
public void testIsMaven41() throws IOException {
assertFalse(MavenUtil.INSTANCE.isMaven410(null, null));
assertFalse(MavenUtil.INSTANCE.isMaven410(null, "http://maven.apache.org/POM/4.1.0 http://maven.apache.org/xsd/maven-4.1.0.xsd"));
assertFalse(MavenUtil.INSTANCE.isMaven410("http://maven.apache.org/POM/4.1.0", null));
assertFalse(MavenUtil.INSTANCE.isMaven410("http://maven.apache.org/POM/4.1.0", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"));
assertFalse(MavenUtil.INSTANCE.isMaven410("http://maven.apache.org/POM/4.0.0", "http://maven.apache.org/POM/4.1.0 http://maven.apache.org/xsd/maven-4.1.0.xsd"));
assertTrue(MavenUtil.INSTANCE.isMaven410("http://maven.apache.org/POM/4.1.0", "http://maven.apache.org/POM/4.1.0 http://maven.apache.org/xsd/maven-4.1.0.xsd"));
assertTrue(MavenUtil.INSTANCE.isMaven410("https://maven.apache.org/POM/4.1.0", "https://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd"));
assertTrue(MavenUtil.INSTANCE.isMaven410("https://maven.apache.org/POM/4.1.0", "https://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd"));
assertTrue(MavenUtil.INSTANCE.isMaven410("https://maven.apache.org/POM/4.1.0", "https://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd https://maven.apache.org/maven-v4_1_0.xsd"));
assertTrue(MavenUtil.INSTANCE.isMaven410("https://maven.apache.org/POM/4.1.0", "https://maven.apache.org/POM/4.1.0\nhttps://maven.apache.org/xsd/maven-4.1.0.xsd\n https://maven.apache.org/maven-v4_1_0.xsd"));
}
}