diff --git a/cobigen-eclipse/cobigen-eclipse-test/.classpath b/cobigen-eclipse/cobigen-eclipse-test/.classpath
index 8d0ae98bfc..318d6ef9a9 100644
--- a/cobigen-eclipse/cobigen-eclipse-test/.classpath
+++ b/cobigen-eclipse/cobigen-eclipse-test/.classpath
@@ -1,7 +1,5 @@
-
-
@@ -17,7 +15,6 @@
-
@@ -32,5 +29,7 @@
+
+
diff --git a/cobigen-eclipse/cobigen-eclipse-test/build.properties b/cobigen-eclipse/cobigen-eclipse-test/build.properties
index 1943f55c16..4ba969d2da 100644
--- a/cobigen-eclipse/cobigen-eclipse-test/build.properties
+++ b/cobigen-eclipse/cobigen-eclipse-test/build.properties
@@ -11,7 +11,6 @@ bin.includes = .,\
lib/error_prone_annotations.jar,\
lib/failureaccess.jar,\
lib/guava.jar,\
- lib/hamcrest-core.jar,\
lib/j2objc-annotations.jar,\
lib/jcl-over-slf4j.jar,\
lib/jsr305.jar,\
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ClassLoadingTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ClassLoadingTest.java
index 809ca2e83b..b6dd030493 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ClassLoadingTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ClassLoadingTest.java
@@ -1,21 +1,20 @@
package com.devonfw.cobigen.systemtest;
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
-import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.internal.matchers.Any.ANY;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.List;
+import org.hamcrest.Matcher;
import org.junit.Test;
import com.devonfw.cobigen.api.CobiGen;
@@ -27,9 +26,11 @@
import com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher;
import com.devonfw.cobigen.api.to.GenerationReportTo;
import com.devonfw.cobigen.api.to.TemplateTo;
+import com.devonfw.cobigen.api.to.VariableAssignmentTo;
import com.devonfw.cobigen.impl.CobiGenFactory;
import com.devonfw.cobigen.impl.extension.PluginRegistry;
import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
+import com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@@ -72,7 +73,6 @@ public void callClassLoadingTest() throws Exception {
assertThat(report).isSuccessful();
assertThat(generatedFile).exists();
assertThat(generatedFile).isFile().hasSameContentAs(expectedResult);
-
}
@Test
@@ -140,24 +140,27 @@ public String toString() {
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
- .thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
- .thenReturn(true);
+ when(matcher.matches(argThat(
+ new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class), sameInstance(container)))))
+ .thenReturn(false);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), org.hamcrest.CoreMatchers.any(String.class),
+ sameInstance(container))))).thenReturn(true);
// Simulate container children resolution of any plug-in
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
- .thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class),
+ sameInstance(firstChildResource))))).thenReturn(true);
// Simulate variable resolving of any plug-in
- when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
- argThat(hasItemsInList(
- //
- new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
- new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
- any()))
+ Matcher m1 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"),
+ equalTo("1"), equalTo(false));
+ Matcher m2 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"),
+ equalTo("3"), equalTo(false));
+ Matcher> tmp = CustomHamcrestMatchers.hasItemsInList(m1, m2);
+ // IsIterableContaining t1 = new IsIterableContaining<>();
+ when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"),
+ org.hamcrest.CoreMatchers.any(String.class), sameInstance(firstChildResource))), argThat(tmp), any()))
.thenReturn(ImmutableMap. builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ContainerMatcherTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ContainerMatcherTest.java
index dd5245afd5..6390bec629 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ContainerMatcherTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ContainerMatcherTest.java
@@ -2,16 +2,15 @@
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
+import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyList;
-import static org.mockito.Matchers.argThat;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.internal.matchers.Any.ANY;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.File;
import java.nio.charset.Charset;
@@ -20,6 +19,7 @@
import org.junit.Assert;
import org.junit.Test;
+import org.mockito.Mockito;
import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
@@ -251,26 +251,34 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
// Simulate container children resolution of any plug-in
- when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))), anyList(),
- any())).thenReturn(ImmutableMap. builder().put("variable", "child1").build());
- when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))), anyList(),
- any())).thenReturn(ImmutableMap. builder().put("variable", "child2").build());
- when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(child1, child2));
+ when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1))),
+ anyList(), Mockito.any()))
+ .thenReturn(ImmutableMap. builder().put("variable", "child1").build());
+ when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2))),
+ anyList(), Mockito.any()))
+ .thenReturn(ImmutableMap. builder().put("variable", "child2").build());
+ when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
+ .thenReturn(Lists.newArrayList(child1, child2));
// match container
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("container"), ANY, sameInstance(container)))))
- .thenReturn(true);
+ when(matcher
+ .matches(argThat(new MatcherToMatcher(equalTo("container"), any(String.class), sameInstance(container)))))
+ .thenReturn(true);
// do not match first child
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child1))))).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1)))))
+ .thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child1)))))
+ .thenReturn(true);
// match second child
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child2))))).thenReturn(false);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2)))))
+ .thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child2)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -346,10 +354,10 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(container)))))
.thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), any(String.class), sameInstance(container)))))
.thenReturn(true);
// Simulate container children resolution of any plug-in
@@ -361,22 +369,25 @@ public String toString() {
return "child2";
}
};
- when(inputReader.getInputObjects(any(), any(Charset.class)))
+ when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
.thenReturn(Lists.newArrayList(firstChildResource, secondChildResource));
} else {
- when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));
+ when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
+ .thenReturn(Lists.newArrayList(firstChildResource));
}
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
- .thenReturn(containerChildMatchesTrigger);
+ when(matcher
+ .matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource)))))
+ .thenReturn(containerChildMatchesTrigger);
// Simulate variable resolving of any plug-in
- when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
+ when(matcher.resolveVariables(
+ argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource))),
argThat(hasItemsInList(
//
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
- any()))
+ Mockito.any()))
.thenReturn(ImmutableMap. builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java
index 41e08b7c2f..9210ddda36 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java
@@ -3,13 +3,12 @@
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.internal.matchers.Any.ANY;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.File;
import java.io.FileWriter;
@@ -23,6 +22,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
+import org.mockito.Mockito;
import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
@@ -165,13 +165,15 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
// Simulate variable resolving of any plug-in
HashMap variables = new HashMap<>(1);
variables.put("contextVar", "contextValue");
- when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
+ when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
+ .thenReturn(variables);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -218,13 +220,15 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
// Simulate variable resolving of any plug-in
HashMap variables = new HashMap<>(1);
variables.put("contextVar", "contextValue");
- when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
+ when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
+ .thenReturn(variables);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
index 680f7e4b85..4b92561261 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TemplateProcessingTest.java
@@ -1,6 +1,5 @@
package com.devonfw.cobigen.systemtest;
-import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
@@ -8,14 +7,19 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
import com.devonfw.cobigen.api.constants.ConfigurationConstants;
+import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.impl.CobiGenFactory;
import com.devonfw.cobigen.impl.util.ConfigurationFinder;
import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
@@ -34,98 +38,88 @@ public class TemplateProcessingTest extends AbstractApiTest {
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
+ /**
+ * mock the pathObject to use the temporary folder instead of the user folder
+ */
+ private MockedStatic cobigenPaths;
+
/**
* temporary project to store CobiGen home
*/
- File cobiGenHome;
+ Path cobiGenHome;
/**
- * Creates a temporary CobiGen home directory for each test
+ * Creates a temporary CobiGen home directory for each test and create static mock for CobiGenPaths object
*
* @throws IOException if an Exception occurs
*/
@Before
public void prepare() throws IOException {
- this.cobiGenHome = this.tempFolder.newFolder("playground", "templatesHome");
+ this.cobiGenHome = this.tempFolder.newFolder("playground", "templatesHome").toPath();
+
+ this.cobigenPaths = Mockito.mockStatic(CobiGenPaths.class, Mockito.CALLS_REAL_METHODS);
+ this.cobigenPaths.when(() -> CobiGenPaths.getCobiGenHomePath()).thenReturn(this.cobiGenHome);
+
+ }
+
+ /**
+ * cleanup mockito static mock
+ */
+ @After
+ public void cleanup() {
+
+ this.cobigenPaths.close();
}
/**
+ * Tests if template sets can be extracted properly
+ *
* @throws IOException if an Exception occurs
*/
+ @Test
public void extractTemplateSetsTest() throws IOException {
FileUtils.copyDirectory(new File(testFileRootPath + "templates"),
- this.cobiGenHome.toPath().resolve("template-sets/downloaded").toFile());
+ this.cobiGenHome.resolve("template-sets/downloaded").toFile());
CobiGenFactory.extractTemplates();
- Path adaptedFolder = this.cobiGenHome.toPath().resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)
+ Path adaptedFolder = this.cobiGenHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)
.resolve(ConfigurationConstants.ADAPTED_FOLDER);
Path extractedJar1 = adaptedFolder.resolve("template-test1-0.0.1");
Path extractedJar2 = adaptedFolder.resolve("template-test2-0.0.1");
- assertThat(Files.exists(extractedJar1));
- assertThat(Files.exists(extractedJar2));
+ assertThat(extractedJar1).exists().isDirectory();
+ assertThat(extractedJar2).exists().isDirectory();
}
/**
+ * Test of extract templates with old CobiGen_Templates project existing
+ *
* @throws IOException if an Exception occurs
*/
+ @Test
public void extractTemplatesWithOldConfiguration() throws IOException {
- Path cobigenTemplatesProject = this.cobiGenHome.toPath()
- .resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH)
- .resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
+ Path cobigenTemplatesParent = this.cobiGenHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH);
+ Files.createDirectories(cobigenTemplatesParent);
+ Path cobigenTemplatesProject = cobigenTemplatesParent.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
Files.createDirectories(cobigenTemplatesProject);
CobiGenFactory.extractTemplates();
- assertThat(Files.exists(cobigenTemplatesProject));
- }
-
- /**
- * Test of extract templates with old CobiGen_Templates project existing with custom COBIGEN_HOME environment variable
- *
- * @throws Exception test fails
- */
- @Test
- public void testExtractTemplatesWithOldConfiguration() throws Exception {
-
- withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
- .execute(() -> extractTemplatesWithOldConfiguration());
+ assertThat(cobigenTemplatesProject).exists().isDirectory();
}
/**
- * Test of extract template sets with custom COBIGEN_HOME environment variable
+ * Test of find template set downloaded folder to ensure backwards compatibility
*
- * @throws Exception test fails
- */
- @Test
- public void testExtractTemplateSets() throws Exception {
-
- withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
- .execute(() -> extractTemplateSetsTest());
- }
-
- /**
* @throws IOException if an Exception occurs
*/
- public void findTemplateSetJarsWithBackwardsCompatibilityTest() throws IOException {
+ @Test
+ public void findTemplateSetsDownloadedFolderTest() throws IOException {
- Path downloadedFolder = this.cobiGenHome.toPath().resolve("template-sets").resolve("downloaded");
+ Path downloadedFolder = this.cobiGenHome.resolve("template-sets").resolve("downloaded");
Files.createDirectories(downloadedFolder);
URI templatesLocationURI = ConfigurationFinder.findTemplatesLocation();
- assertThat(templatesLocationURI.compareTo(this.cobiGenHome.toPath().resolve("template-sets").toUri()));
-
- }
-
- /**
- * Test of find template set downloaded folder to ensure backwards compatibility with custom COBIGEN_HOME environment
- * variable
- *
- * @throws Exception test fails
- */
- @Test
- public void testfindTemplateSetDownloadedWithBackwardsCompatibility() throws Exception {
-
- withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
- .execute(() -> findTemplateSetJarsWithBackwardsCompatibilityTest());
+ Path expectedDownloadedFolder = Paths.get(templatesLocationURI).resolve("downloaded");
+ assertThat(expectedDownloadedFolder).exists().isDirectory();
}
}
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TriggerActivationTest.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TriggerActivationTest.java
index 4790f16b58..7582aaebb2 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TriggerActivationTest.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/TriggerActivationTest.java
@@ -1,20 +1,21 @@
package com.devonfw.cobigen.systemtest;
+import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.internal.matchers.Any.ANY;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.io.File;
import java.util.List;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.hamcrest.MockitoHamcrest;
import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
@@ -45,7 +46,6 @@ public class TriggerActivationTest extends AbstractApiTest {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testNoActivation_1Of2AND_MatcherMatches() throws Exception {
Object input = new Object();
@@ -60,11 +60,16 @@ public void testNoActivation_1Of2AND_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -82,7 +87,6 @@ public void testNoActivation_1Of2AND_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testNoActivation_1Of2AND_1OR_MatcherMatches() throws Exception {
Object input = new Object();
@@ -97,11 +101,19 @@ public void testNoActivation_1Of2AND_1OR_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -119,7 +131,6 @@ public void testNoActivation_1Of2AND_1OR_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testActivation_2Of2AND_MatcherMatches() throws Exception {
Object input = new Object();
@@ -130,15 +141,24 @@ public void testActivation_2Of2AND_MatcherMatches() throws Exception {
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+
when(triggerInterpreter.getType()).thenReturn("test");
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -156,7 +176,6 @@ public void testActivation_2Of2AND_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testNoActivation_2Of2AND_1NOT_MatcherMatches() throws Exception {
Object input = new Object();
@@ -171,11 +190,19 @@ public void testNoActivation_2Of2AND_1NOT_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -193,7 +220,6 @@ public void testNoActivation_2Of2AND_1NOT_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testNoActivation_1OR_0AND_MatcherMatches() throws Exception {
Object input = new Object();
@@ -208,11 +234,19 @@ public void testNoActivation_1OR_0AND_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -230,7 +264,6 @@ public void testNoActivation_1OR_0AND_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testNoActivation_1OR_1NOT_MatcherMatches() throws Exception {
Object input = new Object();
@@ -245,11 +278,19 @@ public void testNoActivation_1OR_1NOT_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and1"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("and2"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and1"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(
+ MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("and2"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
@@ -267,7 +308,6 @@ public void testNoActivation_1OR_1NOT_MatcherMatches() throws Exception {
* @author mbrunnli (22.02.2015)
*/
@Test
- @SuppressWarnings("unchecked")
public void testActivation_1OR_MatcherMatches() throws Exception {
Object input = new Object();
@@ -282,9 +322,13 @@ public void testActivation_1OR_MatcherMatches() throws Exception {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(input))))).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(input))))).thenReturn(false);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
+ when(matcher
+ .matches(MockitoHamcrest.argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/util/PluginMockFactory.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/util/PluginMockFactory.java
index 8e71f77ccb..e3df88efe4 100644
--- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/util/PluginMockFactory.java
+++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/util/PluginMockFactory.java
@@ -1,16 +1,17 @@
package com.devonfw.cobigen.systemtest.util;
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
+import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.internal.matchers.Any.ANY;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.util.HashMap;
+import org.mockito.Mockito;
+
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
import com.devonfw.cobigen.api.extension.InputReader;
import com.devonfw.cobigen.api.extension.MatcherInterpreter;
@@ -52,11 +53,14 @@ public String toString() {
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
- when(inputReader.isValidInput(any())).thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(false);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(input))))).thenReturn(true);
+ when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
+ .thenReturn(false);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
- when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
+ when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
+ .thenReturn(true);
// Simulate variable resolving of any plug-in
HashMap variables = new HashMap<>(3);
@@ -64,12 +68,12 @@ public String toString() {
variables.put("component", "comp1");
variables.put("detail", "");
- when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))),
+ when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input))),
argThat(hasItemsInList(
//
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
- any())).thenReturn(variables);
+ Mockito.any())).thenReturn(variables);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
diff --git a/cobigen/cobigen-core-test/pom.xml b/cobigen/cobigen-core-test/pom.xml
index b2239d1c86..87ee06abbe 100644
--- a/cobigen/cobigen-core-test/pom.xml
+++ b/cobigen/cobigen-core-test/pom.xml
@@ -22,13 +22,7 @@
junit
junit
4.13.1
-
-
-
- org.mockito
- mockito-core
- 1.10.19
-
+
org.hamcrest
@@ -36,6 +30,17 @@
+
+
+ org.mockito
+ mockito-inline
+ 4.4.0
+
+
+ org.hamcrest
+ hamcrest
+ 2.2
+
org.assertj
assertj-core
diff --git a/cobigen/cobigen-core-test/src/main/java/com/devonfw/cobigen/test/matchers/CustomHamcrestMatchers.java b/cobigen/cobigen-core-test/src/main/java/com/devonfw/cobigen/test/matchers/CustomHamcrestMatchers.java
index 0d28f03abb..2c80ea4fcf 100644
--- a/cobigen/cobigen-core-test/src/main/java/com/devonfw/cobigen/test/matchers/CustomHamcrestMatchers.java
+++ b/cobigen/cobigen-core-test/src/main/java/com/devonfw/cobigen/test/matchers/CustomHamcrestMatchers.java
@@ -5,9 +5,8 @@
import java.util.ArrayList;
import java.util.List;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
-import org.hamcrest.core.IsCollectionContaining;
+import org.hamcrest.core.IsIterableContaining;
/**
* These functions have been ported from hamcrest, whereas the signature has been customized
@@ -30,7 +29,6 @@ public class CustomHamcrestMatchers {
* @param itemMatchers the matchers to apply to items provided by the examined {@link List}
* @return the matcher instance
*/
- @Factory
@SuppressWarnings("unchecked")
public static Matcher> hasItemsInList(Matcher super T>... itemMatchers) {
@@ -38,7 +36,7 @@ public static Matcher> hasItemsInList(Matcher super T>... itemMatc
for (Matcher super T> elementMatcher : itemMatchers) {
// Doesn't forward to hasItem() method so compiler can sort out generics.
- all.add(new IsCollectionContaining<>(elementMatcher));
+ all.add(new IsIterableContaining<>(elementMatcher));
}
return allOf(all);
diff --git a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/exceptions/UnknownContextVariableException.java b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/exceptions/UnknownContextVariableException.java
index 7257507958..e02af71195 100644
--- a/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/exceptions/UnknownContextVariableException.java
+++ b/cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/exceptions/UnknownContextVariableException.java
@@ -17,7 +17,7 @@ public class UnknownContextVariableException extends InvalidConfigurationExcepti
*/
public UnknownContextVariableException(String variableName) {
- super(
- "Either unknown context variable: " + variableName + "or invalid external incrementRef in case of having one.");
+ super("Either unknown context variable: " + variableName
+ + " or invalid external incrementRef in case of having one.");
}
}