Skip to content

Commit 36ab7ce

Browse files
Template set deployables test optimizations (#1515)
* update mockito and Hamcrest * adapt TemplatedProcessingTest to work as expected * #1452 fixed eclipse build.properties and .classpath * #1452 implemented requested changes changed cobigenHome from File to Path * #1452 implemented requested changes * #1452 removed unnecessary lambda because of more effective mockito * Revert "#1452 removed unnecessary lambda because of more effective mockito" This reverts commit e85dde5. * test without mockito partial mock * #1452 re-introduced mockito changes with latest changes from template-set-deployables renamed findTemplateSetJarsWithBackwardsCompatibilityTest to findTemplateSetsDownloadedFolderTest fixed logic of findTemplateSetsDownloadedFolderTest Co-authored-by: LarsReinken <[email protected]>
1 parent 54e3436 commit 36ab7ce

File tree

11 files changed

+234
-173
lines changed

11 files changed

+234
-173
lines changed

cobigen-eclipse/cobigen-eclipse-test/.classpath

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
4-
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
53
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
64
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
75
<classpathentry kind="src" path="src/main/java/">
@@ -17,7 +15,6 @@
1715
<classpathentry exported="true" kind="lib" path="lib/error_prone_annotations.jar"/>
1816
<classpathentry exported="true" kind="lib" path="lib/failureaccess.jar"/>
1917
<classpathentry exported="true" kind="lib" path="lib/guava.jar"/>
20-
<classpathentry exported="true" kind="lib" path="lib/hamcrest-core.jar"/>
2118
<classpathentry exported="true" kind="lib" path="lib/j2objc-annotations.jar"/>
2219
<classpathentry exported="true" kind="lib" path="lib/jcl-over-slf4j.jar"/>
2320
<classpathentry exported="true" kind="lib" path="lib/jsr305.jar"/>
@@ -32,5 +29,7 @@
3229
<classpathentry exported="true" kind="lib" path="lib/system-lambda.jar"/>
3330
<classpathentry exported="true" kind="lib" path="lib/xmlunit.jar"/>
3431
<classpathentry exported="true" kind="lib" path="lib/zt-exec.jar"/>
32+
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
33+
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
3534
<classpathentry kind="output" path="eclipse-target/classes"/>
3635
</classpath>

cobigen-eclipse/cobigen-eclipse-test/build.properties

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ bin.includes = .,\
1111
lib/error_prone_annotations.jar,\
1212
lib/failureaccess.jar,\
1313
lib/guava.jar,\
14-
lib/hamcrest-core.jar,\
1514
lib/j2objc-annotations.jar,\
1615
lib/jcl-over-slf4j.jar,\
1716
lib/jsr305.jar,\

cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ClassLoadingTest.java

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.devonfw.cobigen.systemtest;
22

33
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
4-
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
54
import static org.assertj.core.api.Assertions.assertThat;
65
import static org.hamcrest.CoreMatchers.equalTo;
76
import static org.hamcrest.CoreMatchers.sameInstance;
8-
import static org.mockito.Matchers.any;
9-
import static org.mockito.Matchers.argThat;
7+
import static org.mockito.ArgumentMatchers.any;
108
import static org.mockito.Mockito.mock;
119
import static org.mockito.Mockito.when;
12-
import static org.mockito.internal.matchers.Any.ANY;
10+
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
1311

1412
import java.io.File;
1513
import java.nio.charset.Charset;
1614
import java.nio.file.Paths;
1715
import java.util.List;
1816

17+
import org.hamcrest.Matcher;
1918
import org.junit.Test;
2019

2120
import com.devonfw.cobigen.api.CobiGen;
@@ -27,9 +26,11 @@
2726
import com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher;
2827
import com.devonfw.cobigen.api.to.GenerationReportTo;
2928
import com.devonfw.cobigen.api.to.TemplateTo;
29+
import com.devonfw.cobigen.api.to.VariableAssignmentTo;
3030
import com.devonfw.cobigen.impl.CobiGenFactory;
3131
import com.devonfw.cobigen.impl.extension.PluginRegistry;
3232
import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
33+
import com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers;
3334
import com.google.common.collect.ImmutableMap;
3435
import com.google.common.collect.Lists;
3536

@@ -72,7 +73,6 @@ public void callClassLoadingTest() throws Exception {
7273
assertThat(report).isSuccessful();
7374
assertThat(generatedFile).exists();
7475
assertThat(generatedFile).isFile().hasSameContentAs(expectedResult);
75-
7676
}
7777

7878
@Test
@@ -140,24 +140,27 @@ public String toString() {
140140
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
141141

142142
when(inputReader.isValidInput(any())).thenReturn(true);
143-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
144-
.thenReturn(false);
145-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
146-
.thenReturn(true);
143+
when(matcher.matches(argThat(
144+
new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class), sameInstance(container)))))
145+
.thenReturn(false);
146+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), org.hamcrest.CoreMatchers.any(String.class),
147+
sameInstance(container))))).thenReturn(true);
147148

148149
// Simulate container children resolution of any plug-in
149150
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));
150151

151-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
152-
.thenReturn(true);
152+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), org.hamcrest.CoreMatchers.any(String.class),
153+
sameInstance(firstChildResource))))).thenReturn(true);
153154

154155
// Simulate variable resolving of any plug-in
155-
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
156-
argThat(hasItemsInList(
157-
//
158-
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
159-
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
160-
any()))
156+
Matcher<VariableAssignmentTo> m1 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"),
157+
equalTo("1"), equalTo(false));
158+
Matcher<VariableAssignmentTo> m2 = new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"),
159+
equalTo("3"), equalTo(false));
160+
Matcher<List<VariableAssignmentTo>> tmp = CustomHamcrestMatchers.hasItemsInList(m1, m2);
161+
// IsIterableContaining<VariableAssignmentTo> t1 = new IsIterableContaining<>();
162+
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"),
163+
org.hamcrest.CoreMatchers.any(String.class), sameInstance(firstChildResource))), argThat(tmp), any()))
161164
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
162165
.put("entityName", "Test").build());
163166

cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/ContainerMatcherTest.java

+36-25
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
44
import static com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers.hasItemsInList;
5+
import static org.hamcrest.CoreMatchers.any;
56
import static org.hamcrest.CoreMatchers.equalTo;
67
import static org.hamcrest.CoreMatchers.sameInstance;
78
import static org.junit.Assert.assertEquals;
89
import static org.junit.Assert.assertNotNull;
9-
import static org.mockito.Matchers.any;
10-
import static org.mockito.Matchers.anyList;
11-
import static org.mockito.Matchers.argThat;
10+
import static org.mockito.ArgumentMatchers.anyList;
1211
import static org.mockito.Mockito.mock;
1312
import static org.mockito.Mockito.when;
14-
import static org.mockito.internal.matchers.Any.ANY;
13+
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
1514

1615
import java.io.File;
1716
import java.nio.charset.Charset;
@@ -20,6 +19,7 @@
2019

2120
import org.junit.Assert;
2221
import org.junit.Test;
22+
import org.mockito.Mockito;
2323

2424
import com.devonfw.cobigen.api.CobiGen;
2525
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
@@ -251,26 +251,34 @@ public String toString() {
251251
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
252252
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
253253

254-
when(inputReader.isValidInput(any())).thenReturn(true);
254+
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
255255

256256
// Simulate container children resolution of any plug-in
257-
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))), anyList(),
258-
any())).thenReturn(ImmutableMap.<String, String> builder().put("variable", "child1").build());
259-
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))), anyList(),
260-
any())).thenReturn(ImmutableMap.<String, String> builder().put("variable", "child2").build());
261-
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(child1, child2));
257+
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1))),
258+
anyList(), Mockito.any()))
259+
.thenReturn(ImmutableMap.<String, String> builder().put("variable", "child1").build());
260+
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2))),
261+
anyList(), Mockito.any()))
262+
.thenReturn(ImmutableMap.<String, String> builder().put("variable", "child2").build());
263+
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
264+
.thenReturn(Lists.newArrayList(child1, child2));
262265

263266
// match container
264-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("container"), ANY, sameInstance(container)))))
265-
.thenReturn(true);
267+
when(matcher
268+
.matches(argThat(new MatcherToMatcher(equalTo("container"), any(String.class), sameInstance(container)))))
269+
.thenReturn(true);
266270

267271
// do not match first child
268-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child1))))).thenReturn(true);
269-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child1))))).thenReturn(true);
272+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child1)))))
273+
.thenReturn(true);
274+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child1)))))
275+
.thenReturn(true);
270276

271277
// match second child
272-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), ANY, sameInstance(child2))))).thenReturn(true);
273-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child2))))).thenReturn(false);
278+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("or"), any(String.class), sameInstance(child2)))))
279+
.thenReturn(true);
280+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), any(String.class), sameInstance(child2)))))
281+
.thenReturn(false);
274282

275283
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
276284

@@ -346,10 +354,10 @@ public String toString() {
346354
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
347355
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
348356

349-
when(inputReader.isValidInput(any())).thenReturn(true);
350-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(container)))))
357+
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
358+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(container)))))
351359
.thenReturn(false);
352-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), ANY, sameInstance(container)))))
360+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("package"), any(String.class), sameInstance(container)))))
353361
.thenReturn(true);
354362

355363
// Simulate container children resolution of any plug-in
@@ -361,22 +369,25 @@ public String toString() {
361369
return "child2";
362370
}
363371
};
364-
when(inputReader.getInputObjects(any(), any(Charset.class)))
372+
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
365373
.thenReturn(Lists.newArrayList(firstChildResource, secondChildResource));
366374
} else {
367-
when(inputReader.getInputObjects(any(), any(Charset.class))).thenReturn(Lists.newArrayList(firstChildResource));
375+
when(inputReader.getInputObjects(Mockito.any(), Mockito.any(Charset.class)))
376+
.thenReturn(Lists.newArrayList(firstChildResource));
368377
}
369378

370-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource)))))
371-
.thenReturn(containerChildMatchesTrigger);
379+
when(matcher
380+
.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource)))))
381+
.thenReturn(containerChildMatchesTrigger);
372382

373383
// Simulate variable resolving of any plug-in
374-
when(matcher.resolveVariables(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(firstChildResource))),
384+
when(matcher.resolveVariables(
385+
argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(firstChildResource))),
375386
argThat(hasItemsInList(
376387
//
377388
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("rootPackage"), equalTo("1"), equalTo(false)),
378389
new VariableAssignmentToMatcher(equalTo("regex"), equalTo("entityName"), equalTo("3"), equalTo(false)))),
379-
any()))
390+
Mockito.any()))
380391
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
381392
.put("entityName", "Test").build());
382393

cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationTest.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import static com.devonfw.cobigen.api.assertj.CobiGenAsserts.assertThat;
44
import static org.assertj.core.api.Assertions.assertThat;
55
import static org.assertj.core.api.Assertions.assertThatThrownBy;
6+
import static org.hamcrest.CoreMatchers.any;
67
import static org.hamcrest.CoreMatchers.equalTo;
78
import static org.hamcrest.CoreMatchers.sameInstance;
8-
import static org.mockito.Matchers.any;
9-
import static org.mockito.Matchers.argThat;
109
import static org.mockito.Mockito.mock;
1110
import static org.mockito.Mockito.when;
12-
import static org.mockito.internal.matchers.Any.ANY;
11+
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
1312

1413
import java.io.File;
1514
import java.io.FileWriter;
@@ -23,6 +22,7 @@
2322
import org.apache.commons.io.FileUtils;
2423
import org.apache.commons.io.IOUtils;
2524
import org.junit.Test;
25+
import org.mockito.Mockito;
2626

2727
import com.devonfw.cobigen.api.CobiGen;
2828
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
@@ -165,13 +165,15 @@ public String toString() {
165165
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
166166
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
167167

168-
when(inputReader.isValidInput(any())).thenReturn(true);
169-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
168+
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
169+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
170+
.thenReturn(true);
170171

171172
// Simulate variable resolving of any plug-in
172173
HashMap<String, String> variables = new HashMap<>(1);
173174
variables.put("contextVar", "contextValue");
174-
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
175+
when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
176+
.thenReturn(variables);
175177

176178
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
177179

@@ -218,13 +220,15 @@ public String toString() {
218220
when(triggerInterpreter.getMatcher()).thenReturn(matcher);
219221
when(triggerInterpreter.getInputReader()).thenReturn(inputReader);
220222

221-
when(inputReader.isValidInput(any())).thenReturn(true);
222-
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), ANY, sameInstance(input))))).thenReturn(true);
223+
when(inputReader.isValidInput(Mockito.any())).thenReturn(true);
224+
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("fqn"), any(String.class), sameInstance(input)))))
225+
.thenReturn(true);
223226

224227
// Simulate variable resolving of any plug-in
225228
HashMap<String, String> variables = new HashMap<>(1);
226229
variables.put("contextVar", "contextValue");
227-
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class), any())).thenReturn(variables);
230+
when(matcher.resolveVariables(Mockito.any(MatcherTo.class), Mockito.any(List.class), Mockito.any()))
231+
.thenReturn(variables);
228232

229233
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);
230234

0 commit comments

Comments
 (0)