Resolved broken tests.

This commit is contained in:
A Pottinger
2020-04-20 09:11:36 -07:00
parent 3979d9a0ad
commit 45ee436670
16 changed files with 21 additions and 105 deletions

View File

@@ -0,0 +1,85 @@
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.issue.PdePreprocessIssue;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
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());
}
}