From 17f46fdb8fe3af687e8bb31e61adf6b4bd58e232 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 20 Jan 2025 15:49:20 +0100 Subject: [PATCH] test: use assertj --- .../META-INF/MANIFEST.MF | 3 +- .../core/grammar/internal/RawTestImpl.java | 9 +- .../core/internal/matcher/MatcherTest.java | 5 +- .../internal/theme/AbstractThemeTest.java | 3 +- .../internal/theme/ThemeMatchingTest.java | 70 +++--- .../core/internal/theme/ThemeParsingTest.java | 35 +-- .../internal/theme/ThemeResolvingTest.java | 30 +-- .../internal/theme/css/CSSParserTest.java | 10 +- org.eclipse.tm4e.core/build.properties | 2 +- .../eclipse/tm4e/core/model/TMModelTest.java | 12 +- .../tm4e/core/model/TMTokenizationTest.java | 8 +- .../tm4e/core/registry/RegistryTest.java | 12 +- .../META-INF/MANIFEST.MF | 3 +- .../tests/TestAutoClosing.java | 44 ++-- .../tests/TestComment.java | 52 ++--- .../tests/TestIndent.java | 6 +- .../tests/TestIndentationRules.java | 10 +- .../tests/TestOnEnter.java | 4 +- .../tests/TestSurroundingPairs.java | 19 +- .../build.properties | 2 +- .../internal/IndentationRulesTest.java | 18 +- .../internal/model/ParsingTest.java | 100 +++++---- .../internal/supports/OnEnterSupportTest.java | 26 +-- .../internal/utils/IndentationTest.java | 68 +++--- .../internal/utils/StringsTest.java | 36 ++-- .../internal/utils/TextUtilsTest.java | 200 +++++++++--------- .../META-INF/MANIFEST.MF | 3 +- .../eclipse/tm4e/ui/tests/RegistryTest.java | 7 +- ...MPresentationReconcilerTypeScriptTest.java | 80 +++---- .../tm4e/ui/tests/TMinGenericEditorTest.java | 4 +- .../internal/model/TMDocumentModelTest.java | 18 +- .../internal/themes/TMTokenProviderTest.java | 163 +++++++------- .../utils/DocumentInputStreamTest.java | 44 ++-- .../tm4e/ui/tests/support/TestUtils.java | 6 +- .../ui/tests/themes/TMEditorColorTest.java | 63 ++++-- .../ui/tests/themes/ThemeManagerTest.java | 18 +- org.eclipse.tm4e.ui/build.properties | 2 +- .../internal/model/TMDocumentModelTest.java | 9 +- .../preferences/PreferenceHelperTest.java | 4 +- .../internal/utils/CharsInputStreamTest.java | 48 ++--- target-platforms/latest.target | 11 + target-platforms/oldest.target | 8 +- target-platforms/unstable.target | 11 + 43 files changed, 659 insertions(+), 627 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF index e9e84d673..a45b984df 100644 --- a/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Require-Bundle: org.apache.batik.css;resolution:=optional, org.apache.batik.util;resolution:=optional, com.google.gson;resolution:=optional, org.eclipse.core.runtime, - org.eclipse.tm4e.core + org.eclipse.tm4e.core, + assertj-core Import-Package: org.junit.jupiter.api, org.junit.jupiter.api.function, org.w3c.css.sac;resolution:=optional, diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java index ed0a7d6e1..ef61d82e4 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/grammar/internal/RawTestImpl.java @@ -16,7 +16,7 @@ package org.eclipse.tm4e.core.grammar.internal; import static java.util.stream.Collectors.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; import java.io.File; import java.util.Arrays; @@ -136,16 +136,15 @@ private static void deepEqual(final List actualTokens, final List m.matcher.matches(input)); - assertEquals(result, this.result); + assertThat(matcher.stream().anyMatch(m -> m.matcher.matches(input))).isEqualTo(this.result); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/AbstractThemeTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/AbstractThemeTest.java index d11418dd8..3ccfceb2f 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/AbstractThemeTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/AbstractThemeTest.java @@ -17,9 +17,8 @@ import org.eclipse.tm4e.core.internal.theme.raw.RawThemeReader; import org.eclipse.tm4e.core.registry.IThemeSource; -import org.junit.jupiter.api.Assertions; -public abstract class AbstractThemeTest extends Assertions { +public abstract class AbstractThemeTest extends org.assertj.core.api.Assertions { protected static final int _NOT_SET = 0; diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java index 627ea29dd..73346dc32 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeMatchingTest.java @@ -41,7 +41,7 @@ void testGivesHigherPriorityToDeeperMatches() throws Exception { ]}"""); final var actual = theme.match(ScopeStack.from("punctuation.definition.string.begin.html")); - assertEquals(theme.getColorMap().get(actual.foregroundId), "#300000"); + assertThat(theme.getColorMap().get(actual.foregroundId)).isEqualTo("#300000"); } @Test @@ -58,7 +58,7 @@ void testGivesHigherPriorityToParentMatches1() throws Exception { final var map = theme.getColorMap(); - assertEquals(map.get(theme.match(ScopeStack.from("d", "a.b")).foregroundId), "#400000"); + assertThat(map.get(theme.match(ScopeStack.from("d", "a.b")).foregroundId)).isEqualTo("#400000"); } @Test @@ -80,7 +80,7 @@ void testGivesHigherPriorityToParentMatches2() throws Exception { "entity.name.tag.structure.any.html")); final var colorMap = theme.getColorMap(); - assertEquals(colorMap.get(result.foregroundId), "#300000"); + assertThat(colorMap.get(result.foregroundId)).isEqualTo("#300000"); } private Map match(final Theme theme, final String... path) { @@ -118,41 +118,41 @@ void testCanMatch() throws Exception { ]}"""); // simpleMatch1..25 - assertEquals(match(theme, "source"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "source"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "source.ts"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "source.tss"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "something"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "something.ts"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "something.tss"), map("background", "#100000", "fontStyle", "not set")); - assertEquals(match(theme, "baz"), map("background", "#200000", "fontStyle", "not set")); - assertEquals(match(theme, "baz.ts"), map("background", "#200000", "fontStyle", "not set")); - assertEquals(match(theme, "baz.tss"), map("background", "#200000", "fontStyle", "not set")); - assertEquals(match(theme, "constant"), map("foreground", "#300000", "fontStyle", "italic")); - assertEquals(match(theme, "constant.string"), map("foreground", "#300000", "fontStyle", "italic")); - assertEquals(match(theme, "constant.hex"), map("foreground", "#300000", "fontStyle", "italic")); - assertEquals(match(theme, "constant.numeric"), map("foreground", "#400000", "fontStyle", "italic")); - assertEquals(match(theme, "constant.numeric.baz"), map("foreground", "#400000", "fontStyle", "italic")); - assertEquals(match(theme, "constant.numeric.hex"), map("foreground", "#400000", "fontStyle", "bold")); - assertEquals(match(theme, "constant.numeric.hex.baz"), map("foreground", "#400000", "fontStyle", "bold")); - assertEquals(match(theme, "constant.numeric.oct"), map("foreground", "#400000", "fontStyle", "italic bold underline")); - assertEquals(match(theme, "constant.numeric.oct.baz"), map("foreground", "#400000", "fontStyle", "italic bold underline")); - assertEquals(match(theme, "constant.numeric.dec"), map("foreground", "#500000", "fontStyle", "none")); - assertEquals(match(theme, "constant.numeric.dec.baz"), map("foreground", "#500000", "fontStyle", "none")); - assertEquals(match(theme, "storage.object.bar"), map("foreground", "#600000", "fontStyle", "none")); - assertEquals(match(theme, "storage.object.bar.baz"), map("foreground", "#600000", "fontStyle", "none")); - assertEquals(match(theme, "storage.object.bart"), map("fontStyle", "not set")); - assertEquals(match(theme, "storage.object"), map("fontStyle", "not set")); - assertEquals(match(theme, "storage"), map("fontStyle", "not set")); + assertThat(match(theme, "source")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "source")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "source.ts")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "source.tss")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "something")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "something.ts")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "something.tss")).isEqualTo(map("background", "#100000", "fontStyle", "not set")); + assertThat(match(theme, "baz")).isEqualTo(map("background", "#200000", "fontStyle", "not set")); + assertThat(match(theme, "baz.ts")).isEqualTo(map("background", "#200000", "fontStyle", "not set")); + assertThat(match(theme, "baz.tss")).isEqualTo(map("background", "#200000", "fontStyle", "not set")); + assertThat(match(theme, "constant")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic")); + assertThat(match(theme, "constant.string")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic")); + assertThat(match(theme, "constant.hex")).isEqualTo(map("foreground", "#300000", "fontStyle", "italic")); + assertThat(match(theme, "constant.numeric")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic")); + assertThat(match(theme, "constant.numeric.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic")); + assertThat(match(theme, "constant.numeric.hex")).isEqualTo(map("foreground", "#400000", "fontStyle", "bold")); + assertThat(match(theme, "constant.numeric.hex.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "bold")); + assertThat(match(theme, "constant.numeric.oct")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic bold underline")); + assertThat(match(theme, "constant.numeric.oct.baz")).isEqualTo(map("foreground", "#400000", "fontStyle", "italic bold underline")); + assertThat(match(theme, "constant.numeric.dec")).isEqualTo(map("foreground", "#500000", "fontStyle", "none")); + assertThat(match(theme, "constant.numeric.dec.baz")).isEqualTo(map("foreground", "#500000", "fontStyle", "none")); + assertThat(match(theme, "storage.object.bar")).isEqualTo(map("foreground", "#600000", "fontStyle", "none")); + assertThat(match(theme, "storage.object.bar.baz")).isEqualTo(map("foreground", "#600000", "fontStyle", "none")); + assertThat(match(theme, "storage.object.bart")).isEqualTo(map("fontStyle", "not set")); + assertThat(match(theme, "storage.object")).isEqualTo(map("fontStyle", "not set")); + assertThat(match(theme, "storage")).isEqualTo(map("fontStyle", "not set")); // defaultMatch1..3 - assertEquals(match(theme, ""), map("fontStyle", "not set")); - assertEquals(match(theme, "bazz"), map("fontStyle", "not set")); - assertEquals(match(theme, "asdfg"), map("fontStyle", "not set")); + assertThat(match(theme, "")).isEqualTo(map("fontStyle", "not set")); + assertThat(match(theme, "bazz")).isEqualTo(map("fontStyle", "not set")); + assertThat(match(theme, "asdfg")).isEqualTo(map("fontStyle", "not set")); // multiMatch1..2 - assertEquals(match(theme, "bar"), map("background", "#200000", "fontStyle", "not set")); - assertEquals(match(theme, "source.css", "selector", "bar"), map("background", "#200000", "fontStyle", "bold")); + assertThat(match(theme, "bar")).isEqualTo(map("background", "#200000", "fontStyle", "not set")); + assertThat(match(theme, "source.css", "selector", "bar")).isEqualTo(map("background", "#200000", "fontStyle", "bold")); } @Test @@ -191,6 +191,6 @@ void testMicrosoft_vscode_23460() throws Exception { "meta.structure.dictionary.value.json", "string.quoted.double.json"); final var result = theme.match(path); - assertEquals(theme.getColorMap().get(result.foregroundId), "#FF410D"); + assertThat(theme.getColorMap().get(result.foregroundId)).isEqualTo("#FF410D"); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java index f1da88524..a6790741d 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeParsingTest.java @@ -18,6 +18,8 @@ import static org.eclipse.tm4e.core.internal.theme.FontStyle.*; +import java.util.List; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -36,7 +38,7 @@ public class ThemeParsingTest extends AbstractThemeTest { @Order(1) @DisplayName("Theme parsing can parse") public void testCanParse() throws Exception { - final var actual = parseTheme(""" + final List actual = parseTheme(""" { "settings": [ { "settings": { "foreground": "#F8F8F2", "background": "#272822" } }, { "scope": "source, something", "settings": { "background": "#100000" } }, @@ -51,22 +53,21 @@ public void testCanParse() throws Exception { { "scope": "foo", "settings": { "fontStyle": "", "foreground": "#CFA" } } ]}"""); - final var expected = new ParsedThemeRule[] { - new ParsedThemeRule("", null, 0, NotSet, "#F8F8F2", "#272822"), - new ParsedThemeRule("source", null, 1, NotSet, null, "#100000"), - new ParsedThemeRule("something", null, 1, NotSet, null, "#100000"), - new ParsedThemeRule("bar", null, 2, NotSet, null, "#010000"), - new ParsedThemeRule("baz", null, 2, NotSet, null, "#010000"), - new ParsedThemeRule("bar", list("selector", "source.css"), 3, Bold, null, null), - new ParsedThemeRule("constant", null, 4, Italic, "#ff0000", null), - new ParsedThemeRule("constant.numeric", null, 5, NotSet, "#00ff00", null), - new ParsedThemeRule("constant.numeric.hex", null, 6, Bold, null, null), - new ParsedThemeRule("constant.numeric.oct", null, 7, Bold | Italic | Underline, null, null), - new ParsedThemeRule("constant.numeric.bin", null, 8, Bold | Strikethrough, null, null), - new ParsedThemeRule("constant.numeric.dec", null, 9, None, "#0000ff", null), - new ParsedThemeRule("foo", null, 10, None, "#CFA", null), - }; + final var expected = list( + new ParsedThemeRule("", null, 0, NotSet, "#F8F8F2", "#272822"), + new ParsedThemeRule("source", null, 1, NotSet, null, "#100000"), + new ParsedThemeRule("something", null, 1, NotSet, null, "#100000"), + new ParsedThemeRule("bar", null, 2, NotSet, null, "#010000"), + new ParsedThemeRule("baz", null, 2, NotSet, null, "#010000"), + new ParsedThemeRule("bar", list("selector", "source.css"), 3, Bold, null, null), + new ParsedThemeRule("constant", null, 4, Italic, "#ff0000", null), + new ParsedThemeRule("constant.numeric", null, 5, NotSet, "#00ff00", null), + new ParsedThemeRule("constant.numeric.hex", null, 6, Bold, null, null), + new ParsedThemeRule("constant.numeric.oct", null, 7, Bold | Italic | Underline, null, null), + new ParsedThemeRule("constant.numeric.bin", null, 8, Bold | Strikethrough, null, null), + new ParsedThemeRule("constant.numeric.dec", null, 9, None, "#0000ff", null), + new ParsedThemeRule("foo", null, 10, None, "#CFA", null)); - assertArrayEquals(expected, actual.toArray()); + assertThat(actual).isEqualTo(expected); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java index 71627bc7b..cb8a19e89 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/ThemeResolvingTest.java @@ -46,7 +46,7 @@ public class ThemeResolvingTest extends AbstractThemeTest { private static final ThemeTrieElement NOTSET_THEME_TRIE_ELEMENT = new ThemeTrieElement(NOTSET_THEME_TRIE_ELEMENT_RULE); private static void assertStrArrCmp(final String testCase, final List a, final List b, final int expected) { - assertEquals(expected, StringUtils.strArrCmp(a, b), testCase); + assertThat(StringUtils.strArrCmp(a, b)).as(testCase).isEqualTo(expected); } @Test @@ -57,7 +57,7 @@ public void testStrcmpWorks() { actual.sort(StringUtils::strcmp); final var expected = list("", "a", "ab", "bar", "z", "zu"); - assertArrayEquals(expected.toArray(), actual.toArray()); + assertThat(actual).isEqualTo(expected); } @Test @@ -96,10 +96,10 @@ public boolean shouldSkipClass(final Class clazz) { private static void assertThemeEqual(final Theme actual, final Theme expected) { // if this fails, we get a nice visual representation of the difference: - assertEquals(THEME_GSON.toJson(expected), THEME_GSON.toJson(actual)); + assertThat(THEME_GSON.toJson(actual)).isEqualTo(THEME_GSON.toJson(expected)); // this ensures hashCode/equals are properly implemented: - assertEquals(expected, actual); + assertThat(actual).isEqualTo(expected); } @Test @@ -372,10 +372,10 @@ interface Matcher { return colorMap.get(result.foregroundId); }; - assertEquals(matcher.match("b", "a"), "#300000", "b a"); - assertEquals(matcher.match("b", "c", "a"), "#200000", "b c a"); - assertEquals(matcher.match("c", "b", "a"), "#400000", "c b a"); - assertEquals(matcher.match("c", "b", "d", "a"), "#200000", "c b d a"); + assertThat(matcher.match("b", "a")).as("b a").isEqualTo("#300000"); + assertThat(matcher.match("b", "c", "a")).as("b c a").isEqualTo("#200000"); + assertThat(matcher.match("c", "b", "a")).as("c b a").isEqualTo("#400000"); + assertThat(matcher.match("c", "b", "d", "a")).as("c b d a").isEqualTo("#200000"); } @Test @@ -402,14 +402,14 @@ interface Matcher { return colorMap.get(result.foregroundId); }; - assertEquals(matcher.match("x", "a.b"), null, "x a.b"); - assertEquals(matcher.match("y", "a.b"), null, "y a.b"); - assertEquals(matcher.match("y.z", "a"), null, "y.z a"); - assertEquals(matcher.match("x", "y", "a.b"), "#300000", "x y a.b"); + assertThat(matcher.match("x", "a.b")).as("x a.b").isNull(); + assertThat(matcher.match("y", "a.b")).as("y a.b").isNull(); + assertThat(matcher.match("y.z", "a")).as("y.z a").isNull(); + assertThat(matcher.match("x", "y", "a.b")).as("x y a.b").isEqualTo("#300000"); // Even though the "x y a.b" rule has more scopes in its path, the "y.z a.b" rule has // a deeper match, so it should take precedence. - assertEquals(matcher.match("x", "y.z", "a.b"), "#200000", "y.z a.b"); + assertThat(matcher.match("x", "y.z", "a.b")).as("y.z a.b").isEqualTo("#200000"); } @Test @@ -467,7 +467,7 @@ public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception { new ParsedThemeRule("variable.other", null, 4, None, null, null), new ParsedThemeRule("variable.parameter.function.coffee", null, 5, Italic, "#F9D423", null)); - assertArrayEquals(expected.toArray(), actual.toArray()); + assertThat(actual).isEqualTo(expected); } @Test @@ -505,6 +505,6 @@ public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exc new ParsedThemeRule("meta.at-rule.if.scss", null, 1, NotSet, "#CC7832", null), new ParsedThemeRule("punctuation.definition", list("meta.at-rule.if.scss"), 1, NotSet, "#CC7832", null)); - assertArrayEquals(expected.toArray(), actual.toArray()); + assertThat(actual).isEqualTo(expected); } } diff --git a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSParserTest.java b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSParserTest.java index cf8ce1312..7d103000e 100644 --- a/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSParserTest.java +++ b/org.eclipse.tm4e.core.tests/src/main/java/org/eclipse/tm4e/core/internal/theme/css/CSSParserTest.java @@ -12,7 +12,7 @@ */ package org.eclipse.tm4e.core.internal.theme.css; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.*; import org.eclipse.tm4e.core.theme.RGB; import org.eclipse.tm4e.core.theme.css.CSSParser; @@ -27,9 +27,9 @@ void testCSSParser() throws Exception { .storage.invalid { background-color: red; } """); - assertEquals(null, parser.getBestStyle("undefined")); - assertEquals(new RGB(255,128,128), parser.getBestStyle("invalid").getBackgroundColor()); - assertEquals(new RGB(255,0,0), parser.getBestStyle("storage", "invalid").getBackgroundColor()); - assertEquals(new RGB(255,0,0), parser.getBestStyle("storage" , "modifier", "invalid", "deprecated").getBackgroundColor()); + assertThat(parser.getBestStyle("undefined")).isNull(); + assertThat(parser.getBestStyle("invalid").getBackgroundColor()).isEqualTo(new RGB(255, 128, 128)); + assertThat(parser.getBestStyle("storage", "invalid").getBackgroundColor()).isEqualTo(new RGB(255, 0, 0)); + assertThat(parser.getBestStyle("storage", "modifier", "invalid", "deprecated").getBackgroundColor()).isEqualTo(new RGB(255, 0, 0)); } } diff --git a/org.eclipse.tm4e.core/build.properties b/org.eclipse.tm4e.core/build.properties index 047ed006b..944011674 100644 --- a/org.eclipse.tm4e.core/build.properties +++ b/org.eclipse.tm4e.core/build.properties @@ -6,4 +6,4 @@ bin.includes = META-INF/,\ about.html # JDT Null Analysis for Eclipse -additional.bundles = org.eclipse.jdt.annotation +additional.bundles = org.eclipse.jdt.annotation,assertj-core diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMModelTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMModelTest.java index a3037f76b..9651d2116 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMModelTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMModelTest.java @@ -9,8 +9,8 @@ */ package org.eclipse.tm4e.core.model; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.core.registry.IGrammarSource.fromResource; -import static org.junit.jupiter.api.Assertions.*; import org.eclipse.tm4e.core.Data; import org.eclipse.tm4e.core.internal.grammar.StateStack; @@ -31,7 +31,7 @@ function addNumbers(a: number, b: number) { // 1 const sum = addNumbers(10, 15); // 4 console.log('Sum is: ' + sum); // 5 """.split("\\r?\\n"); - assertEquals(5, textLines.length); + assertThat(textLines.length).isEqualTo(5); final var tmModel = new TMModel(textLines.length) { @Override @@ -43,7 +43,7 @@ public String getLineText(final int lineIndex) throws Exception { try { tmModel.setGrammar(grammar); - assertEquals(BackgroundTokenizationState.COMPLETED, tmModel.getBackgroundTokenizationState()); + assertThat(tmModel.getBackgroundTokenizationState()).isEqualTo(BackgroundTokenizationState.COMPLETED); // adding a listener will spawn the TokenizerThread tmModel.addModelTokensChangedListener(event -> { @@ -64,13 +64,13 @@ public String getLineText(final int lineIndex) throws Exception { Thread.yield(); } - assertEquals(BackgroundTokenizationState.COMPLETED, tmModel.getBackgroundTokenizationState()); + assertThat(tmModel.getBackgroundTokenizationState()).isEqualTo(BackgroundTokenizationState.COMPLETED); for (int i = 1; i < textLines.length; i++) { - assertNotEquals(StateStack.NULL, tmModel.lines.get(i).startState, "Line " + i + " is expected to be up-to-date"); + assertThat(tmModel.lines.get(i).startState).as("Line " + i + " is expected to be up-to-date").isNotEqualTo(StateStack.NULL); } for (int i = 0; i < textLines.length; i++) { - assertNotNull(tmModel.lines.get(i).tokens, "Line " + i + " is expected to be up-to-date"); + assertThat(tmModel.lines.get(i).tokens).as("Line " + i + " is expected to be up-to-date").isNotNull(); } } finally { tmModel.dispose(); diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMTokenizationTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMTokenizationTest.java index 20d1bf81e..e24dd6857 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMTokenizationTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/model/TMTokenizationTest.java @@ -9,8 +9,8 @@ */ package org.eclipse.tm4e.core.model; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.core.registry.IGrammarSource.fromResource; -import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.time.Duration; @@ -31,12 +31,12 @@ void testTokenizeWithTimeout() throws IOException { try (var reader = ResourceUtils.getResourceReader(Data.class, "raytracer.ts")) { final String veryLongLine = reader.lines().collect(Collectors.joining()); final var result1 = tokenizer.tokenize(veryLongLine, null); - assertFalse(result1.stoppedEarly); + assertThat(result1.stoppedEarly).isFalse(); final var result2 = tokenizer.tokenize(veryLongLine, null, null, Duration.ofMillis(10)); - assertTrue(result2.stoppedEarly); + assertThat(result2.stoppedEarly).isTrue(); - assertNotEquals(result1.tokens.size(), result2.tokens.size()); + assertThat(result1.tokens.size()).isNotEqualTo(result2.tokens.size()); } } } diff --git a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/registry/RegistryTest.java b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/registry/RegistryTest.java index 37013b97a..42300e4f5 100644 --- a/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/registry/RegistryTest.java +++ b/org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/registry/RegistryTest.java @@ -12,7 +12,7 @@ */ package org.eclipse.tm4e.core.registry; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.nio.file.FileVisitResult; @@ -43,21 +43,21 @@ public FileVisitResult visitFile(final Path file, final @Nullable BasicFileAttri System.out.println("Parsing [" + file + "]..."); final var grammar = reg.addGrammar(IGrammarSource.fromFile(file)); count.incrementAndGet(); - assertFalse(grammar.getScopeName().isBlank()); - assertNotNull(grammar.getFileTypes()); + assertThat(grammar.getScopeName()).isNotBlank(); + assertThat(grammar.getFileTypes()).isNotNull(); } } return FileVisitResult.CONTINUE; } }); System.out.println("Successfully parsed " + count.intValue() + " grammars."); - assertTrue(count.intValue() > 10, "Only " + count.intValue() + " grammars found, expected more than 10!"); + assertThat(count).as("Number of grammars found.").hasValueGreaterThan(10); } @Test void testLoadingUnknownGrammar() { final var reg = new Registry(); - assertNull(reg.grammarForScopeName("undefined")); - assertNull(reg.loadGrammar("undefined")); + assertThat(reg.grammarForScopeName("undefined")).isNull(); + assertThat(reg.loadGrammar("undefined")).isNull(); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF index 391533c98..8fefe34ae 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui.workbench, org.eclipse.ui.workbench.texteditor, org.eclipse.tm4e.languageconfiguration, - org.eclipse.tm4e.ui + org.eclipse.tm4e.ui, + assertj-core Bundle-ActivationPolicy: lazy Import-Package: org.junit.jupiter.api diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java index 0eefd1885..22cd8510f 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestAutoClosing.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; @@ -45,42 +45,50 @@ public void testAutoClose() throws Exception { file.create(new ByteArrayInputStream(new byte[0]), true, null); final ITextEditor editor = (ITextEditor) IDE.openEditor(UI.getActivePage(), file); final StyledText text = (StyledText) editor.getAdapter(Control.class); + // insert closing text.setText(""); text.replaceTextRange(0, 0, "("); - assertEquals("()", text.getText()); - assertEquals(1, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("()"); + assertThat(text.getCaretOffset()).isEqualTo(1); + // nested insert closing text.setText("foo(String::from)"); text.replaceTextRange(16, 0, "("); - assertEquals("foo(String::from())", text.getText()); - assertEquals(17, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("foo(String::from())"); + assertThat(text.getCaretOffset()).isEqualTo(17); + // ignore already opened text.setText("()"); text.replaceTextRange(0, 0, "("); - assertEquals("()", text.getText()); - assertEquals(1, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("()"); + assertThat(text.getCaretOffset()).isEqualTo(1); + // ignore already closed text.setText("()"); text.replaceTextRange(1, 0, ")"); - assertEquals("()", text.getText()); - assertEquals(2, text.getCaretOffset()); - // + assertThat(text.getText()).isEqualTo("()"); + assertThat(text.getCaretOffset()).isEqualTo(2); + + // extra closing text.setText("()"); text.replaceTextRange(2, 0, ")"); - assertEquals("())", text.getText()); - // + assertThat(text.getText()).isEqualTo("())"); + + // double quotes text.setText(""); text.replaceTextRange(0, 0, "\""); - assertEquals("\"\"", text.getText()); - assertEquals(1, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("\"\""); + assertThat(text.getCaretOffset()).isEqualTo(1); + // continued text.replaceTextRange(1, 0, "\""); - assertEquals("\"\"", text.getText()); - assertEquals(2, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("\"\""); + assertThat(text.getCaretOffset()).isEqualTo(2); + // continued text.replaceTextRange(2, 0, "\""); - assertEquals("\"\"\"\"", text.getText()); - assertEquals(3, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("\"\"\"\""); + assertThat(text.getCaretOffset()).isEqualTo(3); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java index 03a87b6b0..be3003b19 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java @@ -8,7 +8,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; @@ -50,14 +50,14 @@ public void testToggleLineCommentUseBlockComment() throws Exception { String text = doc.get(); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals("/*a*/\n\n/*b*/\n\n/*c*/", doc.get()); + assertThat(doc.get()).isEqualTo("/*a*/\n\n/*b*/\n\n/*c*/"); checktTextSelection(editor.getSelectionProvider().getSelection(), 2, 15); // Repeatedly executed toggle comment command should remove the comments inserted previously text = doc.get(); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals("a\n\nb\n\nc", doc.get()); + assertThat(doc.get()).isEqualTo("a\n\nb\n\nc"); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 7); } @@ -77,19 +77,19 @@ public void testToggleLineCommentUseBlockCommentnPartiallyIncludedEnds() throws service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); text = doc.get(); - assertEquals(" a ", text); + assertThat(text).isEqualTo(" a "); final ISelection selection = editor.getSelectionProvider().getSelection(); - assertNotNull(selection); - assertInstanceOf(ITextSelection.class, selection); + assertThat(selection).isNotNull(); + assertThat(selection).isInstanceOf(ITextSelection.class); final var textSelection = (ITextSelection) selection; - assertEquals(0, textSelection.getOffset()); - assertEquals(3, textSelection.getLength()); + assertThat(textSelection.getOffset()).isEqualTo(0); + assertThat(textSelection.getLength()).isEqualTo(3); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 3); // Repeatedly executed toggle comment command should remove the comments inserted previously editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals("/* a */", doc.get()); + assertThat(doc.get()).isEqualTo("/* a */"); checktTextSelection(editor.getSelectionProvider().getSelection(), 2, 3); } @@ -109,13 +109,13 @@ public void testToggleLineCommentUseBlockCommentAndWindowsEOL() throws Exception final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(0, 0)); // No matter the selection length service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals("/*a*/\r\n\r\nb\r\n\r\nc", doc.get()); + assertThat(doc.get()).isEqualTo("/*a*/\r\n\r\nb\r\n\r\nc"); checktTextSelection(editor.getSelectionProvider().getSelection(), 2, 0); // Repeatedly executed toggle comment command should remove the comments inserted previously editor.getSelectionProvider().setSelection(new TextSelection(0, 0)); // No matter the selection length service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals("a\r\n\r\nb\r\n\r\nc", doc.get()); + assertThat(doc.get()).isEqualTo("a\r\n\r\nb\r\n\r\nc"); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 0); } @@ -139,11 +139,11 @@ public void testToggleLineComment() throws Exception { editor.getSelectionProvider().setSelection(new TextSelection(indexOfA, lengthToC)); service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); String commented = padding + "//a\n//b\n//c\n" + padding; - assertEquals(commented, doc.get()); + assertThat(doc.get()).isEqualTo(commented); // Repeatedly executed toggle comment command should remove the comments inserted previously service.executeCommand(ToggleLineCommentHandler.TOGGLE_LINE_COMMENT_COMMAND_ID, null); - assertEquals(input, doc.get()); + assertThat(doc.get()).isEqualTo(input); checktTextSelection(editor.getSelectionProvider().getSelection(), indexOfA, lengthToC); } @@ -161,14 +161,14 @@ public void testToggleBlockCommentUseLineComment() throws Exception { String text = doc.get(); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.ADD_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals("//a\n//\n//b\n//\n//c", doc.get()); + assertThat(doc.get()).isEqualTo("//a\n//\n//b\n//\n//c"); checktTextSelection(editor.getSelectionProvider().getSelection(), 2, 15); // Repeatedly executed toggle comment command should remove the comments inserted previously text = doc.get(); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals("a\n\nb\n\nc", doc.get()); + assertThat(doc.get()).isEqualTo("a\n\nb\n\nc"); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 7); } @@ -186,7 +186,7 @@ public void testRemoveBlockComment() throws Exception { final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals(" a ", doc.get()); + assertThat(doc.get()).isEqualTo(" a "); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 0); } @@ -204,7 +204,7 @@ public void testRemoveBlockCommentMultiplesComments() throws Exception { final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(0, text.length())); service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals(" a b c ", doc.get()); + assertThat(doc.get()).isEqualTo(" a b c "); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 0); } @@ -222,7 +222,7 @@ public void testRemoveBlockCommentPartiallyIncludedEnds() throws Exception { final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(1, text.length() - 2)); service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals(" a ", doc.get()); + assertThat(doc.get()).isEqualTo(" a "); checktTextSelection(editor.getSelectionProvider().getSelection(), 0, 0); } @@ -240,7 +240,7 @@ public void testRemoveBlockCommentMultiplesCommentsBrokenEnds() throws Exception final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(5, 7)); // [*/ b /*] service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals(" a b c ", doc.get()); + assertThat(doc.get()).isEqualTo(" a b c "); checktTextSelection(editor.getSelectionProvider().getSelection(), 3, 0); } @@ -258,7 +258,7 @@ public void testRemoveBlockCommentMultiplesCommentsBrokenPartiallyIncludedEnds() final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(6, 5)); // [/ b /] service.executeCommand(ToggleLineCommentHandler.REMOVE_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals(" a b c ", doc.get()); + assertThat(doc.get()).isEqualTo(" a b c "); checktTextSelection(editor.getSelectionProvider().getSelection(), 3, 0); } @@ -276,7 +276,7 @@ public void testAddBlockComment() throws Exception { final var service = PlatformUI.getWorkbench().getService(IHandlerService.class); editor.getSelectionProvider().setSelection(new TextSelection(2, 1)); // [b] service.executeCommand(ToggleLineCommentHandler.ADD_BLOCK_COMMENT_COMMAND_ID, null); - assertEquals("a /*b*/ c", doc.get()); + assertThat(doc.get()).isEqualTo("a /*b*/ c"); checktTextSelection(editor.getSelectionProvider().getSelection(), 4, 0); } @@ -296,15 +296,15 @@ public void testAddBlockCommentInsideExistingBockComment() throws Exception { service.executeCommand(ToggleLineCommentHandler.ADD_BLOCK_COMMENT_COMMAND_ID, null); // No comment is to be added because the selection is already inside a block comment - assertEquals(text, doc.get()); + assertThat(doc.get()).isEqualTo(text); checktTextSelection(editor.getSelectionProvider().getSelection(), 4, 1); } private void checktTextSelection(final ISelection selection, final int expectedOffset, final int expectedLength) { - assertNotNull(selection); - assertInstanceOf(ITextSelection.class, selection); + assertThat(selection).isNotNull(); + assertThat(selection).isInstanceOf(ITextSelection.class); final var textSelection = (ITextSelection) selection; - assertEquals(expectedOffset, textSelection.getOffset()); - assertEquals(expectedLength, textSelection.getLength()); + assertThat(textSelection.getOffset()).isEqualTo(expectedOffset); + assertThat(textSelection.getLength()).isEqualTo(expectedLength); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java index 3f08dd31a..12e3f6f4b 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndent.java @@ -8,7 +8,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; @@ -45,11 +45,11 @@ public void testIndentOnNewLine() throws Exception { text.setText("\t"); text.setSelection(text.getText().length()); text.insert("\n"); - assertEquals("\t\n\t", text.getText()); + assertThat(text.getText()).isEqualTo("\t\n\t"); // Space only text.setText(" "); text.setSelection(text.getText().length()); text.insert("\n"); - assertEquals(" \n ", text.getText()); + assertThat(text.getText()).isEqualTo(" \n "); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndentationRules.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndentationRules.java index 3d7fda8f9..115450dc0 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndentationRules.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestIndentationRules.java @@ -12,7 +12,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; @@ -50,13 +50,13 @@ public void testIndentAdjustmentOnPaste() throws Exception { text.setText(""); text.setSelection(0); text.insert(" function bar() {\n }"); - assertEquals("function bar() {\n}", text.getText()); + assertThat(text.getText()).isEqualTo("function bar() {\n}"); // insert an unindented code snippet into the body of a class and expect it to be indented text.setText("public class Foo {\n\n}"); text.setSelection(19); text.insert("function bar() {\n}"); - assertEquals("public class Foo {\n\tfunction bar() {\n\t}\n}", text.getText()); + assertThat(text.getText()).isEqualTo("public class Foo {\n\tfunction bar() {\n\t}\n}"); // insert single line text and ensure the text is only indented in blank lines text.setText("public class Foo {\n\n}"); @@ -64,7 +64,7 @@ public void testIndentAdjustmentOnPaste() throws Exception { text.insert("bar"); text.setSelection(16); text.insert("bar"); - assertEquals("public class Foobar {\n\tbar\n}", text.getText()); + assertThat(text.getText()).isEqualTo("public class Foobar {\n\tbar\n}"); } @Test @@ -81,6 +81,6 @@ public void testIndentAdjustmentOnEnter() throws Exception { text.setText("public class Foo {\n\n}"); text.setSelection(18); text.insert("\n"); - assertEquals("public class Foo {\n\t\n\n}", text.getText()); + assertThat(text.getText()).isEqualTo("public class Foo {\n\t\n\n}"); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestOnEnter.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestOnEnter.java index ced83ee81..1cf0dd14a 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestOnEnter.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestOnEnter.java @@ -8,7 +8,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; @@ -43,6 +43,6 @@ public void testOnEnter() throws Exception { final StyledText text = (StyledText) editor.getAdapter(Control.class); text.setSelection(text.getText().length()); text.insert("\n"); - assertEquals(" ///\n /// ", text.getText()); + assertThat(text.getText()).isEqualTo(" ///\n /// "); } } diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestSurroundingPairs.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestSurroundingPairs.java index d495f5c6c..469e93f75 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestSurroundingPairs.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestSurroundingPairs.java @@ -12,7 +12,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.util.stream.Stream; @@ -61,22 +61,21 @@ public void testSurroundingPairs() throws Exception { text.setText("the mountain is high"); text.setSelection(4, 12); - assertEquals(12, text.getCaretOffset()); - assertEquals("mountain", text.getSelectionText()); + assertThat(text.getCaretOffset()).isEqualTo(12); + assertThat(text.getSelectionText()).isEqualTo("mountain"); text.insert("("); - assertEquals("the (mountain) is high", text.getText()); - assertEquals("mountain", text.getSelectionText()); - assertEquals(13, text.getCaretOffset()); + assertThat(text.getText()).isEqualTo("the (mountain) is high"); + assertThat(text.getSelectionText()).isEqualTo("mountain"); + assertThat(text.getCaretOffset()).isEqualTo(13); // test with disabled surrounding pairs langDef.setMatchingPairsEnabled(false); text.setText("the mountain is high"); text.setSelection(4, 12); - assertEquals(12, text.getCaretOffset()); - assertEquals("mountain", text.getSelectionText()); + assertThat(text.getCaretOffset()).isEqualTo(12); + assertThat(text.getSelectionText()).isEqualTo("mountain"); text.insert("("); - assertEquals("the ( is high", text.getText()); - + assertThat(text.getText()).isEqualTo("the ( is high"); } } diff --git a/org.eclipse.tm4e.languageconfiguration/build.properties b/org.eclipse.tm4e.languageconfiguration/build.properties index c0f01f4c0..0bbc0d82d 100644 --- a/org.eclipse.tm4e.languageconfiguration/build.properties +++ b/org.eclipse.tm4e.languageconfiguration/build.properties @@ -9,4 +9,4 @@ bin.includes = META-INF/,\ about.html # JDT Null Analysis for Eclipse -additional.bundles = org.eclipse.jdt.annotation +additional.bundles = org.eclipse.jdt.annotation,assertj-core diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/IndentationRulesTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/IndentationRulesTest.java index ede147667..bd647c641 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/IndentationRulesTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/IndentationRulesTest.java @@ -16,12 +16,11 @@ */ package org.eclipse.tm4e.languageconfiguration.internal; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNonNull; -import static org.junit.jupiter.api.Assertions.*; import java.io.StringReader; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.IDocument; import org.eclipse.tm4e.languageconfiguration.internal.model.CursorConfiguration; import org.eclipse.tm4e.languageconfiguration.internal.model.IndentForEnter; @@ -79,15 +78,14 @@ public function bar() { } - private void assertResult(final @Nullable IndentForEnter result, final String beforeEnter, final String AfterEnter, - final String indent) { - assertNotNull(result); - assertEquals(beforeEnter, result.beforeEnter); - assertEquals(AfterEnter, result.afterEnter); - assertEquals(indent, indentConv.normalizeIndentation(AfterEnter)); + private void assertResult(final IndentForEnter result, final String expectedBeforeEnter, final String expectedAfterEnter, + final String expectedIndent) { + assertThat(result.beforeEnter).isEqualTo(expectedBeforeEnter); + assertThat(result.afterEnter).isEqualTo(expectedAfterEnter); + assertThat(indentConv.normalizeIndentation(expectedAfterEnter)).isEqualTo(expectedIndent); } - private @Nullable IndentForEnter getIndentForEnter(final IDocument doc, final int offset) { - return IndentForEnterHelper.getIndentForEnter(doc, offset, indentConv, indentRulesSupport); + private IndentForEnter getIndentForEnter(final IDocument doc, final int offset) { + return castNonNull(IndentForEnterHelper.getIndentForEnter(doc, offset, indentConv, indentRulesSupport)); } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/model/ParsingTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/model/ParsingTest.java index 591766f90..16bf29d58 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/model/ParsingTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/model/ParsingTest.java @@ -9,7 +9,8 @@ **********************************************************************/ package org.eclipse.tm4e.languageconfiguration.internal.model; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNonNull; import java.io.IOException; import java.io.InputStream; @@ -28,16 +29,20 @@ class ParsingTest { - private @Nullable LanguageConfiguration loadLanguageConfiguration(final String path) throws IOException { + private LanguageConfiguration loadLanguageConfigFromClassPath(final String path) throws IOException { try (InputStream is = getClass().getResourceAsStream(path)) { - assertNotNull(is); - return LanguageConfiguration.load(new InputStreamReader(is)); + assert is != null; + return castNonNull(LanguageConfiguration.load(new InputStreamReader(is))); } } + private LanguageConfiguration loadLanguageConfigFromString(final String content) { + return castNonNull(LanguageConfiguration.load(new StringReader(content))); + } + @Test void testOniguramaFallback() { - final var languageConfiguration = LanguageConfiguration.load(new StringReader(""" + final var languageConfiguration = loadLanguageConfigFromString(""" { "onEnterRules": [{ "beforeText": "^[\\\\s]*///.*$", @@ -51,48 +56,42 @@ void testOniguramaFallback() { "end": "{%\\\\s*end(block|filter|for|if|macro|raw)\\\\s*%}" } } - }""")); - assertNotNull(languageConfiguration); + }"""); + assertThat(languageConfiguration.getOnEnterRules().get(0).beforeText.getClass().getSimpleName()) + .endsWith("JavaRegExPattern"); - assertTrue(languageConfiguration.getOnEnterRules().get(0).beforeText.getClass().getSimpleName().endsWith("JavaRegExPattern")); - - final var folding = languageConfiguration.getFolding(); - assert folding != null; - assertTrue(folding.markers.start.getClass().getSimpleName().endsWith("OnigRegExPattern")); + final var folding = castNonNull(languageConfiguration.getFolding()); + assertThat(folding.markers.start.getClass().getSimpleName()).endsWith("OnigRegExPattern"); } @Test void testCanLoadPhpLanguageConfig() throws Exception { - final var languageConfiguration = loadLanguageConfiguration("/php-language-configuration.json"); - assertNotNull(languageConfiguration); - final var comments = languageConfiguration.getComments(); - assertNotNull(comments); - assertNotNull(comments.blockComment); - assertEquals("//", comments.lineComment); - assertEquals(3, languageConfiguration.getBrackets().size()); - assertEquals(6, languageConfiguration.getAutoClosingPairs().size()); - assertEquals(";:.,=}])>` \n\t", languageConfiguration.getAutoCloseBefore()); - assertNotNull(languageConfiguration.getWordPattern()); - assertEquals(5, languageConfiguration.getOnEnterRules().size()); - assertEquals(6, languageConfiguration.getSurroundingPairs().size()); - assertNotNull(languageConfiguration.getFolding()); + final var languageConfiguration = loadLanguageConfigFromClassPath("/php-language-configuration.json"); + final var comments = castNonNull(languageConfiguration.getComments()); + assertThat(comments.blockComment).isNotNull(); + assertThat(comments.lineComment).isEqualTo("//"); + assertThat(languageConfiguration.getBrackets()).hasSize(3); + assertThat(languageConfiguration.getAutoClosingPairs()).hasSize(6); + assertThat(languageConfiguration.getAutoCloseBefore()).isEqualTo(";:.,=}])>` \n\t"); + assertThat(languageConfiguration.getWordPattern()).isNotNull(); + assertThat(languageConfiguration.getOnEnterRules()).hasSize(5); + assertThat(languageConfiguration.getSurroundingPairs()).hasSize(6); + assertThat(languageConfiguration.getFolding()).isNotNull(); } @Test void testCanLoadRustLanguageConfig() throws Exception { - final var languageConfiguration = loadLanguageConfiguration("/rust-language-configuration.json"); - assertNotNull(languageConfiguration); - final var comments = languageConfiguration.getComments(); - assertNotNull(comments); - assertNotNull(comments.blockComment); - assertEquals("//", comments.lineComment); - assertEquals(4, languageConfiguration.getBrackets().size()); - assertEquals(6, languageConfiguration.getAutoClosingPairs().size()); - assertNull(languageConfiguration.getAutoCloseBefore()); - assertNull(languageConfiguration.getWordPattern()); - assertEquals(6, languageConfiguration.getOnEnterRules().size()); - assertEquals(6, languageConfiguration.getSurroundingPairs().size()); - assertNull(languageConfiguration.getFolding()); + final var languageConfiguration = loadLanguageConfigFromClassPath("/rust-language-configuration.json"); + final var comments = castNonNull(languageConfiguration.getComments()); + assertThat(comments.blockComment).isNotNull(); + assertThat(comments.lineComment).isEqualTo("//"); + assertThat(languageConfiguration.getBrackets()).hasSize(4); + assertThat(languageConfiguration.getAutoClosingPairs()).hasSize(6); + assertThat(languageConfiguration.getAutoCloseBefore()).isNull(); + assertThat(languageConfiguration.getWordPattern()).isNull(); + assertThat(languageConfiguration.getOnEnterRules()).hasSize(6); + assertThat(languageConfiguration.getSurroundingPairs()).hasSize(6); + assertThat(languageConfiguration.getFolding()).isNull(); } @Test @@ -106,19 +105,19 @@ public FileVisitResult visitFile(final Path file, final @Nullable BasicFileAttri System.out.println("Parsing [" + file + "]..."); final var languageConfiguration = LanguageConfiguration.load(input); count.incrementAndGet(); - assertNotNull(languageConfiguration); + assertThat(languageConfiguration).isNotNull(); } } return FileVisitResult.CONTINUE; } }); System.out.println("Successfully parsed " + count.intValue() + " language configurations."); - assertTrue(count.intValue() > 10, "Only " + count.intValue() + " language configurations found, expected more than 10!"); + assertThat(count.intValue()).isGreaterThan(10); } @Test void testParseColorizedBracketsPair() { - final var languageConfiguration = LanguageConfiguration.load(new StringReader(""" + final var languageConfiguration = loadLanguageConfigFromString(""" { "colorizedBracketPairs": [ ["(",")"], @@ -126,28 +125,27 @@ void testParseColorizedBracketsPair() { ["{","}"], ["<",">"] ], - }""")); - assertNotNull(languageConfiguration); + }"""); - assertEquals(4, languageConfiguration.getColorizedBracketPairs().size()); - assertEquals("(", languageConfiguration.getColorizedBracketPairs().get(0).open); - assertEquals(")", languageConfiguration.getColorizedBracketPairs().get(0).close); + assertThat(languageConfiguration.getColorizedBracketPairs()).hasSize(4); + assertThat(languageConfiguration.getColorizedBracketPairs().get(0).open).isEqualTo("("); + assertThat(languageConfiguration.getColorizedBracketPairs().get(0).close).isEqualTo(")"); } @Test void testIndentationRules() { - final var languageConfiguration = LanguageConfiguration.load(new StringReader(""" + final var languageConfiguration = loadLanguageConfigFromString(""" { "indentationRules": { "increaseIndentPattern": "(^.*\\\\{[^}]*$)", "decreaseIndentPattern": "^\\\\s*\\\\}" }, - }""")); - assertNotNull(languageConfiguration); + }"""); var indentationRules = languageConfiguration.getIndentationRules(); assert indentationRules != null; - assertEquals("(^.*\\{[^}]*$)", indentationRules.increaseIndentPattern.toString()); - assertEquals("^\\s*\\}", indentationRules.decreaseIndentPattern.toString()); + + assertThat(indentationRules.increaseIndentPattern).hasToString("(^.*\\{[^}]*$)"); + assertThat(indentationRules.decreaseIndentPattern).hasToString("^\\s*\\}"); } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java index 1c3058bd1..3d6e76ac2 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupportTest.java @@ -18,7 +18,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.supports; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -86,10 +86,10 @@ class Support extends OnEnterSupport { void testIndentAction(final String beforeText, final String afterText, final IndentAction expected) { final EnterAction actual = onEnter("", beforeText, afterText); if (expected == IndentAction.None) { - assertNull(actual); + assertThat(actual).isNull(); } else { - assertNotNull(actual); - assertEquals(expected, actual.indentAction); + assert actual != null; + assertThat(actual.indentAction).isEqualTo(expected); } } } @@ -129,20 +129,22 @@ void testIndentAction(final String previousLineText, final String beforeText, fi testIndentAction(previousLineText, beforeText, afterText, expectedIndentAction, expectedAppendText, 0); } + @SuppressWarnings("null") void testIndentAction(final String previousLineText, final String beforeText, final String afterText, final @Nullable IndentAction expectedIndentAction, final @Nullable String expectedAppendText, final int removeText) { final EnterAction actual = onEnter(previousLineText, beforeText, afterText); if (expectedIndentAction == null) { - assertNull(actual, "isNull:" + beforeText); + assertThat(actual).as("isNull:" + beforeText).isNull(); } else { - assertNotNull(actual, "isNotNull:" + beforeText); - assertEquals(expectedIndentAction, actual.indentAction, "indentAction:" + beforeText); + assertThat(actual).as("isNotNull:" + beforeText).isNotNull(); + assert actual != null; + assertThat(actual.indentAction).as("indentAction:" + beforeText).isEqualTo(expectedIndentAction); if (expectedAppendText != null) { - assertEquals(expectedAppendText, actual.appendText, "appendText:" + beforeText); + assertThat(actual.appendText).as("appendText:" + beforeText).isEqualTo(expectedAppendText); } if (removeText != 0) { - assertEquals(removeText, actual.removeText, "removeText:" + beforeText); + assertThat(actual.removeText).as("removeText:" + beforeText).isEqualTo(removeText); } } } @@ -230,10 +232,10 @@ class Support extends OnEnterSupport { void testIndentAction(final String beforeText, final String afterText, final @Nullable IndentAction expected) { final EnterAction actual = onEnter("", beforeText, afterText); if (expected == IndentAction.None) { - assertNull(actual); + assertThat(actual).isNull(); } else { - assertNotNull(actual); - assertEquals(expected, actual.indentAction); + assert actual != null; + assertThat(actual.indentAction).isEqualTo(expected); } } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/IndentationTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/IndentationTest.java index 96e3d2d0c..b833eb9bd 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/IndentationTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/IndentationTest.java @@ -17,7 +17,7 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.utils; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.eclipse.tm4e.languageconfiguration.internal.model.CursorConfiguration; import org.junit.jupiter.api.Test; @@ -33,45 +33,45 @@ class IndentationTest { void testNormalizeIndentation1() { var cursorCfg = new CursorConfiguration(false, 4); - assertEquals("\t", cursorCfg.normalizeIndentation("\t")); - assertEquals("\t", cursorCfg.normalizeIndentation(" ")); - assertEquals(" ", cursorCfg.normalizeIndentation(" ")); - assertEquals(" ", cursorCfg.normalizeIndentation(" ")); - assertEquals(" ", cursorCfg.normalizeIndentation(" ")); - assertEquals("", cursorCfg.normalizeIndentation("")); - assertEquals("\t\t", cursorCfg.normalizeIndentation(" \t ")); - assertEquals("\t ", cursorCfg.normalizeIndentation(" \t ")); - assertEquals("\t ", cursorCfg.normalizeIndentation(" \t ")); - assertEquals("\t ", cursorCfg.normalizeIndentation(" \t ")); - assertEquals("\t", cursorCfg.normalizeIndentation(" \t")); + assertThat(cursorCfg.normalizeIndentation("\t")).isEqualTo("\t"); + assertThat(cursorCfg.normalizeIndentation(" ")).isEqualTo("\t"); + assertThat(cursorCfg.normalizeIndentation(" ")).isEqualTo(" "); + assertThat(cursorCfg.normalizeIndentation(" ")).isEqualTo(" "); + assertThat(cursorCfg.normalizeIndentation(" ")).isEqualTo(" "); + assertThat(cursorCfg.normalizeIndentation("")).isEqualTo(""); + assertThat(cursorCfg.normalizeIndentation(" \t ")).isEqualTo("\t\t"); + assertThat(cursorCfg.normalizeIndentation(" \t ")).isEqualTo("\t "); + assertThat(cursorCfg.normalizeIndentation(" \t ")).isEqualTo("\t "); + assertThat(cursorCfg.normalizeIndentation(" \t ")).isEqualTo("\t "); + assertThat(cursorCfg.normalizeIndentation(" \t")).isEqualTo("\t"); - assertEquals("\ta", cursorCfg.normalizeIndentation("\ta")); - assertEquals("\ta", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals("a", cursorCfg.normalizeIndentation("a")); - assertEquals("\t\ta", cursorCfg.normalizeIndentation(" \t a")); - assertEquals("\t a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals("\t a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals("\t a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals("\ta", cursorCfg.normalizeIndentation(" \ta")); + assertThat(cursorCfg.normalizeIndentation("\ta")).isEqualTo("\ta"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo("\ta"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation("a")).isEqualTo("a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo("\t\ta"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo("\t a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo("\t a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo("\t a"); + assertThat(cursorCfg.normalizeIndentation(" \ta")).isEqualTo("\ta"); } @Test void testNormalizeIndentation2() { var cursorCfg = new CursorConfiguration(true, 4); - assertEquals(" a", cursorCfg.normalizeIndentation("\ta")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" a")); - assertEquals("a", cursorCfg.normalizeIndentation("a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" \t a")); - assertEquals(" a", cursorCfg.normalizeIndentation(" \ta")); + assertThat(cursorCfg.normalizeIndentation("\ta")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation("a")).isEqualTo("a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" \t a")).isEqualTo(" a"); + assertThat(cursorCfg.normalizeIndentation(" \ta")).isEqualTo(" a"); } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/StringsTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/StringsTest.java index 5af8bc534..fbb9591fd 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/StringsTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/StringsTest.java @@ -17,8 +17,8 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.utils; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.languageconfiguration.internal.utils.Strings.*; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -31,26 +31,26 @@ class StringsTest { @Test void testLastNonWhitespaceIndex() { - assertEquals(2, lastNonWhitespaceIndex("abc \t \t ")); - assertEquals(2, lastNonWhitespaceIndex("abc")); - assertEquals(2, lastNonWhitespaceIndex("abc\t")); - assertEquals(2, lastNonWhitespaceIndex("abc ")); - assertEquals(2, lastNonWhitespaceIndex("abc \t \t ")); - assertEquals(11, lastNonWhitespaceIndex("abc \t \t abc \t \t ")); - assertEquals(2, lastNonWhitespaceIndex("abc \t \t abc \t \t ", 8)); - assertEquals(-1, lastNonWhitespaceIndex(" \t \t ")); + assertThat(lastNonWhitespaceIndex("abc \t \t ")).isEqualTo(2); + assertThat(lastNonWhitespaceIndex("abc")).isEqualTo(2); + assertThat(lastNonWhitespaceIndex("abc\t")).isEqualTo(2); + assertThat(lastNonWhitespaceIndex("abc ")).isEqualTo(2); + assertThat(lastNonWhitespaceIndex("abc \t \t ")).isEqualTo(2); + assertThat(lastNonWhitespaceIndex("abc \t \t abc \t \t ")).isEqualTo(11); + assertThat(lastNonWhitespaceIndex("abc \t \t abc \t \t ", 8)).isEqualTo(2); + assertThat(lastNonWhitespaceIndex(" \t \t ")).isEqualTo(-1); } @Test void testGetLeadingWhitespace() { - assertEquals(" ", getLeadingWhitespace(" foo")); - assertEquals("", getLeadingWhitespace(" foo", 2)); - assertEquals("", getLeadingWhitespace(" foo", 1, 1)); - assertEquals(" ", getLeadingWhitespace(" foo", 0, 1)); - assertEquals(" ", getLeadingWhitespace(" ")); - assertEquals(" ", getLeadingWhitespace(" ", 1)); - assertEquals(" ", getLeadingWhitespace(" ", 0, 1)); - assertEquals("\t", getLeadingWhitespace("\t\tfunction foo(){", 0, 1)); - assertEquals("\t\t", getLeadingWhitespace("\t\tfunction foo(){", 0, 2)); + assertThat(getLeadingWhitespace(" foo")).isEqualTo(" "); + assertThat(getLeadingWhitespace(" foo", 2)).isEqualTo(""); + assertThat(getLeadingWhitespace(" foo", 1, 1)).isEqualTo(""); + assertThat(getLeadingWhitespace(" foo", 0, 1)).isEqualTo(" "); + assertThat(getLeadingWhitespace(" ")).isEqualTo(" "); + assertThat(getLeadingWhitespace(" ", 1)).isEqualTo(" "); + assertThat(getLeadingWhitespace(" ", 0, 1)).isEqualTo(" "); + assertThat(getLeadingWhitespace("\t\tfunction foo(){", 0, 1)).isEqualTo("\t"); + assertThat(getLeadingWhitespace("\t\tfunction foo(){", 0, 2)).isEqualTo("\t\t"); } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtilsTest.java b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtilsTest.java index 3bf8a981a..4c479fe8b 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtilsTest.java +++ b/org.eclipse.tm4e.languageconfiguration/src/test/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtilsTest.java @@ -12,8 +12,8 @@ */ package org.eclipse.tm4e.languageconfiguration.internal.utils; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.languageconfiguration.internal.utils.TextUtils.*; -import static org.junit.jupiter.api.Assertions.*; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.tm4e.languageconfiguration.internal.model.CursorConfiguration; @@ -27,142 +27,142 @@ private static MockDocument newDoc(final String txt) { @Test void testIsEnter() { - assertTrue(isEnter(newDoc(""), new DocumentCommand() { + assertThat(isEnter(newDoc(""), new DocumentCommand() { { text = "\n"; } - })); - assertTrue(isEnter(newDoc(""), new DocumentCommand() { + })).isTrue(); + assertThat(isEnter(newDoc(""), new DocumentCommand() { { text = "\r\n"; } - })); - assertFalse(isEnter(newDoc(""), new DocumentCommand() { + })).isTrue(); + assertThat(isEnter(newDoc(""), new DocumentCommand() { { text = "word"; } - })); + })).isFalse(); } @Test void testGetIndentationFromWhitespace() { - assertEquals("\t\t", getIndentationFromWhitespace("\t\t", new CursorConfiguration(false, 0))); - assertEquals("\t\t", getIndentationFromWhitespace("\t\t", new CursorConfiguration(true, 2))); - assertEquals("\t\t", getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))); - assertEquals("\t\t ", getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))); - assertEquals("\t\t ", getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))); - assertEquals("", getIndentationFromWhitespace(" \t ", new CursorConfiguration(true, 2))); + assertThat(getIndentationFromWhitespace("\t\t", new CursorConfiguration(false, 0))).isEqualTo("\t\t"); + assertThat(getIndentationFromWhitespace("\t\t", new CursorConfiguration(true, 2))).isEqualTo("\t\t"); + assertThat(getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))).isEqualTo("\t\t"); + assertThat(getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))).isEqualTo("\t\t "); + assertThat(getIndentationFromWhitespace("\t\t ", new CursorConfiguration(true, 2))).isEqualTo("\t\t "); + assertThat(getIndentationFromWhitespace(" \t ", new CursorConfiguration(true, 2))).isEqualTo(""); } @Test void testGetLeadingWhitespace() throws Exception { final var indent = "\t \t "; - assertEquals(indent, getLeadingWhitespace(newDoc(indent + "hello"), 0)); - assertEquals(indent, getLeadingWhitespace(newDoc("hello\n" + indent + "world"), 1)); - assertEquals(indent, getIndentationAtPosition(newDoc(indent + "hello"), indent.length() + 2)); + assertThat(getLeadingWhitespace(newDoc(indent + "hello"), 0)).isEqualTo(indent); + assertThat(getLeadingWhitespace(newDoc("hello\n" + indent + "world"), 1)).isEqualTo(indent); + assertThat(getIndentationAtPosition(newDoc(indent + "hello"), indent.length() + 2)).isEqualTo(indent); } @Test - void testIndentationAtPosition() throws Exception { + void testIndentationAtPosition() { final var indent = "\t \t "; - assertEquals("", getIndentationAtPosition(newDoc(indent + "hello"), 0)); - assertEquals("\t", getIndentationAtPosition(newDoc(indent + "hello"), 1)); - assertEquals("\t ", getIndentationAtPosition(newDoc(indent + "hello"), 2)); + assertThat(getIndentationAtPosition(newDoc(indent + "hello"), 0)).isEqualTo(""); + assertThat(getIndentationAtPosition(newDoc(indent + "hello"), 1)).isEqualTo("\t"); + assertThat(getIndentationAtPosition(newDoc(indent + "hello"), 2)).isEqualTo("\t "); } @Test void testIsBlankLine() { - assertTrue(isBlankLine(newDoc(""), 0)); - assertTrue(isBlankLine(newDoc(" "), 0)); - assertTrue(isBlankLine(newDoc(" \t"), 0)); - assertTrue(isBlankLine(newDoc("\n\n"), 1)); - assertTrue(isBlankLine(newDoc("\n \n"), 1)); - assertTrue(isBlankLine(newDoc("\n \t\n"), 1)); - - assertFalse(isBlankLine(newDoc("word"), 0)); - assertFalse(isBlankLine(newDoc("\nword\n"), 1)); + assertThat(isBlankLine(newDoc(""), 0)).isTrue(); + assertThat(isBlankLine(newDoc(" "), 0)).isTrue(); + assertThat(isBlankLine(newDoc(" \t"), 0)).isTrue(); + assertThat(isBlankLine(newDoc("\n\n"), 1)).isTrue(); + assertThat(isBlankLine(newDoc("\n \n"), 1)).isTrue(); + assertThat(isBlankLine(newDoc("\n \t\n"), 1)).isTrue(); + + assertThat(isBlankLine(newDoc("word"), 0)).isFalse(); + assertThat(isBlankLine(newDoc("\nword\n"), 1)).isFalse(); } @Test void testIsEmptyLine() { - assertTrue(isEmptyLine(newDoc(""), 0)); - assertFalse(isEmptyLine(newDoc(" "), 0)); - assertFalse(isEmptyLine(newDoc(" \t"), 0)); - assertTrue(isEmptyLine(newDoc("\n\n"), 1)); - assertFalse(isEmptyLine(newDoc("\n \n"), 1)); - assertFalse(isEmptyLine(newDoc("\n \t\n"), 1)); - - assertFalse(isEmptyLine(newDoc("word"), 0)); - assertFalse(isEmptyLine(newDoc("\nword\n"), 1)); + assertThat(isEmptyLine(newDoc(""), 0)).isTrue(); + assertThat(isEmptyLine(newDoc(" "), 0)).isFalse(); + assertThat(isEmptyLine(newDoc(" \t"), 0)).isFalse(); + assertThat(isEmptyLine(newDoc("\n\n"), 1)).isTrue(); + assertThat(isEmptyLine(newDoc("\n \n"), 1)).isFalse(); + assertThat(isEmptyLine(newDoc("\n \t\n"), 1)).isFalse(); + + assertThat(isEmptyLine(newDoc("word"), 0)).isFalse(); + assertThat(isEmptyLine(newDoc("\nword\n"), 1)).isFalse(); } @Test void testReplaceIndent_IndentEmptyLines() { - assertEquals("", replaceIndent("\t\t", 2, "", true).toString()); - assertEquals("foo ", replaceIndent("foo ", 2, "", true).toString()); - assertEquals("foo", replaceIndent(" \t foo", 2, "", true).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n bar", 2, "", true).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n\tbar", 2, "", true).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n\tbar", 2, "", true).toString()); - assertEquals("foo\n\tbar", replaceIndent("\tfoo\n\t\tbar", 2, "", true).toString()); - assertEquals("foo\n\tbar", replaceIndent("\tfoo\n \tbar", 2, "", true).toString()); - - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n bar", 2, "", true).toString()); - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n\tbar", 2, "", true).toString()); - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n\tbar", 2, "", true).toString()); - assertEquals("foo\r\n\tbar", replaceIndent("\tfoo\r\n\t\tbar", 2, "", true).toString()); - assertEquals("foo\r\n\tbar", replaceIndent("\tfoo\r\n \tbar", 2, "", true).toString()); - - assertEquals("..", replaceIndent("\t\t", 2, "..", true).toString()); - assertEquals("..foo ", replaceIndent("foo ", 2, "..", true).toString()); - assertEquals("..foo", replaceIndent(" \t foo", 2, "..", true).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n bar", 2, "..", true).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n\tbar", 2, "..", true).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n\tbar", 2, "..", true).toString()); - assertEquals("..foo\n..\tbar", replaceIndent("\tfoo\n\t\tbar", 2, "..", true).toString()); - assertEquals("..foo\n..\tbar", replaceIndent("\tfoo\n \tbar", 2, "..", true).toString()); - - assertEquals("..\n", replaceIndent("\n", 2, "..", true).toString()); - assertEquals("..\n..\n", replaceIndent("\n\n", 2, "..", true).toString()); - assertEquals("..foo\n..bar\n", replaceIndent("\tfoo\n\tbar\n", 2, "..", true).toString()); - - assertEquals("..\r\n", replaceIndent("\r\n", 2, "..", true).toString()); - assertEquals("..\r\n..\r\n", replaceIndent("\r\n\r\n", 2, "..", true).toString()); - assertEquals("..foo\r\n..bar\r\n", replaceIndent("\tfoo\r\n\tbar\r\n", 2, "..", true).toString()); + assertThat(replaceIndent("\t\t", 2, "", true)).hasToString(""); + assertThat(replaceIndent("foo ", 2, "", true)).hasToString("foo "); + assertThat(replaceIndent(" \t foo", 2, "", true)).hasToString("foo"); + assertThat(replaceIndent(" foo\n bar", 2, "", true)).hasToString("foo\nbar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "", true)).hasToString("foo\nbar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "", true)).hasToString("foo\nbar"); + assertThat(replaceIndent("\tfoo\n\t\tbar", 2, "", true)).hasToString("foo\n\tbar"); + assertThat(replaceIndent("\tfoo\n \tbar", 2, "", true)).hasToString("foo\n\tbar"); + + assertThat(replaceIndent(" foo\r\n bar", 2, "", true)).hasToString("foo\r\nbar"); + assertThat(replaceIndent(" foo\r\n\tbar", 2, "", true)).hasToString("foo\r\nbar"); + assertThat(replaceIndent(" foo\r\n\tbar", 2, "", true)).hasToString("foo\r\nbar"); + assertThat(replaceIndent("\tfoo\r\n\t\tbar", 2, "", true)).hasToString("foo\r\n\tbar"); + assertThat(replaceIndent("\tfoo\r\n \tbar", 2, "", true)).hasToString("foo\r\n\tbar"); + + assertThat(replaceIndent("\t\t", 2, "..", true)).hasToString(".."); + assertThat(replaceIndent("foo ", 2, "..", true)).hasToString("..foo "); + assertThat(replaceIndent(" \t foo", 2, "..", true)).hasToString("..foo"); + assertThat(replaceIndent(" foo\n bar", 2, "..", true)).hasToString("..foo\n..bar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "..", true)).hasToString("..foo\n..bar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "..", true)).hasToString("..foo\n..bar"); + assertThat(replaceIndent("\tfoo\n\t\tbar", 2, "..", true)).hasToString("..foo\n..\tbar"); + assertThat(replaceIndent("\tfoo\n \tbar", 2, "..", true)).hasToString("..foo\n..\tbar"); + + assertThat(replaceIndent("\n", 2, "..", true)).hasToString("..\n"); + assertThat(replaceIndent("\n\n", 2, "..", true)).hasToString("..\n..\n"); + assertThat(replaceIndent("\tfoo\n\tbar\n", 2, "..", true)).hasToString("..foo\n..bar\n"); + + assertThat(replaceIndent("\r\n", 2, "..", true)).hasToString("..\r\n"); + assertThat(replaceIndent("\r\n\r\n", 2, "..", true)).hasToString("..\r\n..\r\n"); + assertThat(replaceIndent("\tfoo\r\n\tbar\r\n", 2, "..", true)).hasToString("..foo\r\n..bar\r\n"); } @Test void testReplaceIndent_DoNotIndentEmptyLines() { - assertEquals("", replaceIndent("\t\t", 2, "", false).toString()); - assertEquals("foo ", replaceIndent("foo ", 2, "", false).toString()); - assertEquals("foo", replaceIndent(" \t foo", 2, "", false).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n bar", 2, "", false).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n\tbar", 2, "", false).toString()); - assertEquals("foo\nbar", replaceIndent(" foo\n\tbar", 2, "", false).toString()); - assertEquals("foo\n\tbar", replaceIndent("\tfoo\n\t\tbar", 2, "", false).toString()); - assertEquals("foo\n\tbar", replaceIndent("\tfoo\n \tbar", 2, "", false).toString()); - - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n bar", 2, "", false).toString()); - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n\tbar", 2, "", false).toString()); - assertEquals("foo\r\nbar", replaceIndent(" foo\r\n\tbar", 2, "", false).toString()); - assertEquals("foo\r\n\tbar", replaceIndent("\tfoo\r\n\t\tbar", 2, "", false).toString()); - assertEquals("foo\r\n\tbar", replaceIndent("\tfoo\r\n \tbar", 2, "", false).toString()); - - assertEquals("", replaceIndent("\t\t", 2, "..", false).toString()); - assertEquals("..foo ", replaceIndent("foo ", 2, "..", false).toString()); - assertEquals("..foo", replaceIndent(" \t foo", 2, "..", false).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n bar", 2, "..", false).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n\tbar", 2, "..", false).toString()); - assertEquals("..foo\n..bar", replaceIndent(" foo\n\tbar", 2, "..", false).toString()); - assertEquals("..foo\n..\tbar", replaceIndent("\tfoo\n\t\tbar", 2, "..", false).toString()); - assertEquals("..foo\n..\tbar", replaceIndent("\tfoo\n \tbar", 2, "..", false).toString()); - - assertEquals("\n", replaceIndent("\n", 2, "..", false).toString()); - assertEquals("\n\n", replaceIndent("\n\n", 2, "..", false).toString()); - assertEquals("..foo\n..bar\n", replaceIndent("\tfoo\n\tbar\n", 2, "..", false).toString()); - - assertEquals("\r\n", replaceIndent("\r\n", 2, "..", false).toString()); - assertEquals("\r\n\r\n", replaceIndent("\r\n\r\n", 2, "..", false).toString()); - assertEquals("..foo\r\n..bar\r\n", replaceIndent("\tfoo\r\n\tbar\r\n", 2, "..", false).toString()); + assertThat(replaceIndent("\t\t", 2, "", false)).hasToString(""); + assertThat(replaceIndent("foo ", 2, "", false)).hasToString("foo "); + assertThat(replaceIndent(" \t foo", 2, "", false)).hasToString("foo"); + assertThat(replaceIndent(" foo\n bar", 2, "", false)).hasToString("foo\nbar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "", false)).hasToString("foo\nbar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "", false)).hasToString("foo\nbar"); + assertThat(replaceIndent("\tfoo\n\t\tbar", 2, "", false)).hasToString("foo\n\tbar"); + assertThat(replaceIndent("\tfoo\n \tbar", 2, "", false)).hasToString("foo\n\tbar"); + + assertThat(replaceIndent(" foo\r\n bar", 2, "", false)).hasToString("foo\r\nbar"); + assertThat(replaceIndent(" foo\r\n\tbar", 2, "", false)).hasToString("foo\r\nbar"); + assertThat(replaceIndent(" foo\r\n\tbar", 2, "", false)).hasToString("foo\r\nbar"); + assertThat(replaceIndent("\tfoo\r\n\t\tbar", 2, "", false)).hasToString("foo\r\n\tbar"); + assertThat(replaceIndent("\tfoo\r\n \tbar", 2, "", false)).hasToString("foo\r\n\tbar"); + + assertThat(replaceIndent("\t\t", 2, "..", false)).hasToString(""); + assertThat(replaceIndent("foo ", 2, "..", false)).hasToString("..foo "); + assertThat(replaceIndent(" \t foo", 2, "..", false)).hasToString("..foo"); + assertThat(replaceIndent(" foo\n bar", 2, "..", false)).hasToString("..foo\n..bar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "..", false)).hasToString("..foo\n..bar"); + assertThat(replaceIndent(" foo\n\tbar", 2, "..", false)).hasToString("..foo\n..bar"); + assertThat(replaceIndent("\tfoo\n\t\tbar", 2, "..", false)).hasToString("..foo\n..\tbar"); + assertThat(replaceIndent("\tfoo\n \tbar", 2, "..", false)).hasToString("..foo\n..\tbar"); + + assertThat(replaceIndent("\n", 2, "..", false)).hasToString("\n"); + assertThat(replaceIndent("\n\n", 2, "..", false)).hasToString("\n\n"); + assertThat(replaceIndent("\tfoo\n\tbar\n", 2, "..", false)).hasToString("..foo\n..bar\n"); + + assertThat(replaceIndent("\r\n", 2, "..", false)).hasToString("\r\n"); + assertThat(replaceIndent("\r\n\r\n", 2, "..", false)).hasToString("\r\n\r\n"); + assertThat(replaceIndent("\tfoo\r\n\tbar\r\n", 2, "..", false)).hasToString("..foo\r\n..bar\r\n"); } } diff --git a/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF index 134c5ccde..7c05243c9 100644 --- a/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.jface.text, org.eclipse.ui.tests.harness, org.eclipse.tm4e.core, org.eclipse.tm4e.registry, - org.eclipse.tm4e.ui + org.eclipse.tm4e.ui, + assertj-core Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy Import-Package: org.junit.jupiter.api, diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/RegistryTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/RegistryTest.java index d5b585eb3..ba6578238 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/RegistryTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/RegistryTest.java @@ -11,11 +11,12 @@ */ package org.eclipse.tm4e.ui.tests; +import static org.assertj.core.api.Assertions.assertThat; + import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.tm4e.core.grammar.IGrammar; import org.eclipse.tm4e.registry.TMEclipseRegistryPlugin; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class RegistryTest { @@ -24,13 +25,13 @@ class RegistryTest { void testGrammarRegistered() { final IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.tm4e.ui.tests.testContentType"); final IGrammar grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentType); - Assertions.assertNotNull(grammar); + assertThat(grammar).isNotNull(); } @Test void testThemeAppliesToSubtypes() { final IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.tm4e.ui.tests.testContentType.child"); final IGrammar grammar = TMEclipseRegistryPlugin.getGrammarRegistryManager().getGrammarFor(contentType); - Assertions.assertNotNull(grammar); + assertThat(grammar).isNotNull(); } } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java index 6fc816fbb..14bf5256c 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.ui.tests; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -63,10 +63,10 @@ void colorizeTypescript() { editor = new TMEditor(grammar, theme, "let a = '';\nlet b = 10;\nlet c = true;"); final List commands = editor.execute(); - assertEquals(1, commands.size()); + assertThat(commands).hasSize(1); - final ICommand command = commands.get(0); - assertEquals("[" + final ICommand command0 = commands.get(0); + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -91,8 +91,7 @@ void colorizeTypescript() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command.getStyleRanges()); + + "]"); } @Test @@ -101,11 +100,11 @@ void colorizeTypescriptWithInvalidate1() { editor.invalidateTextPresentation(0, 3); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); // document.set("let a = '';\nlet b = 10;\nlet c = true;"); final ICommand command0 = commands.get(0); - assertEquals("[" + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -130,15 +129,13 @@ void colorizeTypescriptWithInvalidate1() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); + + "]"); // viewer.invalidateTextPresentation(0, 3); final ICommand command1 = commands.get(1); - assertEquals("[" + assertThat(command1.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); + + "]"); } @Test @@ -147,11 +144,11 @@ void colorizeTypescriptWithInvalidate2() { editor.invalidateTextPresentation(0, 2); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); // document.set("let a = '';\nlet b = 10;\nlet c = true;"); final ICommand command0 = commands.get(0); - assertEquals("[" + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -176,15 +173,13 @@ void colorizeTypescriptWithInvalidate2() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); + + "]"); // viewer.invalidateTextPresentation(0, 2); final ICommand command1 = commands.get(1); - assertEquals("[" + assertThat(command1.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); + + "]"); } @Test @@ -193,11 +188,11 @@ void colorizeTypescriptWithInvalidate3() { editor.invalidateTextPresentation(1, 2); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); // document.set("let a = '';\nlet b = 10;\nlet c = true;"); - final ICommand Command0 = commands.get(0); - assertEquals("[" + final ICommand command0 = commands.get(0); + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -222,15 +217,13 @@ void colorizeTypescriptWithInvalidate3() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - Command0.getStyleRanges()); + + "]"); // viewer.invalidateTextPresentation(1, 2); final ICommand command1 = commands.get(1); - assertEquals("[" + assertThat(command1.getStyleRanges()).isEqualTo("[" + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); + + "]"); } @Test @@ -239,11 +232,11 @@ void colorizeTypescriptWithInvalidate4() { editor.invalidateTextPresentation(1, 1); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); // document.set("let a = '';\nlet b = 10;\nlet c = true;"); final ICommand command0 = commands.get(0); - assertEquals("[" + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -268,15 +261,13 @@ void colorizeTypescriptWithInvalidate4() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); + + "]"); // viewer.invalidateTextPresentation(1, 1); final ICommand command1 = commands.get(1); - assertEquals("[" + assertThat(command1.getStyleRanges()).isEqualTo("[" + "StyleRange {1, 1, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); + + "]"); } @Disabled @@ -286,11 +277,11 @@ void colorizeTypescriptWithInvalidate8() { editor.invalidateTextPresentation(1, 8); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); // document.set("let a = '';\nlet b = 10;\nlet c = true;"); final ICommand command0 = commands.get(0); - assertEquals("[" + assertThat(command0.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=bold, foreground=Color {7, 54, 66, 255}}, " + "StyleRange {3, 1, fontStyle=normal}, " + "StyleRange {4, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " @@ -315,15 +306,13 @@ void colorizeTypescriptWithInvalidate8() { + "StyleRange {31, 1, fontStyle=normal}, " + "StyleRange {32, 4, fontStyle=normal, foreground=Color {181, 137, 0, 255}}, " + "StyleRange {36, 1, fontStyle=normal}" - + "]", - command0.getStyleRanges()); + + "]"); //viewer.invalidateTextPresentation(1, 8); final ICommand command1 = commands.get(1); - assertEquals("[" + assertThat(command1.getStyleRanges()).isEqualTo("[" + "StyleRange {1, 2, fontStyle=bold, foreground=Color {7, 54, 66, 255}}" - + "]", - command1.getStyleRanges()); + + "]"); } @Test @@ -332,15 +321,14 @@ void colorizeTypescriptWithInvalidateAndSeveralLines() { editor.invalidateTextPresentation(0, 6); final List commands = editor.execute(); - assertEquals(2, commands.size()); + assertThat(commands).hasSize(2); for (final ICommand command : commands) { - assertEquals("[" + assertThat(command.getStyleRanges()).isEqualTo("[" + "StyleRange {0, 3, fontStyle=normal, foreground=Color {38, 139, 210, 255}}, " + "StyleRange {3, 2, fontStyle=normal}, " + "StyleRange {5, 1, fontStyle=normal, foreground=Color {38, 139, 210, 255}}" - + "]", - command.getStyleRanges()); + + "]"); } } } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMinGenericEditorTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMinGenericEditorTest.java index ad130e1c4..70e194312 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMinGenericEditorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMinGenericEditorTest.java @@ -11,8 +11,6 @@ */ package org.eclipse.tm4e.ui.tests; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.FileOutputStream; import org.eclipse.swt.custom.StyledText; @@ -54,7 +52,7 @@ void testTMHighlightInGenericEditor() throws Exception { editor = IDE.openEditor(UI.getActivePage(), f.toURI(), genericEditorDescr.getId(), true); final var text = (StyledText) editor.getAdapter(Control.class); - assertTrue(TestUtils.waitForCondition(3_000, () -> text.getStyleRanges().length > 1)); + TestUtils.waitForAndAssertCondition(3_000, () -> text.getStyleRanges().length > 1); } @Test diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java index efab7649d..088ebe408 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java @@ -13,7 +13,7 @@ */ package org.eclipse.tm4e.ui.tests.internal.model; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.nio.file.Path; import java.util.ArrayList; @@ -41,8 +41,8 @@ @TestMethodOrder(MethodOrderer.MethodName.class) class TMDocumentModelTest { - interface ThrowingRunnable { - void run() throws Throwable; + interface ThrowingRunnable { + void run() throws Throwable; } private static final String LF = "\n"; @@ -61,12 +61,12 @@ static void beforeAll() { private final TMDocumentModel model = new TMDocumentModel(doc); private void assertDocHasLines(final Iterable lines) { - assertEquals(String.join(LF, lines), doc.get()); - assertEquals(model.getDocument().getNumberOfLines(), model.getNumberOfLines()); + assertThat(doc.get()).isEqualTo(String.join(LF, lines)); + assertThat(model.getNumberOfLines()).isEqualTo(model.getDocument().getNumberOfLines()); } private void assertRange(final ModelTokensChangedEvent e, final int startLineNumber, final int endLineNumber) { - assertEquals(List.of(new Range(startLineNumber, endLineNumber)), e.ranges); + assertThat(e.ranges).containsOnly(new Range(startLineNumber, endLineNumber)); } private ModelTokensChangedEvent awaitModelChangedEvent(final TMDocumentModel model, final List initialLines, @@ -78,12 +78,12 @@ private ModelTokensChangedEvent awaitModelChangedEvent(final TMDocumentModel mod final ModelTokensChangedEvent.Listener listener = e -> signal.countDown(); model.addModelTokensChangedListener(listener); model.getDocument().set(String.join(LF, initialLines)); - assertTrue(signal.await(2, TimeUnit.SECONDS)); + assertThat(signal.await(2, TimeUnit.SECONDS)).isTrue(); Thread.sleep(TestUtils.isCI() ? 500 : 50); model.removeModelTokensChangedListener(listener); } - assertEquals(model.getDocument().getNumberOfLines(), model.getNumberOfLines()); + assertThat(model.getNumberOfLines()).isEqualTo(model.getDocument().getNumberOfLines()); // test final var event = new AtomicReference(); @@ -94,7 +94,7 @@ private ModelTokensChangedEvent awaitModelChangedEvent(final TMDocumentModel mod }; model.addModelTokensChangedListener(listener); action.run(); - assertTrue(signal.await(2, TimeUnit.SECONDS)); + assertThat(signal.await(2, TimeUnit.SECONDS)).isTrue(); model.removeModelTokensChangedListener(listener); return event.get(); } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/themes/TMTokenProviderTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/themes/TMTokenProviderTest.java index 6906a4c97..d63392b69 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/themes/TMTokenProviderTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/themes/TMTokenProviderTest.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.tm4e.ui.tests.internal.themes; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.nio.file.Files; @@ -35,76 +35,67 @@ void testTMPlistTheme() throws Exception { .newInputStream(Path.of("../org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/QuietLight.tmTheme"))) { final var theme = new TMThemeTokenProvider(ContentType.XML, in); - assertEquals(colors.getColor(RGB.fromHex("#333333")), theme.getEditorForeground()); - assertEquals(colors.getColor(RGB.fromHex("#F5F5F5")), theme.getEditorBackground()); - assertEquals(colors.getColor(RGB.fromHex("#E4F6D4")), theme.getEditorCurrentLineHighlight()); - assertEquals(null, theme.getEditorSelectionForeground()); - assertEquals(colors.getColor(RGB.fromHex("#C9D0D9")), theme.getEditorSelectionBackground()); - - if (theme.getToken("comment").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#AAAAAA")), attrs.getForeground()); - assertEquals(SWT.ITALIC, attrs.getStyle() | SWT.ITALIC); - } else { - fail(); - } - - if (theme.getToken("punctuation.definition.comment").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#AAAAAA")), attrs.getForeground()); - assertEquals(SWT.ITALIC, attrs.getStyle() | SWT.ITALIC); - } else { - fail(); - } - - if (theme.getToken("keyword").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#4B83CD")), attrs.getForeground()); - } else { - fail(); - } - - if (theme.getToken("keyword.operator").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#777777")), attrs.getForeground()); - } else { - fail(); - } + assertThat(theme.getEditorForeground()).isEqualTo(colors.getColor(RGB.fromHex("#333333"))); + assertThat(theme.getEditorBackground()).isEqualTo(colors.getColor(RGB.fromHex("#F5F5F5"))); + assertThat(theme.getEditorCurrentLineHighlight()).isEqualTo(colors.getColor(RGB.fromHex("#E4F6D4"))); + assertThat(theme.getEditorSelectionForeground()).isNull(); + assertThat(theme.getEditorSelectionBackground()).isEqualTo(colors.getColor(RGB.fromHex("#C9D0D9"))); + + var token = theme.getToken("comment").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + var attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#AAAAAA"))); + assertThat(attrs.getStyle() | SWT.ITALIC).isEqualTo(SWT.ITALIC); + + token = theme.getToken("punctuation.definition.comment").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#AAAAAA"))); + assertThat(attrs.getStyle() | SWT.ITALIC).isEqualTo(SWT.ITALIC); + + token = theme.getToken("keyword").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#4B83CD"))); + + token = theme.getToken("keyword.operator").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#777777"))); } } @Test void testTMJsonTheme() throws Exception { - try (var in = Files - .newInputStream(Path.of("../org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_vs.json"))) { + try (var in = Files.newInputStream(Path.of("../org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes/dark_vs.json"))) { final var theme = new TMThemeTokenProvider(ContentType.JSON, in); - assertEquals(colors.getColor(RGB.fromHex("#D4D4D4")), theme.getEditorForeground()); - assertEquals(colors.getColor(RGB.fromHex("#1E1E1E")), theme.getEditorBackground()); - assertEquals(null, theme.getEditorCurrentLineHighlight()); - assertEquals(null, theme.getEditorSelectionForeground()); - assertEquals(null, theme.getEditorSelectionBackground()); - - if (theme.getToken("comment").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#608B4E")), attrs.getForeground()); - assertEquals(SWT.ITALIC, attrs.getStyle() | SWT.ITALIC); - } else { - fail(); - } - - if (theme.getToken("keyword").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#569CD6")), attrs.getForeground()); - } else { - fail(); - } - - if (theme.getToken("keyword.operator").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#D4D4D4")), attrs.getForeground()); - } else { - fail(); - } - - if (theme.getToken("keyword.operator.expression").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#569CD6")), attrs.getForeground()); - } else { - fail(); - } + assertThat(theme.getEditorForeground()).isEqualTo(colors.getColor(RGB.fromHex("#D4D4D4"))); + assertThat(theme.getEditorBackground()).isEqualTo(colors.getColor(RGB.fromHex("#1E1E1E"))); + assertThat(theme.getEditorCurrentLineHighlight()).isNull(); + assertThat(theme.getEditorSelectionForeground()).isNull(); + assertThat(theme.getEditorSelectionBackground()).isNull(); + + var token = theme.getToken("comment").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + var attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#608B4E"))); + assertThat(attrs.getStyle() | SWT.ITALIC).isEqualTo(SWT.ITALIC); + + token = theme.getToken("keyword").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#569CD6"))); + + token = theme.getToken("keyword.operator").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#D4D4D4"))); + + token = theme.getToken("keyword.operator.expression").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#569CD6"))); } } @@ -137,35 +128,33 @@ void testVSCodeJsonTheme() throws Exception { } ], "colors": { - "editor.foreground": "#FFFFFF", - "editor.background": "#000000", - "editor.selectionForeground": "#EEEEEE", - "editor.selectionBackground": "#333333", - "editor.lineHighlightBackground": "#999999" + "editor.foreground": "#FFFFFF", + "editor.background": "#000000", + "editor.selectionForeground": "#EEEEEE", + "editor.selectionBackground": "#333333", + "editor.lineHighlightBackground": "#999999" }, "semanticHighlighting": true } """.getBytes())) { final var theme = new TMThemeTokenProvider(ContentType.JSON, in); - assertEquals(colors.getColor(RGB.fromHex("#FFFFFF")), theme.getEditorForeground()); - assertEquals(colors.getColor(RGB.fromHex("#000000")), theme.getEditorBackground()); - assertEquals(colors.getColor(RGB.fromHex("#999999")), theme.getEditorCurrentLineHighlight()); - assertEquals(colors.getColor(RGB.fromHex("#EEEEEE")), theme.getEditorSelectionForeground()); - - assertEquals(colors.getColor(RGB.fromHex("#333333")), theme.getEditorSelectionBackground()); - if (theme.getToken("comment").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#FF0000")), attrs.getForeground()); - assertEquals(SWT.ITALIC, attrs.getStyle() | SWT.ITALIC); - } else { - fail(); - } - - if (theme.getToken("keyword").getData() instanceof TextAttribute attrs) { - assertEquals(colors.getColor(RGB.fromHex("#00FF00")), attrs.getForeground()); - } else { - fail(); - } + assertThat(theme.getEditorForeground()).isEqualTo(colors.getColor(RGB.fromHex("#FFFFFF"))); + assertThat(theme.getEditorBackground()).isEqualTo(colors.getColor(RGB.fromHex("#000000"))); + assertThat(theme.getEditorCurrentLineHighlight()).isEqualTo(colors.getColor(RGB.fromHex("#999999"))); + assertThat(theme.getEditorSelectionForeground()).isEqualTo(colors.getColor(RGB.fromHex("#EEEEEE"))); + assertThat(theme.getEditorSelectionBackground()).isEqualTo(colors.getColor(RGB.fromHex("#333333"))); + + var token = theme.getToken("comment").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + var attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#FF0000"))); + assertThat(attrs.getStyle()).isEqualTo(SWT.ITALIC); + + token = theme.getToken("keyword").getData(); + assertThat(token).isInstanceOf(TextAttribute.class); + attrs = (TextAttribute) token; + assertThat(attrs.getForeground()).isEqualTo(colors.getColor(RGB.fromHex("#00FF00"))); } } } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java index 0514099fe..13765a215 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java @@ -12,7 +12,7 @@ package org.eclipse.tm4e.ui.tests.internal.utils; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -61,39 +61,39 @@ public void setUp() throws CoreException { public void testAvailable() throws IOException { document.set(TEST_ASCII); try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); - assertEquals(TEST_ASCII.length(), is.available()); + assertThat(is.getCharset()).isEqualTo(UTF_8); + assertThat(is.available()).isEqualTo(TEST_ASCII.length()); final var buffer = new byte[4]; is.read(buffer); - assertEquals(TEST_ASCII.length() - 4, is.available()); + assertThat(is.available()).isEqualTo(TEST_ASCII.length() - 4); is.readAllBytes(); - assertEquals(0, is.available()); + assertThat(is.available()).isZero(); } document.set(TEST_UNICODE); try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); - assertTrue(is.available() > 0); + assertThat(is.getCharset()).isEqualTo(UTF_8); + assertThat(is.available()).isGreaterThan(0); is.read(new byte[10]); - assertTrue(is.available() > 0); + assertThat(is.available()).isGreaterThan(0); is.readAllBytes(); - assertEquals(0, is.available()); + assertThat(is.available()).isZero(); } } @Test public void testEndOfStream() throws IOException { try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); is.skip(Long.MAX_VALUE); - assertEquals(-1, is.read()); + assertThat(is.read()).isEqualTo(-1); } } @Test public void testReadEachByte() throws IOException { try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); final var bytesRead = new ArrayList(); int b; while ((b = is.read()) != -1) { @@ -104,7 +104,7 @@ public void testReadEachByte() throws IOException { for (int i = 0; i < bytesRead.size(); i++) { byteArray[i] = bytesRead.get(i); } - assertEquals(TEST_UNICODE, new String(byteArray, UTF_8)); + assertThat(new String(byteArray, UTF_8)).isEqualTo(TEST_UNICODE); } } @@ -113,25 +113,25 @@ public void testReadIntoByteArray() throws IOException { final var buffer = new byte[1024]; // Buffer to read a portion of the text try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); final int bytesRead = is.read(buffer, 0, buffer.length); - assertEquals(TEST_UNICODE, new String(buffer, 0, bytesRead, UTF_8)); + assertThat(new String(buffer, 0, bytesRead, UTF_8)).isEqualTo(TEST_UNICODE); } } @Test public void testSkip() throws IOException { try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); // skip emoji final long skipped = is.skip(EMOJI_BYTES_LEN); - assertEquals(EMOJI_BYTES_LEN, skipped); + assertThat(skipped).isEqualTo(EMOJI_BYTES_LEN); final var japanese = new byte[TEST_UNICODE_BYTES_LEN]; final int bytesRead = is.read(japanese); - assertEquals(JAPANESE, new String(japanese, 0, bytesRead, UTF_8)); + assertThat(new String(japanese, 0, bytesRead, UTF_8)).isEqualTo(JAPANESE); } } @@ -139,12 +139,12 @@ public void testSkip() throws IOException { public void testHighSurrogateAtEndOfInput() throws IOException { document.set(new String(new char[] { 'A', '\uD800' })); // valid char followed by an isolated high surrogate try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); final byte[] result = is.readAllBytes(); final var output = new String(result, UTF_8); // the high surrogate at the end should be replaced by the Unicode replacement char - assertEquals("A" + CharsInputStream.UNICODE_REPLACEMENT_CHAR, output); + assertThat(output).isEqualTo("A" + CharsInputStream.UNICODE_REPLACEMENT_CHAR); } } @@ -152,12 +152,12 @@ public void testHighSurrogateAtEndOfInput() throws IOException { public void testHighSurrogateWithoutLowSurrogate() throws IOException { document.set(new String(new char[] { '\uD800', 'A' })); // \uD800 is a high surrogate, followed by 'A' try (var is = new DocumentInputStream(document)) { - assertEquals(UTF_8, is.getCharset()); + assertThat(is.getCharset()).isEqualTo(UTF_8); final byte[] result = is.readAllBytes(); final var output = new String(result, UTF_8); // the invalid surrogate pair should be replaced by the Unicode replacement char - assertEquals(CharsInputStream.UNICODE_REPLACEMENT_CHAR + "A", output); + assertThat(output).isEqualTo(CharsInputStream.UNICODE_REPLACEMENT_CHAR + "A"); } } } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java index 6e5dc33c1..195f5671c 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java @@ -13,7 +13,7 @@ */ package org.eclipse.tm4e.ui.tests.support; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; import java.io.File; import java.io.IOException; @@ -39,7 +39,7 @@ public interface Condition { public static IEditorDescriptor assertHasGenericEditor() { final var genericEditorDescr = PlatformUI.getWorkbench().getEditorRegistry() .findEditor("org.eclipse.ui.genericeditor.GenericEditor"); - assertNotNull(genericEditorDescr); + assertThat(genericEditorDescr).isNotNull(); return genericEditorDescr; } @@ -130,7 +130,7 @@ protected boolean condition() { } throw new AssertionError(errorMessage, ex.get()); } - assertTrue(isConditionMet, errorMessage); + assertThat(isConditionMet).as(errorMessage).isTrue(); } public static boolean waitForCondition(final int timeout_ms, final Condition condition) { diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/TMEditorColorTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/TMEditorColorTest.java index 812c1df3e..c5517cf02 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/TMEditorColorTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/TMEditorColorTest.java @@ -11,7 +11,7 @@ */ package org.eclipse.tm4e.ui.tests.themes; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -67,16 +67,29 @@ void systemDefaultEditorColorTest() throws IOException, PartInitException { final String themeId = manager.getDefaultTheme().getId(); final ITheme theme = manager.getThemeById(themeId); - assertEquals(SolarizedLight, themeId, "Default light theme isn't set"); - assertEquals(theme.getEditorBackground(), styledText.getBackground(), "Background colors isn't equals"); - assertEquals(theme.getEditorForeground(), styledText.getForeground(), "Foreground colors isn't equals"); - assertNull(theme.getEditorSelectionBackground(), "System default selection background should be null"); - assertNull(theme.getEditorSelectionForeground(), "System default selection foreground should be null"); - final Color eclipseLineHighlight = ColorManager.getInstance().getPreferenceEditorColor(EDITOR_CURRENTLINE_HIGHLIGHT); + assertThat(themeId).as("Default light theme isn't set").isEqualTo(SolarizedLight); + assertThat(styledText.getBackground()) + .as("Background colors aren't equal") + .isEqualTo(theme.getEditorBackground()); + assertThat(styledText.getForeground()) + .as("Foreground colors aren't equal") + .isEqualTo(theme.getEditorForeground()); + assertThat(theme.getEditorSelectionBackground()) + .as("System default selection background should be null") + .isNull(); + assertThat(theme.getEditorSelectionForeground()) + .as("System default selection foreground should be null") + .isNull(); + + final Color eclipseLineHighlight = ColorManager.getInstance() + .getPreferenceEditorColor(EDITOR_CURRENTLINE_HIGHLIGHT); final Color themeLineHighlight = theme.getEditorCurrentLineHighlight(); - assertNotNull(themeLineHighlight, "Highlight shouldn't be a null"); - assertNotEquals(eclipseLineHighlight, themeLineHighlight, "Default Line highlight should be from TM theme"); + + assertThat(themeLineHighlight).as("Highlight shouldn't be null").isNotNull(); + assertThat(themeLineHighlight) + .as("Default Line highlight should be from TM theme") + .isNotEqualTo(eclipseLineHighlight); } @Test @@ -98,16 +111,28 @@ void userDefinedEditorColorTest() throws Exception { final String themeId = manager.getDefaultTheme().getId(); final ITheme theme = manager.getThemeById(themeId); - assertEquals(SolarizedLight, themeId, "Default light theme isn't set"); - - assertEquals(styledText.getBackground(), testColor, "Background color should be user defined"); - assertEquals(theme.getEditorForeground(), styledText.getForeground(), "Foreground colors should be "); - assertEquals(theme.getEditorSelectionBackground(), testColor, "Selection background color should be user defined"); - assertNull(theme.getEditorSelectionForeground(), "Selection foreground should be System default (null)"); - final Color lineHighlight = ColorManager.getInstance().getPreferenceEditorColor(EDITOR_CURRENTLINE_HIGHLIGHT); - assertNotNull(lineHighlight, "Highlight shouldn't be a null"); - assertEquals(lineHighlight, theme.getEditorCurrentLineHighlight(), - "Line highlight should be from preferences (because of user defined background)"); + assertThat(themeId).as("Default light theme isn't set").isEqualTo(SolarizedLight); + + assertThat(styledText.getBackground()) + .as("Background color should be user defined") + .isEqualTo(testColor); + assertThat(styledText.getForeground()) + .as("Foreground colors should be user defined") + .isEqualTo(theme.getEditorForeground()); + assertThat(theme.getEditorSelectionBackground()) + .as("Selection background color should be user defined") + .isEqualTo(testColor); + assertThat(theme.getEditorSelectionForeground()) + .as("Selection foreground should be system default (null)") + .isNull(); + + final Color lineHighlight = ColorManager.getInstance() + .getPreferenceEditorColor(EDITOR_CURRENTLINE_HIGHLIGHT); + + assertThat(lineHighlight).as("Highlight shouldn't be null").isNotNull(); + assertThat(lineHighlight) + .as("Line highlight should be from preferences (because of user-defined background)") + .isEqualTo(theme.getEditorCurrentLineHighlight()); } } diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/ThemeManagerTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/ThemeManagerTest.java index b3d3cd30a..29e6eb2d7 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/ThemeManagerTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/themes/ThemeManagerTest.java @@ -11,9 +11,7 @@ */ package org.eclipse.tm4e.ui.tests.themes; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.stream.Stream; +import static org.assertj.core.api.Assertions.assertThat; import org.eclipse.tm4e.ui.TMUIPlugin; import org.eclipse.tm4e.ui.themes.ITheme; @@ -31,21 +29,21 @@ class ThemeManagerTest implements ThemeIdConstants { @Test void testDefaultThemeAssociation() { final ITheme theme = manager.getDefaultTheme(); - assertEquals(SolarizedLight, theme.getId()); + assertThat(theme.getId()).isEqualTo(SolarizedLight); } @Test void testAllThemesAreRegistered() { // All Dark themes final ITheme[] darkThemes = manager.getThemes(true); - assertTrue(Stream.of(darkThemes).anyMatch(t -> t.getId().equals(Dark))); - assertTrue(Stream.of(darkThemes).anyMatch(t -> t.getId().equals(Monokai))); + assertThat(darkThemes).anyMatch(t -> t.getId().equals(Dark)); + assertThat(darkThemes).anyMatch(t -> t.getId().equals(Monokai)); // All themes for Other E4 CSS Theme final ITheme[] lightThemes = manager.getThemes(false); - assertTrue(Stream.of(lightThemes).anyMatch(t -> t.getId().equals(Light))); - assertTrue(Stream.of(lightThemes).anyMatch(t -> t.getId().equals(EclipseLight))); - assertTrue(Stream.of(lightThemes).anyMatch(t -> t.getId().equals(SolarizedLight))); - assertTrue(Stream.of(lightThemes).anyMatch(t -> t.getId().equals(WtpXmlClassic))); + assertThat(lightThemes).anyMatch(t -> t.getId().equals(Light)); + assertThat(lightThemes).anyMatch(t -> t.getId().equals(EclipseLight)); + assertThat(lightThemes).anyMatch(t -> t.getId().equals(SolarizedLight)); + assertThat(lightThemes).anyMatch(t -> t.getId().equals(WtpXmlClassic)); } } diff --git a/org.eclipse.tm4e.ui/build.properties b/org.eclipse.tm4e.ui/build.properties index 1e12b71d7..bc0babe3e 100644 --- a/org.eclipse.tm4e.ui/build.properties +++ b/org.eclipse.tm4e.ui/build.properties @@ -10,4 +10,4 @@ bin.includes = META-INF/,\ about.html # JDT Null Analysis for Eclipse -additional.bundles = org.eclipse.jdt.annotation +additional.bundles = org.eclipse.jdt.annotation,assertj-core diff --git a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModelTest.java b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModelTest.java index d9a81a0a2..a1acd873a 100644 --- a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModelTest.java +++ b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/model/TMDocumentModelTest.java @@ -11,9 +11,8 @@ */ package org.eclipse.tm4e.ui.internal.model; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tm4e.core.registry.IGrammarSource.fromString; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.eclipse.jface.text.Document; import org.eclipse.tm4e.core.registry.IGrammarSource.ContentType; import org.eclipse.tm4e.core.registry.Registry; @@ -34,14 +33,14 @@ void testMultiLineChange() throws InterruptedException { }); Thread.sleep(300); - assertEquals(1, tmModel.getNumberOfLines()); + assertThat(tmModel.getNumberOfLines()).isEqualTo(1); document.set("a\nb\nc\nd"); Thread.sleep(300); - assertEquals(4, tmModel.getNumberOfLines()); + assertThat(tmModel.getNumberOfLines()).isEqualTo(4); document.set("a\nb"); Thread.sleep(300); - assertEquals(2, tmModel.getNumberOfLines()); + assertThat(tmModel.getNumberOfLines()).isEqualTo(2); } } diff --git a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelperTest.java b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelperTest.java index 99b12183e..2d25aebac 100644 --- a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelperTest.java +++ b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/preferences/PreferenceHelperTest.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.tm4e.ui.internal.preferences; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import org.eclipse.tm4e.ui.internal.utils.MarkerConfig; import org.junit.jupiter.api.Test; @@ -23,6 +23,6 @@ class PreferenceHelperTest { void testMarkerConfigsSerialization() { final var defaults = MarkerConfig.getDefaults(); final var defaultsAsJson = PreferenceHelper.toJsonMarkerConfigs(defaults); - assertEquals(defaults, PreferenceHelper.loadMarkerConfigs(defaultsAsJson)); + assertThat(PreferenceHelper.loadMarkerConfigs(defaultsAsJson)).isEqualTo(defaults); } } diff --git a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/utils/CharsInputStreamTest.java b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/utils/CharsInputStreamTest.java index 055a53cf8..ad7276234 100644 --- a/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/utils/CharsInputStreamTest.java +++ b/org.eclipse.tm4e.ui/src/test/java/org/eclipse/tm4e/ui/internal/utils/CharsInputStreamTest.java @@ -12,14 +12,14 @@ package org.eclipse.tm4e.ui.internal.utils; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.util.ArrayList; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class CharsInputStreamTest { +class CharsInputStreamTest { private static final String TEST_ASCII = "Hello, World!"; @@ -30,35 +30,35 @@ public class CharsInputStreamTest { private static final int TEST_UNICODE_BYTES_LEN = TEST_UNICODE.getBytes(UTF_8).length; @Test - public void testAvailable() throws IOException { + void testAvailable() throws IOException { try (var is = new CharsInputStream(TEST_ASCII)) { - assertEquals(TEST_ASCII.length(), is.available()); + assertThat(is.available()).isEqualTo(TEST_ASCII.length()); final var buffer = new byte[4]; is.read(buffer); - assertEquals(TEST_ASCII.length() - 4, is.available()); + assertThat(is.available()).isEqualTo(TEST_ASCII.length() - 4); is.readAllBytes(); - assertEquals(0, is.available()); + assertThat(is.available()).isZero(); } try (var is = new CharsInputStream(TEST_UNICODE)) { - assertTrue(is.available() > 0); + assertThat(is.available()).isPositive(); is.read(new byte[10]); - assertTrue(is.available() > 0); + assertThat(is.available()).isPositive(); is.readAllBytes(); - assertEquals(0, is.available()); + assertThat(is.available()).isZero(); } } @Test - public void testEndOfStream() throws IOException { + void testEndOfStream() throws IOException { try (var is = new CharsInputStream(TEST_UNICODE)) { is.skip(Long.MAX_VALUE); - assertEquals(-1, is.read()); + assertThat(is.read()).isEqualTo(-1); } } @Test - public void testReadEachByte() throws IOException { + void testReadEachByte() throws IOException { try (var is = new CharsInputStream(TEST_UNICODE)) { final var bytesRead = new ArrayList(); int b; @@ -70,57 +70,57 @@ public void testReadEachByte() throws IOException { for (int i = 0; i < bytesRead.size(); i++) { byteArray[i] = bytesRead.get(i); } - assertEquals(TEST_UNICODE, new String(byteArray, UTF_8)); + assertThat(new String(byteArray, UTF_8)).isEqualTo(TEST_UNICODE); } } @Test - public void testReadIntoByteArray() throws IOException { + void testReadIntoByteArray() throws IOException { final var buffer = new byte[1024]; // Buffer to read a portion of the text try (var is = new CharsInputStream(TEST_UNICODE)) { final int bytesRead = is.read(buffer, 0, buffer.length); - assertEquals(TEST_UNICODE_BYTES_LEN, bytesRead); - assertEquals(TEST_UNICODE, new String(buffer, 0, bytesRead, UTF_8)); + assertThat(bytesRead).isEqualTo(TEST_UNICODE_BYTES_LEN); + assertThat(new String(buffer, 0, bytesRead, UTF_8)).isEqualTo(TEST_UNICODE); } } @Test - public void testSkip() throws IOException { + void testSkip() throws IOException { try (var is = new CharsInputStream(TEST_UNICODE)) { // skip emoji final long skipped = is.skip(EMOJI_BYTES_LEN); - assertEquals(EMOJI_BYTES_LEN, skipped); + assertThat(skipped).isEqualTo(EMOJI_BYTES_LEN); final var japanese = new byte[TEST_UNICODE_BYTES_LEN]; final int bytesRead = is.read(japanese); - assertEquals(JAPANESE, new String(japanese, 0, bytesRead, UTF_8)); + assertThat(new String(japanese, 0, bytesRead, UTF_8)).isEqualTo(JAPANESE); } } @Test - public void testHighSurrogateAtEndOfInput() throws IOException { + void testHighSurrogateAtEndOfInput() throws IOException { final char[] invalidSequence = { 'A', '\uD800' }; // valid char followed by an isolated high surrogate try (var is = new CharsInputStream(new String(invalidSequence), UTF_8)) { final byte[] result = is.readAllBytes(); final var output = new String(result, UTF_8); // the high surrogate at the end should be replaced by the Unicode replacement char - assertEquals("A" + CharsInputStream.UNICODE_REPLACEMENT_CHAR, output); + assertThat(output).isEqualTo("A" + CharsInputStream.UNICODE_REPLACEMENT_CHAR); } } @Test - public void testHighSurrogateWithoutLowSurrogate() throws IOException { + void testHighSurrogateWithoutLowSurrogate() throws IOException { final char[] invalidSequence = { '\uD800', 'A' }; // \uD800 is a high surrogate, followed by 'A' try (var is = new CharsInputStream(new String(invalidSequence), UTF_8)) { final byte[] result = is.readAllBytes(); final var output = new String(result, UTF_8); // the invalid surrogate pair should be replaced by the Unicode replacement char - assertEquals(CharsInputStream.UNICODE_REPLACEMENT_CHAR + "A", output); + assertThat(output).isEqualTo(CharsInputStream.UNICODE_REPLACEMENT_CHAR + "A"); } } } diff --git a/target-platforms/latest.target b/target-platforms/latest.target index b48d04eb0..be0167c03 100644 --- a/target-platforms/latest.target +++ b/target-platforms/latest.target @@ -34,6 +34,17 @@ + + + + + org.assertj + assertj-core + 3.27.3 + jar + + + diff --git a/target-platforms/oldest.target b/target-platforms/oldest.target index 9d4b45944..ef22d6ab5 100644 --- a/target-platforms/oldest.target +++ b/target-platforms/oldest.target @@ -32,8 +32,14 @@ - + + + org.assertj + assertj-core + 3.27.3 + jar + org.snakeyaml snakeyaml-engine diff --git a/target-platforms/unstable.target b/target-platforms/unstable.target index a6f167896..e792d8d61 100644 --- a/target-platforms/unstable.target +++ b/target-platforms/unstable.target @@ -34,6 +34,17 @@ + + + + + org.assertj + assertj-core + 3.27.3 + jar + + +