forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseCompletionTestCase.java
128 lines (102 loc) · 4.29 KB
/
BaseCompletionTestCase.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.completion;
import com.magento.idea.magento2plugin.BaseProjectTestCase;
import com.magento.idea.magento2plugin.magento.packages.File;
import java.util.Arrays;
import java.util.List;
public abstract class BaseCompletionTestCase extends BaseProjectTestCase {
private static final String MESSAGE_NO_LOOKUP = "No lookup element was provided";
private final String testDataFolderPath
= "testData" + File.separator + "completion" + File.separator;
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.setTestDataPath(testDataFolderPath);
}
private void configureFixture(final String filePath) {
myFixture.configureByFile(filePath);
myFixture.completeBasic();
}
/**
* Assert that completion suggestions contains the given lookup strings.
*/
public void assertCompletionContains(final String filePath, final String... lookupStrings) {
configureFixture(filePath);
final String messageEmptyLookup = "Failed that completion contains `%s`";
final String messageComplationContains = "Failed that completion contains `%s` in `%s`";
checkContainsCompletion(lookupStrings, messageEmptyLookup, messageComplationContains);
}
protected void assertFileContainsCompletions(
final String filePath,
final String... lookupStrings
) {
configureFixture(filePath);
final String messageEmptyLookup
= "Failed that completion contains `%s` for file " + filePath;
final String messageCompletionContains
= "Failed that completion contains `%s` in `%s` for file " + filePath;
checkContainsCompletion(lookupStrings, messageEmptyLookup, messageCompletionContains);
}
protected void assertFileNotContainsCompletions(
final String filePath,
final String... lookupStrings
) {
configureFixture(filePath);
final String messageCompletionNotContains
= "Failed that completion does not contain `%s` in `%s` for file " + filePath;
checkDoesNotContainCompletion(
lookupStrings, messageCompletionNotContains
);
}
protected void assertCompletionNotShowing(final String filePath) {
configureFixture(filePath);
final List<String> lookupElements = myFixture.getLookupElementStrings();
if (lookupElements != null && !lookupElements.isEmpty()) {
final String messageCompletionDoesNotShow
= "Failed asserting that completion does not show up";
fail(messageCompletionDoesNotShow);
}
}
protected void checkContainsCompletion(
final String[] lookupStrings,
final String emptyLookupError,
final String completionContainsError
) {
if (lookupStrings.length == 0) {
fail(MESSAGE_NO_LOOKUP);
}
final List<String> lookupElements = myFixture.getLookupElementStrings();
if (lookupElements == null || lookupElements.isEmpty()) {
fail(String.format(emptyLookupError, Arrays.toString(lookupStrings)));
}
for (final String lookupString : lookupStrings) {
if (!lookupElements.contains(lookupString)) {
fail(String.format(
completionContainsError, lookupString, lookupElements.toString())
);
}
}
}
protected void checkDoesNotContainCompletion(
final String[] lookupStrings,
final String completionDoesNotContainError
) {
if (lookupStrings.length == 0) {
fail(MESSAGE_NO_LOOKUP);
}
final List<String> lookupElements = myFixture.getLookupElementStrings();
if (lookupElements != null) {
for (final String lookupString : lookupStrings) {
if (lookupElements.contains(lookupString)) {
fail(String.format(
completionDoesNotContainError, lookupString, lookupElements.toString())
);
}
}
}
}
protected abstract String getFixturePath(String fileName);
}