Search in sources :

Example 1 with StaticAnalysisWarningEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method sets_line_number_for_generated_warning.

@Test
public void sets_line_number_for_generated_warning() throws Exception {
    List<StaticAnalysisWarningEvent> generatedEvents = processMarkerAndReturnGeneratedWarningList(() -> {
        try {
            IMarker marker = this.testFile.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.MESSAGE, "This warning does not exist");
            marker.setAttribute(IMarker.LINE_NUMBER, 15);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    });
    assertEquals(generatedEvents.size(), 1);
    assertEquals(generatedEvents.get(0).warning.lineNumber, 15);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 2 with StaticAnalysisWarningEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method correctly_classifies_checkstyle_warning_type.

@Test
public void correctly_classifies_checkstyle_warning_type() throws Exception {
    List<StaticAnalysisWarningEvent> generatedEvents = processMarkerAndReturnGeneratedWarningList(() -> {
        try {
            IMarker marker = this.testFile.createMarker(EclipseMarkupModelListener.CHECKSTYLE_MARKER_ID);
            marker.setAttribute(IMarker.MESSAGE, "Using the '.*' form of import should be avoided - java.util.*.");
        } catch (CoreException e) {
            e.printStackTrace();
        }
    });
    assertEquals(generatedEvents.size(), 1);
    assertEquals(generatedEvents.get(0).warning.type, "checkstyle.imports.import.avoidStar");
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 3 with StaticAnalysisWarningEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method correctly_classifies_warning_type_for_creating_a_new_marker.

@Test
public void correctly_classifies_warning_type_for_creating_a_new_marker() throws Exception {
    List<StaticAnalysisWarningEvent> generatedEvents = processMarkerAndReturnGeneratedWarningList(() -> {
        try {
            IMarker marker = this.testFile.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.MESSAGE, "Duplicate tag for parameter");
        } catch (CoreException e) {
            e.printStackTrace();
        }
    });
    assertEquals(generatedEvents.size(), 1);
    // See explanation in the previous test why this is 474
    assertEquals(generatedEvents.get(0).warning.type, "474");
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 4 with StaticAnalysisWarningEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method non_existing_warning_should_not_match_any_type.

@Test
public void non_existing_warning_should_not_match_any_type() throws Exception {
    List<StaticAnalysisWarningEvent> generatedEvents = processMarkerAndReturnGeneratedWarningList(() -> {
        try {
            IMarker marker = this.testFile.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.MESSAGE, "This warning does not exist");
        } catch (CoreException e) {
            e.printStackTrace();
        }
    });
    assertEquals(generatedEvents.size(), 1);
    assertEquals(generatedEvents.get(0).warning.type, "unknown");
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) IMarker(org.eclipse.core.resources.IMarker) Test(org.junit.Test)

Example 5 with StaticAnalysisWarningEvent

use of nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent in project watchdog by TestRoots.

the class MarkupModelListenerTest method setup.

@Before
public void setup() throws Exception {
    WatchDogEventType.intervalManager = Mockito.mock(IntervalManager.class);
    WatchDogEventType.editorSpecificImplementation = Mockito.mock(WatchDogEventEditorSpecificImplementation.class);
    this.transferManager = Mockito.mock(TransferManager.class);
    this.trackingEventManager = Mockito.mock(TrackingEventManager.class);
    this.generatedEvents = new ArrayList<>();
    Mockito.doAnswer(new Answer<Object>() {

        @SuppressWarnings("unchecked")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Stream<StaticAnalysisWarningEvent> stream = (Stream<StaticAnalysisWarningEvent>) invocation.getArguments()[0];
            stream.map(StaticAnalysisWarningEvent::getType).forEach(generatedEvents::add);
            return null;
        }
    }).when(this.trackingEventManager).addEvents(Mockito.any());
    this.setUpTestingProject();
    this.workbenchListener = new WorkbenchListener(trackingEventManager, transferManager);
    this.workbenchListener.attachListeners();
}
Also used : TransferManager(nl.tudelft.watchdog.eclipse.logic.network.TransferManager) WorkbenchListener(nl.tudelft.watchdog.eclipse.logic.ui.listeners.WorkbenchListener) TrackingEventManager(nl.tudelft.watchdog.core.logic.event.TrackingEventManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) IntervalManager(nl.tudelft.watchdog.eclipse.logic.interval.IntervalManager) WatchDogEventEditorSpecificImplementation(nl.tudelft.watchdog.core.logic.ui.events.WatchDogEventType.WatchDogEventEditorSpecificImplementation) Before(org.junit.Before)

Aggregations

StaticAnalysisWarningEvent (nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent)7 Test (org.junit.Test)6 IMarker (org.eclipse.core.resources.IMarker)5 CoreException (org.eclipse.core.runtime.CoreException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Stream (java.util.stream.Stream)1 Document (nl.tudelft.watchdog.core.logic.document.Document)1 TrackingEventManager (nl.tudelft.watchdog.core.logic.event.TrackingEventManager)1 WatchDogEventEditorSpecificImplementation (nl.tudelft.watchdog.core.logic.ui.events.WatchDogEventType.WatchDogEventEditorSpecificImplementation)1 IntervalManager (nl.tudelft.watchdog.eclipse.logic.interval.IntervalManager)1 TransferManager (nl.tudelft.watchdog.eclipse.logic.network.TransferManager)1 WorkbenchListener (nl.tudelft.watchdog.eclipse.logic.ui.listeners.WorkbenchListener)1 PartInitException (org.eclipse.ui.PartInitException)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1