Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HDouss committed Feb 29, 2020
1 parent 626e607 commit b1fca26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/jpeek/ReportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.jpeek;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -94,7 +95,7 @@ final class ReportData {
ReportData(final String name, final Map<String, Object> args, final double mean,
final double sigma) {
this.metr = name;
this.args = new HashMap<>(args);
this.args = Collections.unmodifiableMap(args);
this.man = mean;
this.sig = sigma;
}
Expand Down Expand Up @@ -128,6 +129,6 @@ public double sigma() {
* @return Params
*/
public Map<String, Object> params() {
return new HashMap<>(this.args);
return this.args;
}
}
27 changes: 23 additions & 4 deletions src/test/java/org/jpeek/ReportDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasValues;
import org.llorllale.cactoos.matchers.Throws;

/**
* Tests for {@link ReportData}.
Expand All @@ -47,9 +48,21 @@ public void reportsData() throws Exception {
final double sigma = random.nextDouble();
final Map<String, Object> sample = ReportDataTest.args();
final ReportData data = new ReportData(name, sample, mean, sigma);
new Assertion<>("Must returns name", data.metric(), new IsEqual<>(name)).affirm();
new Assertion<>("Must returns mean", data.mean(), new IsEqual<>(mean)).affirm();
new Assertion<>("Must returns sigma", data.sigma(), new IsEqual<>(sigma)).affirm();
new Assertion<>(
"Must returns name",
data.metric(),
new IsEqual<>(name)
).affirm();
new Assertion<>(
"Must returns mean",
data.mean(),
new IsEqual<>(mean)
).affirm();
new Assertion<>(
"Must returns sigma",
data.sigma(),
new IsEqual<>(sigma)
).affirm();
new Assertion<>(
"Must returns args",
data.params().entrySet(),
Expand All @@ -64,12 +77,18 @@ public void shouldBeImmutable() throws Exception {
final Map<String, Object> params = new HashMap<>(sample);
final ReportData data = new ReportData(name, params);
params.clear();
data.params().clear();
new Assertion<>(
"Must be immutable",
data.params().entrySet().size(),
new IsEqual<>(sample.size())
).affirm();
new Assertion<>(
"Must throw an exception if retrieved is modified",
() -> {
data.params().clear();
return "";
}, new Throws<>(UnsupportedOperationException.class)
).affirm();
}

private static Map<String, Object> args() {
Expand Down

0 comments on commit b1fca26

Please sign in to comment.