Skip to content

Commit

Permalink
Fix PMD Warning JUnitAssertionsShouldIncludeMessage (dsldevkit#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras authored Nov 9, 2023
1 parent e135fd3 commit fb64f19
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.Collection;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.eclipse.xtext.testing.XtextRunner;
import org.junit.Assert;
import org.junit.Ignore;
Expand Down Expand Up @@ -186,7 +186,7 @@ protected void runChild(final FrameworkMethod method, final RunNotifier notifier
ensureInitialized();
final boolean ignored = method.getAnnotation(Ignore.class) != null;
if (!ignored) {
Assert.assertEquals(expectedMethods.get(currentMethodIndex++), method);
Assert.assertEquals("Method " + method.getName() + " not equal", expectedMethods.get(currentMethodIndex++), method); //$NON-NLS-1$//$NON-NLS-2$
}
if (ignored || testRuns == 1 && testRetries == 0 && method.getAnnotation(Retry.class) == null) {
super.runChild(method, notifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected final void assertPreservedParseTreeConstructor() {
*/
private void assertFormattedParseTreeConstructor(final EObject model, final String expected) {
String actual = getXtextTestUtil().getSerializer().serialize(model, SaveOptions.newBuilder().format().getOptions());
Assert.assertEquals(expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
Assert.assertEquals("Formatted ParseTree", expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
}

/**
Expand All @@ -166,8 +166,7 @@ private void assertFormattedNodeModel(final EObject model, final String input, f
ICompositeNode node = NodeModelUtils.getNode(model).getRootNode();
IFormattedRegion region = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
String actual = input.substring(0, offset) + region.getFormattedText() + input.substring(length + offset);
Assert.assertEquals(expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
Assert.assertEquals("Formatted NodeModel", expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public String apply(final ICompletionProposal from) {
protected void assertContentAssist(final List<String> contentassistProposals, final int offset) {
evaluateCompletionProposals(offset);
Arrays.sort(getCompletionProposals(), new TemplatesFirstCompletionProposalComparator());
Assert.assertEquals(contentassistProposals.size(), getCompletionProposals().length);
Assert.assertEquals("Same length", contentassistProposals.size(), getCompletionProposals().length);
for (int i = 0; i < contentassistProposals.size(); i++) {
Assert.assertEquals(contentassistProposals.get(i), getCompletionProposals()[i].getDisplayString());
Assert.assertEquals("Same displayed string", contentassistProposals.get(i), getCompletionProposals()[i].getDisplayString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
public abstract class AbstractHyperlinkHelperTest extends AbstractXtextEditorTest {

private static final String OFFSET_MUST_BE_EQUAL = "Offset must be equal";
private static final String NUMBER_OF_HYPERLINKS_MUST_BE_EQUAL = "Number of hyperlinks must be equal";
/** The Constant LEAF_NOT_FOUND_VALUE is returned when a leaf node is not found. */
protected static final int LEAF_NOT_FOUND_VALUE = -1;

Expand All @@ -51,7 +53,7 @@ public abstract class AbstractHyperlinkHelperTest extends AbstractXtextEditorTes
* the position at which to look for a hyperlink
*/
protected void assertOffsetHasHyperlink(final int offset) {
Assert.assertEquals(1, getOffsetHyperlinks(offset).size());
Assert.assertEquals(OFFSET_MUST_BE_EQUAL, 1, getOffsetHyperlinks(offset).size());
}

/**
Expand All @@ -61,7 +63,7 @@ protected void assertOffsetHasHyperlink(final int offset) {
* the position at which to look for hyperlinks
*/
protected void assertOffsetHasNoHyperlink(final int offset) {
Assert.assertEquals(0, getOffsetHyperlinks(offset).size());
Assert.assertEquals(OFFSET_MUST_BE_EQUAL, 0, getOffsetHyperlinks(offset).size());
}

/**
Expand Down Expand Up @@ -93,7 +95,7 @@ protected void assertNoHyperlink(final int tag) {
* number of expected hyperlinks
*/
protected void assertHasHyperlinks(final int tag, final int numberOfHyperlinks) {
Assert.assertEquals(numberOfHyperlinks, getHyperlinks(tag).size());
Assert.assertEquals(NUMBER_OF_HYPERLINKS_MUST_BE_EQUAL, numberOfHyperlinks, getHyperlinks(tag).size());
}

/**
Expand All @@ -111,7 +113,7 @@ protected void assertHasHyperlinks(final int tag, final URI target) {
actualTargets.add(((XtextHyperlink) hyperlink).getURI());
}
}
MatcherAssert.assertThat(actualTargets, CoreMatchers.hasItem(target));
MatcherAssert.assertThat("The target must have items", actualTargets, CoreMatchers.hasItem(target));
}

/**
Expand All @@ -125,7 +127,7 @@ protected void assertHasHyperlinks(final int tag, final URI target) {
* number of expected hyperlinks
*/
protected void assertHasHyperlinks(final XtextResource resource, final int tag, final int numberOfHyperlinks) {
Assert.assertEquals(numberOfHyperlinks, getHyperlinks(resource, tag).size());
Assert.assertEquals(NUMBER_OF_HYPERLINKS_MUST_BE_EQUAL, numberOfHyperlinks, getHyperlinks(resource, tag).size());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ protected ISerializer getSerializer() {
protected void assertFormattedPTC(final String expected, final String model) throws IOException {
EObject m = getModel(model);
String res = getSerializer().serialize(m, SaveOptions.newBuilder().format().getOptions());
Assert.assertEquals(expected, res);
Assert.assertEquals("Serialization not equal", expected, res);
}

protected void assertPreserved(final String model) throws IOException {
EObject m = getModel(model);
String res = getSerializer().serialize(m, SaveOptions.newBuilder().getOptions());
Assert.assertEquals(model, res);
Assert.assertEquals("Preserved node model", model, res);
}

// test formatting based on the NodeModel
protected void assertFormattedNM(final String expected, final String model, final int offset, final int length) throws IOException {
ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
IFormattedRegion r = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
Assert.assertEquals(expected, actual);
Assert.assertEquals("Formatting based on the NodeModel", expected, actual);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void linewrapDefault() {
m.getItems().add(d);
String actual = getSerializer().serialize(m, SaveOptions.newBuilder().format().getOptions());
String expected = "test wrapminmax\n\n\nxxx yyy;";
Assert.assertEquals(expected, actual);
Assert.assertEquals("Default Linewrap", expected, actual);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Assert;
import org.junit.Test;


/**
* Tests for {@code AbstractFragmentProvider}.
*/
Expand Down Expand Up @@ -67,7 +68,7 @@ public void testUnescapeEscape() {
for (String text : SPECIAL_ESCAPE_CASES) {
StringBuilder builder = new StringBuilder();
fragmentProvider.appendEscaped(text, builder);
Assert.assertEquals(text, fragmentProvider.unescape(builder.toString()));
Assert.assertEquals("Escaped Characters must be equal", text, fragmentProvider.unescape(builder.toString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
*/
public class ShortFragmentProviderTest extends AbstractTest {

private static AbstractTestUtil testUtil = new AbstractTestUtil() {};
private static final String FRAGMENT_MUST_BE_EQUAL = "Fragment must be equal";
private static AbstractTestUtil testUtil = new AbstractTestUtil() {
};

private static final class TestFallbackFragmentProvider implements IFragmentProvider.Fallback {

Expand Down Expand Up @@ -98,9 +100,9 @@ public void testLongFragment() {
resource.getContents().add(root);

String fragment = fragmentProvider.getFragment(parent, fragmentFallback);
Assert.assertEquals("/0*" + (reps + 1), fragment);
Assert.assertEquals(FRAGMENT_MUST_BE_EQUAL, "/0*" + (reps + 1), fragment);

Assert.assertEquals(parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
Assert.assertEquals(FRAGMENT_MUST_BE_EQUAL, parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
}

@Test
Expand All @@ -122,9 +124,9 @@ public void testLongFragment2() {
resource.getContents().add(root);

String fragment = fragmentProvider.getFragment(parent, fragmentFallback);
Assert.assertEquals("/0*" + (reps + 1) + "/1", fragment);
Assert.assertEquals(FRAGMENT_MUST_BE_EQUAL, "/0*" + (reps + 1) + "/1", fragment);

Assert.assertEquals(parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
Assert.assertEquals(FRAGMENT_MUST_BE_EQUAL, parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
}

@Override
Expand Down

0 comments on commit fb64f19

Please sign in to comment.