Search in sources :

Example 6 with Document

use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.

the class MarkupModelListenerTest method correctly_generates_document_information.

@Test
public void correctly_generates_document_information() throws Exception {
    List<StaticAnalysisWarningEvent> generatedWarnings = this.deleteMarkerAndReturnGeneratedWarningList(this.preExistingMarker);
    assertEquals(generatedWarnings.size(), 1);
    Document document = generatedWarnings.get(0).document;
    assertEquals(document.getFileName(), "Existing.java");
    assertEquals(document.getContent().split("\\d+").length, 25);
}
Also used : StaticAnalysisWarningEvent(nl.tudelft.watchdog.core.logic.event.eventtypes.staticanalysis.StaticAnalysisWarningEvent) Document(nl.tudelft.watchdog.core.logic.document.Document) Test(org.junit.Test)

Example 7 with Document

use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.

the class DocumentCreatorTest method testCreateDocument.

/**
 * Tests whether the creation of a Java production class via the
 * {@link DocumentCreator} actually returns said class, and that the
 * document classification returns the correct type.
 */
@Test
public void testCreateDocument() {
    String contents = "public class A {}";
    ITextEditor mockedEditor = mock(ITextEditor.class);
    IDocumentProvider mockedProvider = mock(IDocumentProvider.class);
    org.eclipse.jface.text.IDocument mockedDocument = mock(org.eclipse.jface.text.IDocument.class);
    when(mockedEditor.getDocumentProvider()).thenReturn(mockedProvider);
    when(mockedProvider.getDocument(Mockito.any())).thenReturn(mockedDocument);
    when(mockedDocument.get()).thenReturn(contents);
    when(mockedEditor.getTitle()).thenReturn("A.java");
    Document doc = DocumentCreator.createDocument(mockedEditor);
    assertEquals("A.java", doc.getFileName());
    doc.prepareDocument();
    assertEquals(DocumentType.PRODUCTION, doc.getDocumentType());
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) Document(nl.tudelft.watchdog.core.logic.document.Document) Test(org.junit.Test)

Example 8 with Document

use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testJsonTypingIntervalTwoSameIntervalsRepresentation.

/**
 * Tests the format of the returned Json representation.
 */
@Test
public void testJsonTypingIntervalTwoSameIntervalsRepresentation() {
    ITextEditor editor = Mockito.mock(ITextEditor.class);
    TypingInterval interval = new TypingInterval(new EditorWrapper(editor), new Date());
    interval.setDocument(new Document("Project", "filepath", "Production.java", "blah-document"));
    interval.setEndingDocument(new Document("Project", "Production.java", "filepath", "blah-document"));
    ArrayList<WatchDogItem> intervals = createSampleIntervals(interval);
    assertEquals("[{\"endingDocument\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"90a8834de76326869f3e703cd61513081ad73d3c\",\"sloc\":1,\"dt\":\"pr\"},\"diff\":0,\"modCountDiff\":0,\"charLengthDiff\":0,\"doc\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"90a8834de76326869f3e703cd61513081ad73d3c\",\"sloc\":1,\"dt\":\"pr\"},\"it\":\"ty\",\"ts\":1,\"te\":2,\"ss\":\"\"," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TypingInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval) EditorWrapper(nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper) Document(nl.tudelft.watchdog.core.logic.document.Document) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 9 with Document

use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testJsonTypingIntervalDiffsNoChanges.

@Test
public void testJsonTypingIntervalDiffsNoChanges() {
    ITextEditor editor = Mockito.mock(ITextEditor.class);
    TypingInterval interval = new TypingInterval(new EditorWrapper(editor), new Date(1));
    interval.setDocument(new Document("Project", "filepath", "Production.java", "blah-document"));
    interval.setEndingDocument(new Document("Project", "filepath", "Production.java", "blah-document"));
    interval.close();
    sleepABit();
    ArrayList<WatchDogItem> intervals = new ArrayList<>();
    intervals.add(interval);
    assertEquals("[{\"endingDocument\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"diff\":0,\"modCountDiff\":0,\"charLengthDiff\":0,\"doc\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"it\":\"ty\",\"ts\":1," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TypingInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval) EditorWrapper(nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper) ArrayList(java.util.ArrayList) Document(nl.tudelft.watchdog.core.logic.document.Document) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Example 10 with Document

use of nl.tudelft.watchdog.core.logic.document.Document in project watchdog by TestRoots.

the class IntervalJsonConverterTest method testJsonTypingIntervalDiffsRemoval.

@Test
public void testJsonTypingIntervalDiffsRemoval() {
    ITextEditor editor = Mockito.mock(ITextEditor.class);
    TypingInterval interval = new TypingInterval(new EditorWrapper(editor), new Date(1));
    interval.setDocument(new Document("Project", "filepath", "Production.java", "blah-document"));
    interval.setEndingDocument(new Document("Project", "filepath", "Production.java", "blah-doc"));
    interval.close();
    sleepABit();
    ArrayList<WatchDogItem> intervals = new ArrayList<>();
    intervals.add(interval);
    assertEquals("[{\"endingDocument\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"diff\":5,\"modCountDiff\":0,\"charLengthDiff\":5,\"doc\":{\"pn\":\"f6f4da8d93e88a08220e03b7810451d3ba540a34\",\"fn\":\"e4afa075bb910c8ecb427e9950426a4599b21d7e\",\"sloc\":1,\"dt\":\"un\"},\"it\":\"ty\",\"ts\":1," + pasteWDVAndClient() + "}]", transferer.toJson(intervals));
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TypingInterval(nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval) EditorWrapper(nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper) ArrayList(java.util.ArrayList) Document(nl.tudelft.watchdog.core.logic.document.Document) Date(java.util.Date) WatchDogItem(nl.tudelft.watchdog.core.logic.storage.WatchDogItem) Test(org.junit.Test)

Aggregations

Document (nl.tudelft.watchdog.core.logic.document.Document)13 Test (org.junit.Test)7 WatchDogItem (nl.tudelft.watchdog.core.logic.storage.WatchDogItem)6 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)6 Date (java.util.Date)5 TypingInterval (nl.tudelft.watchdog.core.logic.interval.intervaltypes.TypingInterval)5 EditorWrapper (nl.tudelft.watchdog.eclipse.logic.document.EditorWrapper)5 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)2 IPath (org.eclipse.core.runtime.IPath)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)1 MarkupModelImpl (com.intellij.openapi.editor.impl.MarkupModelImpl)1 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1