Skip to content

Commit

Permalink
Fix PMD SimplifiableTestAssertion warning (dsldevkit#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenporras authored Nov 9, 2023
1 parent dbb7dc6 commit e135fd3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.avaloq.tools.ddk.xtext.test.contentassist;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;

import java.text.MessageFormat;
Expand Down Expand Up @@ -88,7 +89,7 @@ private String getCompletionProposalDisplayStrings(final ICompletionProposal...
* the expected proposals as display strings
*/
private void assertCompletionProposal(final ICompletionProposal[] computedProposals, final boolean positiveTest, final String... proposals) {
assertFalse(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, proposals.length == 0);
assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, proposals.length, 0);
for (final String s : proposals) {
boolean foundProposal = false;
for (ICompletionProposal p : computedProposals) {
Expand Down Expand Up @@ -153,7 +154,7 @@ protected void assertNotCompletionProposal(final ICompletionProposal[] computedP
* the expected proposals as display strings
*/
protected void assertExactlyCompletionProposal(final ICompletionProposal[] computedProposals, final String... expectedProposals) {
assertFalse(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, expectedProposals.length == 0);
assertNotEquals(AT_LEAST_ONE_PROPOSAL_WAS_PROVIDED, expectedProposals.length, 0);

Set<String> computedProposalsAsSet = new HashSet<String>();
for (ICompletionProposal p : computedProposals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ protected void assertHover(final ENamedElement element, final String firstLine)
*/
protected void assertHoverDoesNotContainText(final ENamedElement element, final String text) {
assertElementExistInHoverMap(element);
Assert.assertTrue("Element '" + element.toString() + "' first line of hover must not have '" + text + "'. " + "\n\nHoverMap contains:\n"
+ getHoverMap().get(element), !hasTextOnFirstLine(getHoverMap().get(element), text));
Assert.assertFalse("Element '" + element.toString() + "' first line of hover must not have '" + text + "'. " + "\n\nHoverMap contains:\n"
+ getHoverMap().get(element), hasTextOnFirstLine(getHoverMap().get(element), text));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected IOutlineNode assertHasOutlineNode(final String nodeName) {
protected IOutlineNode assertHasOutlineNode(final String nodeName, final String nodeType) {
IOutlineTreeProvider provider = getXtextTestUtil().get(IOutlineTreeProvider.class);
IOutlineNode field = findNode(provider.createRoot(getDocument()), nodeName, nodeType);
Assert.assertTrue("Outline must contain element '" + nodeName + "'.", field != null);
Assert.assertNotNull("Outline must contain element '" + nodeName + "'.", field);
return field;
}

Expand All @@ -145,7 +145,7 @@ protected IOutlineNode assertHasOutlineNode(final String nodeName, final String
protected void assertHasOutlineNode(final String nodeName, final String nodeType, final String parentName) {
IOutlineNode field = assertHasOutlineNode(nodeName, nodeType);
IOutlineNode parent = field.getParent();
Assert.assertTrue("The element '" + nodeName + "' doesn't belong to the '" + parentName + "' group.", parentName.equals(parent.getText().toString()));
Assert.assertEquals("The element '" + nodeName + "' doesn't belong to the '" + parentName + "' group.", parentName, parent.getText().toString());
}

/**
Expand Down Expand Up @@ -265,4 +265,3 @@ private void buildOutlineMap(final IOutlineNode node) {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.avaloq.tools.ddk.xtext.test.validation;

import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -936,7 +937,7 @@ private void assertNoDiagnostic(final Diagnostic diagnostics, final String issue
* the diagnostic to check for issues
*/
private void assertNoDiagnostics(final Diagnostic diagnostics) {
assertTrue("Diagnostics should be in OK state.", diagnostics.getCode() == Diagnostic.OK);
assertEquals("Diagnostics should be in OK state.", diagnostics.getCode(), Diagnostic.OK);
assertTrue("There should be no diagnostics. Instead found " + diagnostics.getChildren().size(), diagnostics.getChildren().isEmpty());
}

Expand Down

0 comments on commit e135fd3

Please sign in to comment.