Skip to content

Commit

Permalink
[test] Removes jmockit in favor of mockito (OpenAPITools#5063)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
jimschubert committed Jan 22, 2020
1 parent bf57a99 commit ac528aa
Show file tree
Hide file tree
Showing 36 changed files with 642 additions and 1,020 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.scannerwork/
.vscode
*.iml
out/
Expand Down
6 changes: 3 additions & 3 deletions modules/openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<!-- <version>${jmockit-version}</version> -->
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.GeneratorNotFoundException;

import org.openapitools.codegen.*;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* User: lanwen Date: 24.03.15 Time: 20:22
*/

@Command(name = "generate", description = "Generate code with the specified generator.")
public class Generate implements Runnable {

// private static final Logger LOGGER = LoggerFactory.getLogger(Generate.class);
CodegenConfigurator configurator;
Generator generator;

@Option(name = {"-v", "--verbose"}, description = "verbose mode")
private Boolean verbose;
Expand Down Expand Up @@ -257,13 +252,18 @@ public void run() {
.ifPresent(FilterAttachable::clearAllFilters);
}

// attempt to read from config file
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);

// if a config file wasn't specified or we were unable to read it
// this initial check allows for field-level package private injection (for unit testing)
if (configurator == null) {
// createa a fresh configurator
configurator = new CodegenConfigurator();
if (configFile != null && configFile.length() > 0) {
// attempt to load from configFile
configurator = CodegenConfigurator.fromFile(configFile);
}

// if a config file wasn't specified, or we were unable to read it
if (configurator == null) {
// create a fresh configurator
configurator = new CodegenConfigurator();
}
}

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

try {
final ClientOptInput clientOptInput = configurator.toClientOptInput();
new DefaultGenerator().opts(clientOptInput).generate();

// this null check allows us to inject for unit testing.
if (generator == null) {
generator = new DefaultGenerator();
}

generator.opts(clientOptInput);
generator.generate();
} catch (GeneratorNotFoundException e) {
System.err.println(e.getMessage());
System.err.println("[error] Check the spelling of the generator's name and try again.");
Expand Down
Loading

0 comments on commit ac528aa

Please sign in to comment.