mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
Also: avoid manual mocking of Java 10 classes in StreamCollector10Inlining test, use mockJDK11 instead Also: rewrite SliceTestCase and its inheritors to LightJavaCodeInsightFixtureTestCase, as annotations.jar is not included into project created by DaemonAnalyzerTestCase Also: 'mutates' attribute of @Contract annotation is resolvable now, as we can use newer jetbrains-annotations library. Also: documentation tests now don't generate links to JetBrains annotations, which corresponds to the actual behavior in production GitOrigin-RevId: e460826893c1277cb2b78b18aae9d5aca97d8333
91 lines
3.6 KiB
Kotlin
91 lines
3.6 KiB
Kotlin
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
|
package com.intellij.codeInspection.i18n
|
|
|
|
import com.intellij.codeInsight.assertFolded
|
|
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
|
import com.intellij.testFramework.IdeaTestUtil
|
|
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder
|
|
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
|
|
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
|
import com.intellij.util.PathUtil
|
|
|
|
class PropertyKeyFoldingTest : JavaCodeInsightFixtureTestCase() {
|
|
|
|
override fun setUp() {
|
|
super.setUp()
|
|
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations)
|
|
}
|
|
|
|
override fun tuneFixture(moduleBuilder: JavaModuleFixtureBuilder<*>) {
|
|
super.tuneFixture(moduleBuilder)
|
|
moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().path)
|
|
moduleBuilder.addLibrary("util-rt", PathUtil.getJarPathForClass(com.intellij.BundleBase::class.java))
|
|
}
|
|
|
|
@Suppress("UnresolvedPropertyKey")
|
|
fun testSingleProperty() {
|
|
myFixture.addFileToProject("i18n.properties", "com.example.localization.welcomeMessage=Welcome to our App!")
|
|
myFixture.addClass("""
|
|
import org.jetbrains.annotations.PropertyKey;
|
|
import java.util.ResourceBundle;
|
|
|
|
public class MyClass {
|
|
private final static String BUNDLE_NAME = "i18n";
|
|
private final static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
|
|
|
|
public static void main(String[] args) {
|
|
System.out.print(getMessage("com.example.localization.welcomeMessage"));
|
|
System.out.print(MyClass.getMessage("com.example.localization.welcomeMessage"));
|
|
}
|
|
|
|
|
|
public static String getMessage(@PropertyKey(resourceBundle = BUNDLE_NAME) String key) {
|
|
return BUNDLE.getString(key);
|
|
}
|
|
}
|
|
""".trimIndent())
|
|
|
|
|
|
myFixture.testHighlighting("MyClass.java")
|
|
|
|
with(myFixture.editor) {
|
|
assertFolded("getMessage(\"com.example.localization.welcomeMessage\")", "\"Welcome to our App!\"")
|
|
assertFolded("MyClass.getMessage(\"com.example.localization.welcomeMessage\")", "\"Welcome to our App!\"")
|
|
}
|
|
|
|
}
|
|
|
|
@Suppress("UnresolvedPropertyKey")
|
|
fun testPropertyWithParameters() {
|
|
myFixture.addFileToProject("i18n.properties", "com.example.localization.welcomeMessage=Welcome {0} to our App!")
|
|
myFixture.addClass("""
|
|
import org.jetbrains.annotations.PropertyKey;
|
|
import java.util.ResourceBundle;
|
|
import com.intellij.BundleBase;
|
|
|
|
public class MyClass {
|
|
private final static String BUNDLE_NAME = "i18n";
|
|
private final static ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
|
|
|
|
public static void main(String[] args) {
|
|
System.out.print(getMessage("com.example.localization.welcomeMessage", "My Friend"));
|
|
String param = args[0];
|
|
System.out.print(MyClass.getMessage("com.example.localization.welcomeMessage", param));
|
|
}
|
|
|
|
public static String getMessage(@PropertyKey(resourceBundle = BUNDLE_NAME) String key, Object... params) {
|
|
return BundleBase.message(BUNDLE, key, params);
|
|
}
|
|
}
|
|
""".trimIndent())
|
|
|
|
myFixture.testHighlighting("MyClass.java")
|
|
|
|
with(myFixture.editor) {
|
|
assertFolded("getMessage(\"com.example.localization.welcomeMessage\", \"My Friend\")", "\"Welcome My Friend to our App!\"")
|
|
assertFolded("MyClass.getMessage(\"com.example.localization.welcomeMessage\", param)", "\"Welcome {param} to our App!\"")
|
|
}
|
|
|
|
}
|
|
|
|
} |