forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinemarkerFixtureTestCase.java
83 lines (71 loc) · 3.03 KB
/
LinemarkerFixtureTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.linemarker;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
import com.magento.idea.magento2plugin.BaseProjectTestCase;
import com.magento.idea.magento2plugin.magento.packages.File;
import java.util.List;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
public abstract class LinemarkerFixtureTestCase extends BaseProjectTestCase {
private static final String TEST_DATA_PATH
= "testData" + File.separator + "linemarker" + File.separator;
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.setTestDataPath(TEST_DATA_PATH);
}
protected String getFixturePath(final String fileName, final String folder) {
return prepareFixturePath(fileName, folder + File.separator);
}
protected void assertHasLinemarkerWithTooltipAndIcon(final String tooltip, final String icon) {
myFixture.doHighlighting();
final List<LineMarkerInfo<?>> lineMarkers = getDocumentLineMarkers();
assertNotEmpty(lineMarkers);
for (final LineMarkerInfo lineMarkerInfo: lineMarkers) {
final String lineMarkerTooltip = lineMarkerInfo.getLineMarkerTooltip();
final Icon lineMarkerIcon = lineMarkerInfo.getIcon();
if (lineMarkerTooltip == null || lineMarkerIcon == null) {
continue;
}
if (lineMarkerTooltip.equals(tooltip)
&& lineMarkerIcon.toString().contains(icon)) {
return;
}
}
final String lineMarkerNotFound
= "Failed that documents contains linemarker with the tooltip `%s`";
fail(String.format(lineMarkerNotFound, tooltip));
}
protected void assertHasNoLinemarkerWithTooltipAndIcon(
final String tooltip,
final String icon
) {
myFixture.doHighlighting();
final String lineMarkerExist
= "Failed that documents not contains linemarker with the tooltip `%s`";
final List<LineMarkerInfo<?>> lineMarkers = getDocumentLineMarkers();
assertNotEmpty(lineMarkers);
for (final LineMarkerInfo lineMarkerInfo: lineMarkers) {
final String lineMarkerTooltip = lineMarkerInfo.getLineMarkerTooltip();
final Icon lineMarkerIcon = lineMarkerInfo.getIcon();
if (lineMarkerTooltip == null || lineMarkerIcon == null) {
continue;
}
if (lineMarkerTooltip.equals(tooltip)
&& lineMarkerIcon.toString().equals(icon)) {
fail(String.format(lineMarkerExist, tooltip));
}
}
}
@NotNull
private List<LineMarkerInfo<?>> getDocumentLineMarkers() {
return DaemonCodeAnalyzerImpl.getLineMarkers(
myFixture.getEditor().getDocument(),
getProject()
);
}
}