mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
Removed the preproc.issue package by relocating supporting classes for PreprocessIssueMessageSimplifier and PdeIssueEmitter as inner classes. This assists with https://github.com/processing/processing4/issues/10.
84 lines
2.1 KiB
Java
84 lines
2.1 KiB
Java
package processing.mode.java;
|
|
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.mockito.Mockito;
|
|
import processing.app.Problem;
|
|
import processing.app.ui.Editor;
|
|
import processing.mode.java.preproc.PdePreprocessIssue;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ProblemFactoryTest {
|
|
|
|
private PdePreprocessIssue pdePreprocessIssue;
|
|
private List<Integer> tabStarts;
|
|
private Editor editor;
|
|
private List<Integer> starts;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
pdePreprocessIssue = new PdePreprocessIssue(8, 2, "test");
|
|
|
|
tabStarts = new ArrayList<>();
|
|
tabStarts.add(5);
|
|
|
|
editor = Mockito.mock(Editor.class);
|
|
Mockito.when(editor.getLineStartOffset(3)).thenReturn(10);
|
|
Mockito.when(editor.getLineStopOffset(3)).thenReturn(12);
|
|
|
|
starts = new ArrayList<>();
|
|
starts.add(0);
|
|
starts.add(5);
|
|
starts.add(10);
|
|
}
|
|
|
|
@Test
|
|
public void buildWithEditor() {
|
|
Problem problem = ProblemFactory.build(pdePreprocessIssue, tabStarts, 15, editor);
|
|
|
|
Assert.assertEquals(3, problem.getLineNumber());
|
|
Assert.assertEquals("test", problem.getMessage());
|
|
Assert.assertEquals(10, problem.getStartOffset());
|
|
Assert.assertEquals(11, problem.getStopOffset());
|
|
}
|
|
|
|
@Test
|
|
public void buildWithoutEditor() {
|
|
Problem problem = ProblemFactory.build(pdePreprocessIssue, tabStarts);
|
|
|
|
Assert.assertEquals(3, problem.getLineNumber());
|
|
Assert.assertEquals("test", problem.getMessage());
|
|
}
|
|
|
|
@Test
|
|
public void getTabStart() {
|
|
Assert.assertEquals(0, ProblemFactory.getTab(starts, 0).getTab());
|
|
}
|
|
|
|
@Test
|
|
public void getTabMiddleFrontEdge() {
|
|
Assert.assertEquals(1, ProblemFactory.getTab(starts, 5).getTab());
|
|
}
|
|
|
|
@Test
|
|
public void getTabMiddle() {
|
|
TabLine tabLine = ProblemFactory.getTab(starts, 7);
|
|
Assert.assertEquals(1, tabLine.getTab());
|
|
Assert.assertEquals(2, tabLine.getLineInTab());
|
|
}
|
|
|
|
@Test
|
|
public void getTabMiddleBackEdge() {
|
|
Assert.assertEquals(2, ProblemFactory.getTab(starts, 10).getTab());
|
|
}
|
|
|
|
@Test
|
|
public void getTabEnd() {
|
|
Assert.assertEquals(2, ProblemFactory.getTab(starts, 15).getTab());
|
|
}
|
|
|
|
}
|