use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class MarkerUtilTest method addMarkerWithUnknwonPositionInformation.
/**
* Verifies that {@link MarkerUtil#addMarker(IFile, String, RuleViolation)} adds a marker to the provided file with
* position information set to zero if the respective arguments are negative.
*/
@Test
public void addMarkerWithUnknwonPositionInformation() throws CoreException {
final IFile file = mock(IFile.class);
final IMarker marker = mock(IMarker.class);
when(file.createMarker(MARKER_TYPE)).thenReturn(marker);
final RuleViolation violation = mock(RuleViolation.class);
when(violation.getDescription()).thenReturn("message");
when(violation.getBeginLine()).thenReturn(-1);
when(violation.getBeginColumn()).thenReturn(-18);
when(violation.getEndLine()).thenReturn(-1);
when(violation.getEndColumn()).thenReturn(-24);
when(violation.getClassName()).thenReturn("ClassName");
final Rule rule = mock(Rule.class);
when(rule.getLanguage()).thenReturn(new JavaLanguageModule());
when(rule.getRuleSetName()).thenReturn("basic");
when(rule.getName()).thenReturn("ExtendsObject");
when(violation.getRule()).thenReturn(rule);
final IMarker actual = MarkerUtil.addMarker(file, "class A extends Object {}", violation);
assertNotNull("The method must always return a marker", actual);
verify(file).createMarker(MARKER_TYPE);
verify(actual).setAttribute(IMarker.MESSAGE, "message");
verify(actual).setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
verify(actual).setAttribute(IMarker.LINE_NUMBER, 0);
verify(actual).setAttribute(IMarker.CHAR_START, 0);
verify(actual).setAttribute(IMarker.CHAR_END, 0);
verify(actual).setAttribute("ruleId", "java.basic.ExtendsObject");
verify(actual).setAttribute("violationClassName", "ClassName");
verify(actual).setAttribute("markerText", "");
}
use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class MarkerUtilTest method addMarkerWithTab.
/**
* Verifies that {@link MarkerUtil#addMarker(IFile, String, RuleViolation)} adds a marker to the provided file with
* the correct position if the content contains tabs and spaces.
*/
@Test
public void addMarkerWithTab() throws CoreException {
final IFile file = mock(IFile.class);
final IMarker marker = mock(IMarker.class);
when(file.createMarker(MARKER_TYPE)).thenReturn(marker);
final RuleViolation violation = mock(RuleViolation.class);
when(violation.getDescription()).thenReturn("message");
when(violation.getBeginLine()).thenReturn(1);
when(violation.getBeginColumn()).thenReturn(25);
when(violation.getEndLine()).thenReturn(1);
when(violation.getEndColumn()).thenReturn(30);
when(violation.getClassName()).thenReturn("ClassName");
final Rule rule = mock(Rule.class);
when(rule.getLanguage()).thenReturn(new JavaLanguageModule());
when(rule.getRuleSetName()).thenReturn("basic");
when(rule.getName()).thenReturn("ExtendsObject");
when(violation.getRule()).thenReturn(rule);
final IMarker actual = MarkerUtil.addMarker(file, "class ABC extends\tObject {}", violation);
assertNotNull("The method must always return a marker", actual);
verify(file).createMarker(MARKER_TYPE);
verify(actual).setAttribute(IMarker.MESSAGE, "message");
verify(actual).setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
verify(actual).setAttribute(IMarker.LINE_NUMBER, 1);
verify(actual).setAttribute(IMarker.CHAR_START, 18);
verify(actual).setAttribute(IMarker.CHAR_END, 24);
verify(actual).setAttribute("ruleId", "java.basic.ExtendsObject");
verify(actual).setAttribute("violationClassName", "ClassName");
verify(actual).setAttribute("markerText", "Object");
}
use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class WrappingPMDMarkerTest method setLanguage.
/**
* Verifies that {@link WrappingPMDMarker#setLanguage(String)} sets the language on the wrapped marker.
*/
@Test
public void setLanguage() throws CoreException {
final IMarker marker = mock(IMarker.class);
final WrappingPMDMarker pmdMarker = new WrappingPMDMarker(marker);
final String expected = "java";
pmdMarker.setLanguage(expected);
verify(marker).setAttribute("language", expected);
}
use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class WrappingPMDMarkerTest method setRuleId.
/**
* Verifies that {@link WrappingPMDMarker#setRuleId(String)} sets the rule id on the wrapped marker.
*/
@Test
public void setRuleId() throws CoreException {
final IMarker marker = mock(IMarker.class);
final WrappingPMDMarker pmdMarker = new WrappingPMDMarker(marker);
final String expected = "Rule D";
pmdMarker.setRuleId(expected);
verify(marker).setAttribute(RULE_ID, expected);
}
use of org.eclipse.core.resources.IMarker in project eclipse-pmd by acanda.
the class WrappingPMDMarkerTest method isOtherWithSameRuleId.
/**
* Verifies that {@link WrappingPMDMarker#isOtherWithSameRuleId(IMarker)} returns true if the argument is not the same
* instance but has the same rule id.
*/
@Test
public void isOtherWithSameRuleId() {
final IMarker marker = mock(IMarker.class);
final String ruleId = "Rule A";
when(marker.getAttribute(eq(RULE_ID), isA(String.class))).thenReturn(ruleId);
final WrappingPMDMarker pmdMarker = new WrappingPMDMarker(marker);
final IMarker other = mock(IMarker.class);
when(other.getAttribute(eq(RULE_ID), isA(String.class))).thenReturn(ruleId);
final boolean actual = pmdMarker.isOtherWithSameRuleId(other);
assertTrue("The marker must not be the same instance as the other marker", actual);
}
Aggregations