[tests] adds missing Javadoc generator test cases

This commit is contained in:
Roman Shevchenko
2018-12-19 16:34:39 +01:00
parent 1a9aba6ee9
commit 093fb62672
9 changed files with 74 additions and 23 deletions
@@ -0,0 +1 @@
<html><head><base href="placeholder"></head><body><div class='definition'><pre>module <b>java.base</b></pre></div>
@@ -0,0 +1,3 @@
package packageHtml;
class Foo { }
@@ -0,0 +1,5 @@
<html>
<body>
Some text.
</body>
</html>
@@ -0,0 +1,3 @@
<div class='content'>
Some text.
</div><table class='sections'><p></table>
@@ -0,0 +1,11 @@
<html><head><base href="placeholder"></head><body><div class='definition'><pre><a href="psi_element://E"><code>E</code></a><br><i>@<a href="psi_element://org.jetbrains.annotations.Contract"><code>Contract</code></a>(value = &quot; -&gt; new&quot;,&nbsp;pure = true)</i>&nbsp;
public static&nbsp;<a href="psi_element://E"><code>E</code></a>[]&nbsp;<b>values</b>()</pre></div><div class='content'>
Returns an array containing the constants of this enum
type, in the order they're declared. This method may be
used to iterate over the constants as follows:
<pre>
for(E c : E.values())
System.out.println(c);
</pre>
<p></div><table class='sections'><p><tr><td valign='top' class='section'><p>Returns:</td><td valign='top'><p>an array containing the constants of this enum type, in the order they're declared</td><tr><td valign='top' class='section'><p><i>Inferred</i> annotations:</td><td valign='top'><p><i>@<a href="psi_element://org.jetbrains.annotations.Contract">org.jetbrains.annotations.Contract</a>(value = &quot; -&gt; new&quot;,&nbsp;pure = true)</i></td></table>
@@ -0,0 +1,7 @@
enum E {
E1, E2;
static int count() {
return <caret>values().length;
}
}
@@ -0,0 +1 @@
<html><head><base href="placeholder"></head><body><div class='definition'><pre><a href="psi_element://A"><code>A</code></a>&lt;<a href="psi_element://java.lang.String"><code>String</code></a>&gt; <b>a = new <a href="psi_element://A"><code>A</code></a>&lt;<a href="psi_element://java.lang.String"><code>String</code></a>&gt;()</b></pre></div><table class='sections'></table>
@@ -0,0 +1,6 @@
class A<T> {
static {
A<String> a = new A<String>();
<caret>a.getClass();
}
}
@@ -25,6 +25,7 @@ import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.lang.JavaVersion;
import com.intellij.util.ui.UIUtil;
import org.intellij.lang.annotations.Flow;
@@ -39,7 +40,7 @@ import java.util.List;
public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
private static final String TEST_DATA_FOLDER = "/codeInsight/javadocIG/";
private boolean myUseJava8Sdk;
private int myJdkVersion = 7;
@Override
protected String getTestDataPath() {
@@ -48,7 +49,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
@Override
protected Sdk getTestProjectJdk() {
return myUseJava8Sdk ? IdeaTestUtil.getMockJdk18() : IdeaTestUtil.getMockJdk17();
return IdeaTestUtil.getMockJdk(JavaVersion.compose(myJdkVersion));
}
public void testSimpleField() { doTestField(); }
@@ -99,6 +100,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
public void testLiteralInsideCode() { useJava8(); doTestClass(); }
public void testSuperJavadocExactResolve() { doTestAtCaret(); }
public void testSuperJavadocErasureResolve() { doTestAtCaret(); }
public void testPackageInfo() { doTestPackageInfo(); }
public void testPackageHtml() { doTestPackageInfo(); }
public void testSyntheticEnumValues() { doTestAtCaret(); }
public void testVariableDoc() { doTestAtCaret(); }
public void testAnonymousAndSuperJavadoc() {
PsiClass psiClass = PsiTreeUtil.findChildOfType(getTestClass(), PsiAnonymousClass.class);
@@ -142,17 +147,6 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
assertFileTextEquals(UIUtil.getHtmlBody(docInfo));
}
public void testPackageInfo() {
String path = JavaTestUtil.getJavaTestDataPath() + TEST_DATA_FOLDER;
String packageInfo = path + getTestName(true);
createProjectStructure(path);
PsiPackage psiPackage = myJavaFacade.findPackage(getTestName(true));
String info = JavaDocumentationProvider.generateExternalJavadoc(psiPackage, (List<String>)null);
assertNotNull(info);
String htmlText = loadFile(new File(packageInfo, "packageInfo.html"));
assertEquals(htmlText, replaceEnvironmentDependentContent(info));
}
public void testInheritedParameter() {
configureByFile();
PsiClass outerClass = ((PsiJavaFile) myFile).getClasses()[0];
@@ -246,6 +240,16 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
verifyJavaDoc(aPackage);
}
public void testModuleInfo() {
myJdkVersion = 9;
setUpJdk();
PsiClass aClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT);
assertNotNull(aClass);
PsiFile moduleFile = aClass.getContainingFile().getParent().getParentDirectory().getParentDirectory().findFile("module-info.class");
assertNotNull(moduleFile);
verifyJavaDoc(((PsiJavaFile)moduleFile).getModuleDeclaration());
}
private void doTestClass() {
PsiClass psiClass = getTestClass();
verifyJavaDoc(psiClass);
@@ -296,16 +300,22 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
assertEquals(StringUtil.convertLineSeparators(htmlFile.getText().trim()), replaceEnvironmentDependentContent(doc));
}
private void doTestPackageInfo() {
createProjectStructure(getTestDataPath() + TEST_DATA_FOLDER);
PsiPackage psiPackage = myJavaFacade.findPackage(getTestName(true));
assertNotNull(psiPackage);
String info = JavaDocumentationProvider.generateExternalJavadoc(psiPackage, (List<String>)null);
assertFileTextEquals(info, getTestName(true) + "/packageInfo.html");
}
private void doTestPackageInfo(String caretPositionedAt) {
String rootPath = getTestDataPath() + TEST_DATA_FOLDER;
VirtualFile root = createProjectStructure(rootPath);
VirtualFile piFile = root.findFileByRelativePath(getTestName(true) + "/package-info.java");
assertNotNull(piFile);
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(piFile);
VirtualFile root = createProjectStructure(getTestDataPath() + TEST_DATA_FOLDER);
VirtualFile file = root.findFileByRelativePath(getTestName(true) + "/package-info.java");
assertNotNull(file);
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
assertNotNull(psiFile);
String info = JavaExternalDocumentationTest.getDocumentationText(psiFile, psiFile.getText().indexOf(caretPositionedAt));
String htmlText = loadFile(new File(rootPath + getTestName(true) + File.separator + "packageInfo.html"));
assertEquals(htmlText, replaceEnvironmentDependentContent(info));
assertFileTextEquals(info, getTestName(true) + "/packageInfo.html");
}
private VirtualFile createProjectStructure(String rootPath) {
@@ -334,8 +344,12 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
}
private void assertFileTextEquals(String docInfo) {
assertFileTextEquals(docInfo, getTestName(true) + ".html");
}
private void assertFileTextEquals(String docInfo, String expectedFile) {
String actualText = replaceEnvironmentDependentContent(docInfo);
File htmlPath = new File(getTestDataPath() + TEST_DATA_FOLDER + getTestName(true) + ".html");
File htmlPath = new File(getTestDataPath() + TEST_DATA_FOLDER + expectedFile);
String expectedText = loadFile(htmlPath);
if (!StringUtil.equals(expectedText, actualText)) {
String message = "Text mismatch in file: " + htmlPath.getName();
@@ -344,12 +358,12 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
}
private void useJava8() {
myUseJava8Sdk = true;
myJdkVersion = 8;
setUpJdk();
}
private void useJava7() {
myUseJava8Sdk = false;
myJdkVersion = 7;
setUpJdk();
}