Permalink
Browse files

Plugin.java: Use commons-exec to run coala-json

  • Loading branch information...
arafsheikh committed May 31, 2016
1 parent 60dc1b1 commit cb97a57e07bb60e745500c9b95ae285d18832604
@@ -23,48 +23,48 @@
public class MarkerTest extends TestCase {
private IProject project;
private Plugin plugin;
private RemoveMarkers removeMarkers;
private IFile file;
@Before
public void setUp() throws Exception {
String data = "package test_proj;\n\npublic class newClass {\n\n}";
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
project = root.getProject("com.test_proj");
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
file = project.getFile("test.java");
if (!file.exists()) {
byte[] bytes = data.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
file.create(source, IResource.NONE, null);
}
plugin = new Plugin();
removeMarkers = new RemoveMarkers();
}
@After
public void tearDown() throws CoreException {
project.close(null);
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
project.delete(true, true, null);
}
ResourcesPlugin.getWorkspace().save(true, null);
}
private IProject project;
private Plugin plugin;
private RemoveMarkers removeMarkers;
private IFile file;
@Test
public void test() throws IOException, CoreException, ExecutionException {
removeMarkers.removeAllMarkers(file);
plugin.createCoolMarker(file, 0, 0, "First marker");
plugin.createCoolMarker(file, 0, 0, "Second marker");
IMarker[] markers = file.findMarkers("com.coala.core.coolproblem", true, IResource.DEPTH_INFINITE);
assertEquals(markers.length, 2);
}
@Before
public void setUp() throws Exception {
String data = "package test_proj;\n\npublic class newClass {\n\n}";
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
project = root.getProject(TestUtils.generateRandomStr(5));
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
file = project.getFile("test.java");
if (!file.exists()) {
byte[] bytes = data.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
file.create(source, IResource.NONE, null);
}
plugin = new Plugin();
removeMarkers = new RemoveMarkers();
}
@Test
public void test() throws IOException, CoreException, ExecutionException {
removeMarkers.removeAllMarkers(file);
plugin.createCoolMarker(file, 0, 0, "First marker");
plugin.createCoolMarker(file, 0, 0, "Second marker");
IMarker[] markers = file.findMarkers("com.coala.core.coolproblem", true,
IResource.DEPTH_INFINITE);
assertEquals(markers.length, 2);
}
@After
public void tearDown() throws CoreException {
if (project.isOpen()) {
project.close(null);
}
project.delete(true, true, null);
ResourcesPlugin.getWorkspace().save(true, null);
}
}
@@ -1,11 +1,13 @@
package com.coala.core.tests;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import org.apache.commons.exec.ExecuteException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -21,58 +23,59 @@
import com.coala.core.handlers.RemoveMarkers;
public class RunCmdTest {
private IProject project;
private Plugin plugin;
private RemoveMarkers removeMarkers;
private IFile file;
@Before
public void setUp() throws Exception {
String data = "package test_proj;\n\npublic class newClass {\n\n}";
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
project = root.getProject("com.test_proj");
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
file = project.getFile("test.java");
if (!file.exists()) {
byte[] bytes = data.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
file.create(source, IResource.NONE, null);
}
plugin = new Plugin();
removeMarkers = new RemoveMarkers();
}
private IProject project;
private Plugin plugin;
private RemoveMarkers removeMarkers;
private IFile file;
@After
public void tearDown() throws Exception {
project.close(null);
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
project.delete(true, true, null);
}
ResourcesPlugin.getWorkspace().save(true, null);
}
@Before
public void setUp() throws Exception {
String data = "package test_proj;\n\npublic class newClass {\n\n}";
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
project = root.getProject(TestUtils.generateRandomStr(5));
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
file = project.getFile("test.java");
if (!file.exists()) {
byte[] bytes = data.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
file.create(source, IResource.NONE, null);
}
plugin = new Plugin();
removeMarkers = new RemoveMarkers();
}
@Test
public void test() throws InterruptedException, CoreException {
removeMarkers.removeAllMarkers(file);
plugin.runcoalaOnFile(file, "CheckstyleBear");
sleep(5);
IMarker[] markers = file.findMarkers("com.coala.core.coolproblem", true, IResource.DEPTH_INFINITE);
assertEquals(markers.length, 3);
}
private void sleep(int seconds) {
try {
TimeUnit.SECONDS.sleep(seconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test
public void test() throws InterruptedException, CoreException,
ExecuteException, IOException {
removeMarkers.removeAllMarkers(file);
plugin.runcoalaOnFile(file, "CheckstyleBear");
sleep(15);
IMarker[] markers = file.findMarkers("com.coala.core.coolproblem", true,
IResource.DEPTH_INFINITE);
assertEquals(markers.length, 3);
}
@After
public void tearDown() throws Exception {
if (project.isOpen()) {
project.close(null);
}
project.delete(true, true, null);
ResourcesPlugin.getWorkspace().save(true, null);
}
private void sleep(int seconds) {
try {
TimeUnit.SECONDS.sleep(seconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,18 @@
package com.coala.core.tests;
import java.util.Random;
public class TestUtils {
public static String generateRandomStr(int length) {
String candidateChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.append(candidateChars
.charAt(random.nextInt(candidateChars.length())));
}
return sb.toString();
}
}
Oops, something went wrong.

0 comments on commit cb97a57

Please sign in to comment.