Skip to content

Commit

Permalink
Issue-271: format config file
Browse files Browse the repository at this point in the history
Signed-off-by: l-1sqared <30831153+l-1squared@users.noreply.github.com>
  • Loading branch information
l-1squared committed Jul 2, 2021
1 parent 6ade551 commit 6947bc7
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions jgiven-core/src/main/java/com/tngtech/jgiven/impl/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Helper class to access all system properties to configure JGiven.
*/
public class Config {
private static final Logger log = LoggerFactory.getLogger( Config.class );
private static final Logger log = LoggerFactory.getLogger(Config.class);
private static final Properties CONFIG_FILE_PROPERTIES = loadConfigFileProperties();
private static final Config INSTANCE = new Config();

Expand All @@ -33,13 +33,13 @@ public class Config {
private static final String JGIVEN_CONFIG_PATH = "jgiven.config.path";
private static final String JGIVEN_CONFIG_CHARSET = "jgiven.config.charset";

public static Config config(){
public static Config config() {
return INSTANCE;
}

static{
if( INSTANCE.dryRun() ) {
log.info( "Dry Run enabled." );
static {
if (INSTANCE.dryRun()) {
log.info("Dry Run enabled.");
}
}

Expand All @@ -65,58 +65,59 @@ private String resolveProperty(String name, String defaultValue) {
return System.getProperty(name, CONFIG_FILE_PROPERTIES.getProperty(name, defaultValue));
}

public Optional<File> getReportDir(){
String reportDirName = resolveProperty( JGIVEN_REPORT_DIR );
if( reportDirName == null ) {
if( System.getProperty( "surefire.test.class.path" ) != null ) {
public Optional<File> getReportDir() {
String reportDirName = resolveProperty(JGIVEN_REPORT_DIR);
if (reportDirName == null) {
if (resolveProperty("surefire.test.class.path") != null) {
reportDirName = "target/jgiven-reports/json";
log.info( JGIVEN_REPORT_DIR + " not set, but detected surefire plugin, generating reports to " + reportDirName );
log.info(JGIVEN_REPORT_DIR + " not set, but detected surefire plugin, generating reports to "
+ reportDirName);
} else {
reportDirName = "jgiven-reports";
log.debug( JGIVEN_REPORT_DIR + " not set, using default value jgiven-reports" );
log.debug(JGIVEN_REPORT_DIR + " not set, using default value jgiven-reports");
}
}

File reportDir = new File( reportDirName );
if( reportDir.exists() && !reportDir.isDirectory() ) {
log.warn( reportDirName + " exists but is not a directory. Will not generate JGiven reports." );
File reportDir = new File(reportDirName);
if (reportDir.exists() && !reportDir.isDirectory()) {
log.warn(reportDirName + " exists but is not a directory. Will not generate JGiven reports.");
return Optional.empty();
}

log.debug( "Using folder " + reportDirName + " to store JGiven reports" );
log.debug("Using folder " + reportDirName + " to store JGiven reports");

return Optional.of( reportDir );
return Optional.of(reportDir);
}

public boolean isReportEnabled(){
return TRUE.equalsIgnoreCase( resolveProperty( JGIVEN_REPORT_ENABLED, TRUE ) );
public boolean isReportEnabled() {
return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_REPORT_ENABLED, TRUE));
}

public void setReportEnabled( boolean enabled ){
System.setProperty( JGIVEN_REPORT_ENABLED, "" + enabled );
public void setReportEnabled(boolean enabled) {
System.setProperty(JGIVEN_REPORT_ENABLED, "" + enabled);
}

public ConfigValue textColorEnabled(){
return ConfigValue.fromString( resolveProperty( JGIVEN_REPORT_TEXT_COLOR, AUTO ) );
public ConfigValue textColorEnabled() {
return ConfigValue.fromString(resolveProperty(JGIVEN_REPORT_TEXT_COLOR, AUTO));
}

public boolean textReport(){
return TRUE.equalsIgnoreCase( resolveProperty( JGIVEN_REPORT_TEXT, TRUE ) );
public boolean textReport() {
return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_REPORT_TEXT, TRUE));
}

public void setTextReport( boolean b ){
System.setProperty( JGIVEN_REPORT_TEXT, "" + b );
public void setTextReport(boolean b) {
System.setProperty(JGIVEN_REPORT_TEXT, "" + b);
}

public boolean filterStackTrace(){
return TRUE.equalsIgnoreCase( resolveProperty( JGIVEN_FILTER_STACK_TRACE, TRUE ) );
public boolean filterStackTrace() {
return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_FILTER_STACK_TRACE, TRUE));
}

public void setReportDir( File reportDir ){
System.setProperty( JGIVEN_REPORT_DIR, reportDir.getAbsolutePath() );
public void setReportDir(File reportDir) {
System.setProperty(JGIVEN_REPORT_DIR, reportDir.getAbsolutePath());
}

public boolean dryRun(){
return TRUE.equals( System.getProperty( JGIVEN_REPORT_DRY_RUN, FALSE ) );
public boolean dryRun() {
return TRUE.equals(System.getProperty(JGIVEN_REPORT_DRY_RUN, FALSE));
}
}

0 comments on commit 6947bc7

Please sign in to comment.