Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit ac528aa

Browse files
authoredJan 22, 2020
[test] Removes jmockit in favor of mockito (OpenAPITools#5063)
* [test] Removes jmockit in favor of mockito We use mockito in many tests. This removes jmockit which is run as a javaagent in favor of Mockito which is not. This work is in preparation for applying some static analysis tools, while evaluating others such as Jacoco. I'm also look at ways to improve build times while also decreasing "ramp up time" for contributions from the community. Reducing the number of mock frameworks and dependencies is a step toward that goal. * Rename method in new.sh * [cli] Mock the generate task
1 parent bf57a99 commit ac528aa

36 files changed

+642
-1020
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.scannerwork/
12
.vscode
23
*.iml
34
out/

‎modules/openapi-generator-cli/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
<scope>test</scope>
110110
</dependency>
111111
<dependency>
112-
<groupId>org.jmockit</groupId>
113-
<artifactId>jmockit</artifactId>
114-
<!-- <version>${jmockit-version}</version> -->
112+
<groupId>org.mockito</groupId>
113+
<artifactId>mockito-core</artifactId>
114+
<version>${mockito-version}</version>
115115
<scope>test</scope>
116116
</dependency>
117117
</dependencies>

‎modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java

+23-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,17 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030
import java.util.stream.Stream;
31-
import org.openapitools.codegen.ClientOptInput;
32-
import org.openapitools.codegen.CodegenConstants;
33-
import org.openapitools.codegen.DefaultGenerator;
34-
import org.openapitools.codegen.GeneratorNotFoundException;
31+
32+
import org.openapitools.codegen.*;
3533
import org.openapitools.codegen.config.CodegenConfigurator;
3634
import org.slf4j.Logger;
3735
import org.slf4j.LoggerFactory;
3836

39-
/**
40-
* User: lanwen Date: 24.03.15 Time: 20:22
41-
*/
42-
4337
@Command(name = "generate", description = "Generate code with the specified generator.")
4438
public class Generate implements Runnable {
4539

46-
// private static final Logger LOGGER = LoggerFactory.getLogger(Generate.class);
40+
CodegenConfigurator configurator;
41+
Generator generator;
4742

4843
@Option(name = {"-v", "--verbose"}, description = "verbose mode")
4944
private Boolean verbose;
@@ -257,13 +252,18 @@ public void run() {
257252
.ifPresent(FilterAttachable::clearAllFilters);
258253
}
259254

260-
// attempt to read from config file
261-
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
262-
263-
// if a config file wasn't specified or we were unable to read it
255+
// this initial check allows for field-level package private injection (for unit testing)
264256
if (configurator == null) {
265-
// createa a fresh configurator
266-
configurator = new CodegenConfigurator();
257+
if (configFile != null && configFile.length() > 0) {
258+
// attempt to load from configFile
259+
configurator = CodegenConfigurator.fromFile(configFile);
260+
}
261+
262+
// if a config file wasn't specified, or we were unable to read it
263+
if (configurator == null) {
264+
// create a fresh configurator
265+
configurator = new CodegenConfigurator();
266+
}
267267
}
268268

269269
// now override with any specified parameters
@@ -413,7 +413,14 @@ public void run() {
413413

414414
try {
415415
final ClientOptInput clientOptInput = configurator.toClientOptInput();
416-
new DefaultGenerator().opts(clientOptInput).generate();
416+
417+
// this null check allows us to inject for unit testing.
418+
if (generator == null) {
419+
generator = new DefaultGenerator();
420+
}
421+
422+
generator.opts(clientOptInput);
423+
generator.generate();
417424
} catch (GeneratorNotFoundException e) {
418425
System.err.println(e.getMessage());
419426
System.err.println("[error] Check the spelling of the generator's name and try again.");

0 commit comments

Comments
 (0)