Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 224: Fix behavior of hideParameters parameter #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/fr/jcgay/maven/profiler/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.jcgay.maven.profiler;

import com.google.common.annotations.VisibleForTesting;
import fr.jcgay.maven.profiler.reporting.CompositeReporter;
import fr.jcgay.maven.profiler.reporting.Reporter;
import fr.jcgay.maven.profiler.reporting.console.ConsoleReporter;
Expand All @@ -24,7 +25,8 @@ public class Configuration {
private static final String PROFILE = "profile";
private static final String PROFILE_FORMAT = "profileFormat";
private static final String DISABLE_TIME_SORTING = "disableTimeSorting";
private static final String DISABLE_PARAMETERS_REPORT = "hideParameters";
@VisibleForTesting
static final String DISABLE_PARAMETERS_REPORT = "hideParameters";

private static final Function<String,Reporter> reporters = compose(forMap(ImmutableMap.<String,Reporter>builder()
.put("html", new HtmlReporter())
Expand Down Expand Up @@ -72,7 +74,9 @@ public boolean shouldPrintParameters() {
}

private static boolean hasParametersReportEnabled() {
return Boolean.parseBoolean(System.getProperty(DISABLE_PARAMETERS_REPORT, "false"));
// Inversion of logic: System property is called "hideParameters", but method returns the inverted result
// If the parameter is true or not set, the report is not printed (see issue 224)
return !Boolean.parseBoolean(System.getProperty(DISABLE_PARAMETERS_REPORT, "true"));
}

private static Sorter chooseSorter() {
Expand Down
27 changes: 27 additions & 0 deletions src/test/groovy/fr/jcgay/maven/profiler/ConfigurationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,31 @@ class ConfigurationTest {
assertThat(result.reporter().delegates).extracting("class").containsExactly(HtmlReporter)
assertThat(result.sorter()).isExactlyInstanceOf(ByExecutionTime)
}

@Test
void 'disable parameter report when hideParameters is unset'() {
System.clearProperty(Configuration.DISABLE_PARAMETERS_REPORT)

def result = Configuration.read()

assertThat(result.shouldPrintParameters()).isFalse()
}

@Test
void 'disable parameter report when hideParameters is true'() {
System.setProperty(Configuration.DISABLE_PARAMETERS_REPORT, Boolean.TRUE.toString())

def result = Configuration.read()

assertThat(result.shouldPrintParameters()).isFalse()
}

@Test
void 'enable parameter report when hideParameters is false'() {
System.setProperty(Configuration.DISABLE_PARAMETERS_REPORT, Boolean.FALSE.toString())

def result = Configuration.read()

assertThat(result.shouldPrintParameters()).isTrue()
}
}
Loading