Skip to content

Commit 72a0225

Browse files
committed
test: use assertj
1 parent fef6ccb commit 72a0225

File tree

43 files changed

+659
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+659
-627
lines changed

org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Require-Bundle: org.apache.batik.css;resolution:=optional,
99
org.apache.batik.util;resolution:=optional,
1010
com.google.gson;resolution:=optional,
1111
org.eclipse.core.runtime,
12-
org.eclipse.tm4e.core
12+
org.eclipse.tm4e.core,
13+
assertj-core
1314
Import-Package: org.junit.jupiter.api,
1415
org.junit.jupiter.api.function,
1516
org.w3c.css.sac;resolution:=optional,

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.eclipse.tm4e.core.grammar.internal;
1717

1818
import static java.util.stream.Collectors.*;
19-
import static org.junit.jupiter.api.Assertions.*;
19+
import static org.assertj.core.api.Assertions.*;
2020

2121
import java.io.File;
2222
import java.util.Arrays;
@@ -136,16 +136,15 @@ private static void deepEqual(final List<RawToken> actualTokens, final List<RawT
136136
final var actualTokensStr = actualTokens.stream().map(Object::toString).collect(joining("\n"));
137137
final var expextedTokensStr = expextedTokens.stream().map(Object::toString).collect(joining("\n"));
138138

139-
assertEquals(expextedTokensStr, actualTokensStr,
140-
message + " (collection size problem: actual=" + actualTokens.size() + " expected=" + expextedTokens.size() + ")");
139+
assertThat(actualTokensStr).as(message + " (collection size)").isEqualTo(expextedTokensStr);
141140
}
142141

143142
// compare item
144143
for (int i = 0; i < expextedTokens.size(); i++) {
145144
final var expected = expextedTokens.get(i);
146145
final var actual = actualTokens.get(i);
147-
assertEquals(expected.getValue(), actual.getValue(), message + " (value of item '" + i + "' problem)");
148-
assertEquals(expected.getScopes(), actual.getScopes(), message + " (tokens of item '" + i + "' problem)");
146+
assertThat(actual.getValue()).as(message + " (value of item '" + i + "' problem)").isEqualTo(expected.getValue());
147+
assertThat(actual.getScopes()).as(message + " (scopes of item '" + i + "' problem)").isEqualTo(expected.getScopes());
149148
}
150149
}
151150

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/matcher/MatcherTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
package org.eclipse.tm4e.core.internal.matcher;
1313

14-
import static org.junit.jupiter.api.Assertions.*;
14+
import static org.assertj.core.api.Assertions.*;
1515

1616
import java.util.ArrayList;
1717
import java.util.List;
@@ -41,8 +41,7 @@ static final class MatcherTestImpl implements Executable {
4141
@Override
4242
public void execute() {
4343
final var matcher = Matcher.createMatchers(expression);
44-
final boolean result = matcher.stream().anyMatch(m -> m.matcher.matches(input));
45-
assertEquals(result, this.result);
44+
assertThat(matcher.stream().anyMatch(m -> m.matcher.matches(input))).isEqualTo(this.result);
4645
}
4746
}
4847

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/AbstractThemeTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import org.eclipse.tm4e.core.internal.theme.raw.RawThemeReader;
1919
import org.eclipse.tm4e.core.registry.IThemeSource;
20-
import org.junit.jupiter.api.Assertions;
2120

22-
public abstract class AbstractThemeTest extends Assertions {
21+
public abstract class AbstractThemeTest extends org.assertj.core.api.Assertions {
2322

2423
protected static final int _NOT_SET = 0;
2524

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java

+35-35
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void testGivesHigherPriorityToDeeperMatches() throws Exception {
4141
]}""");
4242

4343
final var actual = theme.match(ScopeStack.from("punctuation.definition.string.begin.html"));
44-
assertEquals(theme.getColorMap().get(actual.foregroundId), "#300000");
44+
assertThat(theme.getColorMap().get(actual.foregroundId)).isEqualTo("#300000");
4545
}
4646

4747
@Test
@@ -58,7 +58,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception {
5858

5959
final var map = theme.getColorMap();
6060

61-
assertEquals(map.get(theme.match(ScopeStack.from("d", "a.b")).foregroundId), "#400000");
61+
assertThat(map.get(theme.match(ScopeStack.from("d", "a.b")).foregroundId)).isEqualTo("#400000");
6262
}
6363

6464
@Test
@@ -80,7 +80,7 @@ void testGivesHigherPriorityToParentMatches2() throws Exception {
8080
"entity.name.tag.structure.any.html"));
8181

8282
final var colorMap = theme.getColorMap();
83-
assertEquals(colorMap.get(result.foregroundId), "#300000");
83+
assertThat(colorMap.get(result.foregroundId)).isEqualTo("#300000");
8484
}
8585

8686
private Map<String, String> match(final Theme theme, final String... path) {
@@ -118,41 +118,41 @@ void testCanMatch() throws Exception {
118118
]}""");
119119

120120
// simpleMatch1..25
121-
assertEquals(match(theme, "source"), map("background", "#100000", "fontStyle", "not set"));
122-
assertEquals(match(theme, "source"), map("background", "#100000", "fontStyle", "not set"));
123-
assertEquals(match(theme, "source.ts"), map("background", "#100000", "fontStyle", "not set"));
124-
assertEquals(match(theme, "source.tss"), map("background", "#100000", "fontStyle", "not set"));
125-
assertEquals(match(theme, "something"), map("background", "#100000", "fontStyle", "not set"));
126-
assertEquals(match(theme, "something.ts"), map("background", "#100000", "fontStyle", "not set"));
127-
assertEquals(match(theme, "something.tss"), map("background", "#100000", "fontStyle", "not set"));
128-
assertEquals(match(theme, "baz"), map("background", "#200000", "fontStyle", "not set"));
129-
assertEquals(match(theme, "baz.ts"), map("background", "#200000", "fontStyle", "not set"));
130-
assertEquals(match(theme, "baz.tss"), map("background", "#200000", "fontStyle", "not set"));
131-
assertEquals(match(theme, "constant"), map("foreground", "#300000", "fontStyle", "italic"));
132-
assertEquals(match(theme, "constant.string"), map("foreground", "#300000", "fontStyle", "italic"));
133-
assertEquals(match(theme, "constant.hex"), map("foreground", "#300000", "fontStyle", "italic"));
134-
assertEquals(match(theme, "constant.numeric"), map("foreground", "#400000", "fontStyle", "italic"));
135-
assertEquals(match(theme, "constant.numeric.baz"), map("foreground", "#400000", "fontStyle", "italic"));
136-
assertEquals(match(theme, "constant.numeric.hex"), map("foreground", "#400000", "fontStyle", "bold"));
137-
assertEquals(match(theme, "constant.numeric.hex.baz"), map("foreground", "#400000", "fontStyle", "bold"));
138-
assertEquals(match(theme, "constant.numeric.oct"), map("foreground", "#400000", "fontStyle", "italic bold underline"));
139-
assertEquals(match(theme, "constant.numeric.oct.baz"), map("foreground", "#400000", "fontStyle", "italic bold underline"));
140-
assertEquals(match(theme, "constant.numeric.dec"), map("foreground", "#500000", "fontStyle", "none"));
141-
assertEquals(match(theme, "constant.numeric.dec.baz"), map("foreground", "#500000", "fontStyle", "none"));
142-
assertEquals(match(theme, "storage.object.bar"), map("foreground", "#600000", "fontStyle", "none"));
143-
assertEquals(match(theme, "storage.object.bar.baz"), map("foreground", "#600000", "fontStyle", "none"));
144-
assertEquals(match(theme, "storage.object.bart"), map("fontStyle", "not set"));
145-
assertEquals(match(theme, "storage.object"), map("fontStyle", "not set"));
146-
assertEquals(match(theme, "storage"), map("fontStyle", "not set"));
121+
assertThat(match(theme, "source")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
122+
assertThat(match(theme, "source")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
123+
assertThat(match(theme, "source.ts")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
124+
assertThat(match(theme, "source.tss")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
125+
assertThat(match(theme, "something")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
126+
assertThat(match(theme, "something.ts")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
127+
assertThat(match(theme, "something.tss")).isEqualTo(map("background", "#100000", "fontStyle", "not set"));
128+
assertThat(match(theme, "baz")).isEqualTo(map("background", "#200000", "fontStyle", "not set"));
129+
assertThat(match(theme, "baz.ts")).isEqualTo(map("background", "#200000", "fontStyle", "not set"));
130+
assertThat(match(theme, "baz.tss")).isEqualTo(map("background", "#200000", "fontStyle", "not set"));
131+
assertThat(match(theme, "constant")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic"));
132+
assertThat(match(theme, "constant.string")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic"));
133+
assertThat(match(theme, "constant.hex")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic"));
134+
assertThat(match(theme, "constant.numeric")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic"));
135+
assertThat(match(theme, "constant.numeric.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic"));
136+
assertThat(match(theme, "constant.numeric.hex")).isEqualTo(map("foreground", "#400000", "fontStyle", "bold"));
137+
assertThat(match(theme, "constant.numeric.hex.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "bold"));
138+
assertThat(match(theme, "constant.numeric.oct")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic bold underline"));
139+
assertThat(match(theme, "constant.numeric.oct.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic bold underline"));
140+
assertThat(match(theme, "constant.numeric.dec")).isEqualTo(map("foreground", "#500000", "fontStyle", "none"));
141+
assertThat(match(theme, "constant.numeric.dec.baz")).isEqualTo(map("foreground", "#500000", "fontStyle", "none"));
142+
assertThat(match(theme, "storage.object.bar")).isEqualTo(map("foreground", "#600000", "fontStyle", "none"));
143+
assertThat(match(theme, "storage.object.bar.baz")).isEqualTo(map("foreground", "#600000", "fontStyle", "none"));
144+
assertThat(match(theme, "storage.object.bart")).isEqualTo(map("fontStyle", "not set"));
145+
assertThat(match(theme, "storage.object")).isEqualTo(map("fontStyle", "not set"));
146+
assertThat(match(theme, "storage")).isEqualTo(map("fontStyle", "not set"));
147147

148148
// defaultMatch1..3
149-
assertEquals(match(theme, ""), map("fontStyle", "not set"));
150-
assertEquals(match(theme, "bazz"), map("fontStyle", "not set"));
151-
assertEquals(match(theme, "asdfg"), map("fontStyle", "not set"));
149+
assertThat(match(theme, "")).isEqualTo(map("fontStyle", "not set"));
150+
assertThat(match(theme, "bazz")).isEqualTo(map("fontStyle", "not set"));
151+
assertThat(match(theme, "asdfg")).isEqualTo(map("fontStyle", "not set"));
152152

153153
// multiMatch1..2
154-
assertEquals(match(theme, "bar"), map("background", "#200000", "fontStyle", "not set"));
155-
assertEquals(match(theme, "source.css", "selector", "bar"), map("background", "#200000", "fontStyle", "bold"));
154+
assertThat(match(theme, "bar")).isEqualTo(map("background", "#200000", "fontStyle", "not set"));
155+
assertThat(match(theme, "source.css", "selector", "bar")).isEqualTo(map("background", "#200000", "fontStyle", "bold"));
156156
}
157157

158158
@Test
@@ -191,6 +191,6 @@ void testMicrosoft_vscode_23460() throws Exception {
191191
"meta.structure.dictionary.value.json",
192192
"string.quoted.double.json");
193193
final var result = theme.match(path);
194-
assertEquals(theme.getColorMap().get(result.foregroundId), "#FF410D");
194+
assertThat(theme.getColorMap().get(result.foregroundId)).isEqualTo("#FF410D");
195195
}
196196
}

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static org.eclipse.tm4e.core.internal.theme.FontStyle.*;
2020

21+
import java.util.List;
22+
2123
import org.junit.jupiter.api.DisplayName;
2224
import org.junit.jupiter.api.MethodOrderer;
2325
import org.junit.jupiter.api.Order;
@@ -36,7 +38,7 @@ public class ThemeParsingTest extends AbstractThemeTest {
3638
@Order(1)
3739
@DisplayName("Theme parsing can parse")
3840
public void testCanParse() throws Exception {
39-
final var actual = parseTheme("""
41+
final List<ParsedThemeRule> actual = parseTheme("""
4042
{ "settings": [
4143
{ "settings": { "foreground": "#F8F8F2", "background": "#272822" } },
4244
{ "scope": "source, something", "settings": { "background": "#100000" } },
@@ -51,22 +53,21 @@ public void testCanParse() throws Exception {
5153
{ "scope": "foo", "settings": { "fontStyle": "", "foreground": "#CFA" } }
5254
]}""");
5355

54-
final var expected = new ParsedThemeRule[] {
55-
new ParsedThemeRule("", null, 0, NotSet, "#F8F8F2", "#272822"),
56-
new ParsedThemeRule("source", null, 1, NotSet, null, "#100000"),
57-
new ParsedThemeRule("something", null, 1, NotSet, null, "#100000"),
58-
new ParsedThemeRule("bar", null, 2, NotSet, null, "#010000"),
59-
new ParsedThemeRule("baz", null, 2, NotSet, null, "#010000"),
60-
new ParsedThemeRule("bar", list("selector", "source.css"), 3, Bold, null, null),
61-
new ParsedThemeRule("constant", null, 4, Italic, "#ff0000", null),
62-
new ParsedThemeRule("constant.numeric", null, 5, NotSet, "#00ff00", null),
63-
new ParsedThemeRule("constant.numeric.hex", null, 6, Bold, null, null),
64-
new ParsedThemeRule("constant.numeric.oct", null, 7, Bold | Italic | Underline, null, null),
65-
new ParsedThemeRule("constant.numeric.bin", null, 8, Bold | Strikethrough, null, null),
66-
new ParsedThemeRule("constant.numeric.dec", null, 9, None, "#0000ff", null),
67-
new ParsedThemeRule("foo", null, 10, None, "#CFA", null),
68-
};
56+
final var expected = list(
57+
new ParsedThemeRule("", null, 0, NotSet, "#F8F8F2", "#272822"),
58+
new ParsedThemeRule("source", null, 1, NotSet, null, "#100000"),
59+
new ParsedThemeRule("something", null, 1, NotSet, null, "#100000"),
60+
new ParsedThemeRule("bar", null, 2, NotSet, null, "#010000"),
61+
new ParsedThemeRule("baz", null, 2, NotSet, null, "#010000"),
62+
new ParsedThemeRule("bar", list("selector", "source.css"), 3, Bold, null, null),
63+
new ParsedThemeRule("constant", null, 4, Italic, "#ff0000", null),
64+
new ParsedThemeRule("constant.numeric", null, 5, NotSet, "#00ff00", null),
65+
new ParsedThemeRule("constant.numeric.hex", null, 6, Bold, null, null),
66+
new ParsedThemeRule("constant.numeric.oct", null, 7, Bold | Italic | Underline, null, null),
67+
new ParsedThemeRule("constant.numeric.bin", null, 8, Bold | Strikethrough, null, null),
68+
new ParsedThemeRule("constant.numeric.dec", null, 9, None, "#0000ff", null),
69+
new ParsedThemeRule("foo", null, 10, None, "#CFA", null));
6970

70-
assertArrayEquals(expected, actual.toArray());
71+
assertThat(actual).isEqualTo(expected);
7172
}
7273
}

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ThemeResolvingTest extends AbstractThemeTest {
4646
private static final ThemeTrieElement NOTSET_THEME_TRIE_ELEMENT = new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE);
4747

4848
private static void assertStrArrCmp(final String testCase, final List<String> a, final List<String> b, final int expected) {
49-
assertEquals(expected, StringUtils.strArrCmp(a, b), testCase);
49+
assertThat(StringUtils.strArrCmp(a, b)).as(testCase).isEqualTo(expected);
5050
}
5151

5252
@Test
@@ -57,7 +57,7 @@ public void testStrcmpWorks() {
5757
actual.sort(StringUtils::strcmp);
5858

5959
final var expected = list("", "a", "ab", "bar", "z", "zu");
60-
assertArrayEquals(expected.toArray(), actual.toArray());
60+
assertThat(actual).isEqualTo(expected);
6161
}
6262

6363
@Test
@@ -96,10 +96,10 @@ public boolean shouldSkipClass(final Class<?> clazz) {
9696

9797
private static void assertThemeEqual(final Theme actual, final Theme expected) {
9898
// if this fails, we get a nice visual representation of the difference:
99-
assertEquals(THEME_GSON.toJson(expected), THEME_GSON.toJson(actual));
99+
assertThat(THEME_GSON.toJson(actual)).isEqualTo(THEME_GSON.toJson(expected));
100100

101101
// this ensures hashCode/equals are properly implemented:
102-
assertEquals(expected, actual);
102+
assertThat(actual).isEqualTo(expected);
103103
}
104104

105105
@Test
@@ -372,10 +372,10 @@ interface Matcher {
372372
return colorMap.get(result.foregroundId);
373373
};
374374

375-
assertEquals(matcher.match("b", "a"), "#300000", "b a");
376-
assertEquals(matcher.match("b", "c", "a"), "#200000", "b c a");
377-
assertEquals(matcher.match("c", "b", "a"), "#400000", "c b a");
378-
assertEquals(matcher.match("c", "b", "d", "a"), "#200000", "c b d a");
375+
assertThat(matcher.match("b", "a")).as("b a").isEqualTo("#300000");
376+
assertThat(matcher.match("b", "c", "a")).as("b c a").isEqualTo("#200000");
377+
assertThat(matcher.match("c", "b", "a")).as("c b a").isEqualTo("#400000");
378+
assertThat(matcher.match("c", "b", "d", "a")).as("c b d a").isEqualTo("#200000");
379379
}
380380

381381
@Test
@@ -402,14 +402,14 @@ interface Matcher {
402402
return colorMap.get(result.foregroundId);
403403
};
404404

405-
assertEquals(matcher.match("x", "a.b"), null, "x a.b");
406-
assertEquals(matcher.match("y", "a.b"), null, "y a.b");
407-
assertEquals(matcher.match("y.z", "a"), null, "y.z a");
408-
assertEquals(matcher.match("x", "y", "a.b"), "#300000", "x y a.b");
405+
assertThat(matcher.match("x", "a.b")).as("x a.b").isNull();
406+
assertThat(matcher.match("y", "a.b")).as("y a.b").isNull();
407+
assertThat(matcher.match("y.z", "a")).as("y.z a").isNull();
408+
assertThat(matcher.match("x", "y", "a.b")).as("x y a.b").isEqualTo("#300000");
409409

410410
// Even though the "x y a.b" rule has more scopes in its path, the "y.z a.b" rule has
411411
// a deeper match, so it should take precedence.
412-
assertEquals(matcher.match("x", "y.z", "a.b"), "#200000", "y.z a.b");
412+
assertThat(matcher.match("x", "y.z", "a.b")).as("y.z a.b").isEqualTo("#200000");
413413
}
414414

415415
@Test
@@ -467,7 +467,7 @@ public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception {
467467
new ParsedThemeRule("variable.other", null, 4, None, null, null),
468468
new ParsedThemeRule("variable.parameter.function.coffee", null, 5, Italic, "#F9D423", null));
469469

470-
assertArrayEquals(expected.toArray(), actual.toArray());
470+
assertThat(actual).isEqualTo(expected);
471471
}
472472

473473
@Test
@@ -505,6 +505,6 @@ public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exc
505505
new ParsedThemeRule("meta.at-rule.if.scss", null, 1, NotSet, "#CC7832", null),
506506
new ParsedThemeRule("punctuation.definition", list("meta.at-rule.if.scss"), 1, NotSet, "#CC7832", null));
507507

508-
assertArrayEquals(expected.toArray(), actual.toArray());
508+
assertThat(actual).isEqualTo(expected);
509509
}
510510
}

org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSParserTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package org.eclipse.tm4e.core.internal.theme.css;
1414

15-
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.assertj.core.api.Assertions.*;
1616

1717
import org.eclipse.tm4e.core.theme.RGB;
1818
import org.eclipse.tm4e.core.theme.css.CSSParser;
@@ -27,9 +27,9 @@ void testCSSParser() throws Exception {
2727
.storage.invalid { background-color: red; }
2828
""");
2929

30-
assertEquals(null, parser.getBestStyle("undefined"));
31-
assertEquals(new RGB(255,128,128), parser.getBestStyle("invalid").getBackgroundColor());
32-
assertEquals(new RGB(255,0,0), parser.getBestStyle("storage", "invalid").getBackgroundColor());
33-
assertEquals(new RGB(255,0,0), parser.getBestStyle("storage" , "modifier", "invalid", "deprecated").getBackgroundColor());
30+
assertThat(parser.getBestStyle("undefined")).isNull();
31+
assertThat(parser.getBestStyle("invalid").getBackgroundColor()).isEqualTo(new RGB(255, 128, 128));
32+
assertThat(parser.getBestStyle("storage", "invalid").getBackgroundColor()).isEqualTo(new RGB(255, 0, 0));
33+
assertThat(parser.getBestStyle("storage", "modifier", "invalid", "deprecated").getBackgroundColor()).isEqualTo(new RGB(255, 0, 0));
3434
}
3535
}

org.eclipse.tm4e.core/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ bin.includes = META-INF/,\
66
about.html
77

88
# JDT Null Analysis for Eclipse
9-
additional.bundles = org.eclipse.jdt.annotation
9+
additional.bundles = org.eclipse.jdt.annotation,assertj-core

0 commit comments

Comments
 (0)