mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 20:01:09 +01:00
Consolidate logic for runtime path generation into a single class.
In response to @benfry feedback within https://github.com/processing/processing4/pull/1, consolidated all of the runtime path calculation into a single class while still maintaining all of the tests and caching logic. This reduces the class count but still adapts to jmod and javafx path calculation requirements for java 11.
This commit is contained in:
@@ -18,14 +18,13 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.util.runtime.RuntimePathUtilTest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -36,29 +35,30 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class CachedRuntimePathFactoryTest {
|
||||
|
||||
private CachedRuntimePathFactory cachedRuntimePathFactory;
|
||||
private RuntimePathBuilder.CachedRuntimePathFactory cachedRuntimePathFactory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cachedRuntimePathFactory = new CachedRuntimePathFactory(new RuntimePathFactoryStrategy() {
|
||||
cachedRuntimePathFactory = new RuntimePathBuilder.CachedRuntimePathFactory(
|
||||
new RuntimePathBuilder.RuntimePathFactoryStrategy() {
|
||||
private int calls = 0;
|
||||
|
||||
private int calls = 0;
|
||||
@Override
|
||||
public List<String> buildClasspath(JavaMode mode, List<ImportStatement> imports,
|
||||
Sketch sketch) {
|
||||
|
||||
@Override
|
||||
public List<String> buildClasspath(JavaMode mode, List<ImportStatement> imports,
|
||||
Sketch sketch) {
|
||||
String retVal = String.format("Test%d", calls);
|
||||
calls++;
|
||||
|
||||
String retVal = String.format("Test%d", calls);
|
||||
calls++;
|
||||
|
||||
List<String> retList = new ArrayList<>();
|
||||
retList.add(retVal);
|
||||
return retList;
|
||||
}
|
||||
});
|
||||
List<String> retList = new ArrayList<>();
|
||||
retList.add(retVal);
|
||||
return retList;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
@@ -97,4 +97,4 @@ public class CachedRuntimePathFactoryTest {
|
||||
assertEquals("Test1", classpath.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,23 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.util.RuntimePathFactoryTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CodeFolderRuntimePathFactoryTest {
|
||||
|
||||
private CodeFolderRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -43,7 +43,8 @@ public class CodeFolderRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new CodeFolderRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildCodeFolderPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,22 +18,22 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.util.RuntimePathFactoryTestUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CoreLibraryRuntimePathFactoryTest {
|
||||
|
||||
private CoreLibraryRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -41,7 +41,8 @@ public class CoreLibraryRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new CoreLibraryRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildCoreLibraryPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,14 +18,13 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.util.runtime.RuntimeConst;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,7 +33,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class JavaFxRuntimePathFactoryTest {
|
||||
|
||||
private JavaFxRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -42,7 +41,8 @@ public class JavaFxRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new JavaFxRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildJavaFxRuntimePath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -52,7 +52,7 @@ public class JavaFxRuntimePathFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testBuildClasspathSize() {
|
||||
assertEquals(RuntimeConst.JAVA_FX_JARS.length, classpath.size());
|
||||
assertEquals(RuntimePathBuilder.JAVA_FX_JARS.length, classpath.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -18,16 +18,14 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.util.runtime.RuntimeConst;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -35,7 +33,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class JavaRuntimePathFactoryTest {
|
||||
|
||||
private JavaRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -44,7 +42,8 @@ public class JavaRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new JavaRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildJavaRuntimePath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -54,7 +53,7 @@ public class JavaRuntimePathFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testBuildClasspathSize() {
|
||||
assertEquals(RuntimeConst.STANDARD_MODULES.length, classpath.size());
|
||||
assertEquals(RuntimePathBuilder.STANDARD_MODULES.length, classpath.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -26,14 +26,13 @@ import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LibrarySearchRuntimePathFactoryTest {
|
||||
|
||||
private LibrarySearchRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -42,7 +41,8 @@ public class LibrarySearchRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new LibrarySearchRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildLibrarySearchPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -26,7 +26,6 @@ import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -34,7 +33,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class LibrarySketchRuntimePathFactoryTest {
|
||||
|
||||
private LibrarySketchRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -42,7 +41,8 @@ public class LibrarySketchRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new LibrarySketchRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildLibrarySketchPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -30,9 +30,10 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class ModeSearchRuntimePathFactoryTest {
|
||||
|
||||
private ModeSearchRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -40,7 +41,8 @@ public class ModeSearchRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new ModeSearchRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildModeSearchPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -30,9 +30,10 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class ModeSketchRuntimePathFactoryTest {
|
||||
|
||||
private ModeSketchRuntimePathFactory factory;
|
||||
private RuntimePathBuilder.RuntimePathFactoryStrategy factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
@@ -40,7 +41,8 @@ public class ModeSketchRuntimePathFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = new ModeSketchRuntimePathFactory();
|
||||
RuntimePathBuilder builder = new RuntimePathBuilder();
|
||||
factory = builder::buildModeSketchPath;
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import processing.app.Library;
|
||||
@@ -1,127 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2019 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
import processing.mode.java.pdex.PreprocessedSketch;
|
||||
import processing.mode.java.pdex.util.runtime.strategy.RuntimePathFactoryTestUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class RuntimePathBuilderTest {
|
||||
|
||||
private RuntimePathBuilder builder;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
private PreprocessedSketch.Builder result;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
builder = new RuntimePathBuilder();
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
|
||||
result = new PreprocessedSketch.Builder();
|
||||
result.programImports.addAll(testImports);
|
||||
result.sketch = testSketch;
|
||||
|
||||
builder.prepareClassPath(result, testMode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassPathLoader() {
|
||||
assertNotNull(result.classLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassPathObj() {
|
||||
assertNotNull(result.classPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSketchClassPathStrategiesJava() {
|
||||
checkPresent(result.classPathArray, "java.base.jmod");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSketchClassPathStrategiesLibrary() {
|
||||
checkPresent(result.classPathArray, "library3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSketchClassPathStrategiesCore() {
|
||||
checkPresent(result.classPathArray, "library3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSketchClassPathStrategiesMode() {
|
||||
checkPresent(result.classPathArray, "library6");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSketchClassPathStrategiesCodeFolder() {
|
||||
checkPresent(result.classPathArray, "file1.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchClassPathStrategiesCodeJava() {
|
||||
checkPresent(result.searchClassPathArray, "java.base.jmod");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchClassPathStrategiesCodeMode() {
|
||||
checkPresent(result.classPathArray, "library6");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchClassPathStrategiesCodeLibrary() {
|
||||
checkPresent(result.classPathArray, "library3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchClassPathStrategiesCodeCore() {
|
||||
checkPresent(result.classPathArray, "library1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchClassPathStrategiesCodeCodeFolder() {
|
||||
checkPresent(result.classPathArray, "file3.zip");
|
||||
}
|
||||
|
||||
private void checkPresent(String[] classPathArray, String target) {
|
||||
long count = Arrays.stream(classPathArray)
|
||||
.filter((x) -> x.contains(target))
|
||||
.count();
|
||||
|
||||
assertTrue(count > 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2019 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class RuntimePathUtilTest {
|
||||
|
||||
@Test
|
||||
public void sanitizeClassPath() {
|
||||
StringJoiner testStrJoiner = new StringJoiner(File.pathSeparator);
|
||||
testStrJoiner.add("test1");
|
||||
testStrJoiner.add("");
|
||||
testStrJoiner.add("test2");
|
||||
|
||||
List<String> classPath = RuntimePathUtil.sanitizeClassPath(testStrJoiner.toString());
|
||||
assertEquals(2, classPath.size());
|
||||
assertEquals("test1", classPath.get(0));
|
||||
assertEquals("test2", classPath.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanitizeClassPathNoDuplicate() {
|
||||
StringJoiner testStrJoiner = new StringJoiner(File.pathSeparator);
|
||||
testStrJoiner.add("test1");
|
||||
testStrJoiner.add("");
|
||||
testStrJoiner.add("test2");
|
||||
testStrJoiner.add("test2");
|
||||
|
||||
List<String> classPath = RuntimePathUtil.sanitizeClassPath(testStrJoiner.toString());
|
||||
assertEquals(2, classPath.size());
|
||||
assertEquals("test1", classPath.get(0));
|
||||
assertEquals("test2", classPath.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2019 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex.util.runtime.strategy;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ImportStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class RuntimePathFactoryStrategyCollectionTest {
|
||||
|
||||
private RuntimePathFactoryStrategyCollection factory;
|
||||
private JavaMode testMode;
|
||||
private List<ImportStatement> testImports;
|
||||
private Sketch testSketch;
|
||||
private List<String> classpath;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
List<RuntimePathFactoryStrategy> innerFactories = new ArrayList<>();
|
||||
innerFactories.add(createInnerFactory("test1"));
|
||||
innerFactories.add(createInnerFactory("test2"));
|
||||
factory = new RuntimePathFactoryStrategyCollection(innerFactories);
|
||||
|
||||
testMode = RuntimePathFactoryTestUtil.createTestJavaMode();
|
||||
testImports = RuntimePathFactoryTestUtil.createTestImports();
|
||||
testSketch = RuntimePathFactoryTestUtil.createTestSketch();
|
||||
|
||||
classpath = factory.buildClasspath(testMode, testImports, testSketch);
|
||||
}
|
||||
|
||||
private RuntimePathFactoryStrategy createInnerFactory(String retStr) {
|
||||
return (mode, imports, sketch) -> {
|
||||
List<String> retList = new ArrayList<>();
|
||||
retList.add(retStr);
|
||||
return retList;
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildClasspathLength() {
|
||||
assertEquals(2, classpath.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildClasspathContent() {
|
||||
assertEquals("test1", classpath.get(0));
|
||||
assertEquals("test2", classpath.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user