@Override public void addMeasure(String metricKey, long value) { validateAddMeasure(metricKey); componentMeasureByMetricKey.put(metricKey, TestMeasure.createMeasure(value)); }
@Override public Iterable<Measure> getChildrenMeasures(String metric) { validateInputMetric(metric); return childrenComponentMeasureByMetricKey.get(metric); }
@Test public void get_doublet_children_measures() throws Exception { underTest.addChildrenMeasures(INPUT_METRIC, 10d, 20d); assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2); }
@Test public void add_string_measure() throws Exception { underTest.addMeasure(OUTPUT_METRIC, "text"); assertThat(underTest.getMeasure(OUTPUT_METRIC).getStringValue()).isEqualTo("text"); }
@Test public void get_int_measure() throws Exception { underTest.addInputMeasure(INPUT_METRIC, 10); assertThat(underTest.getMeasure(INPUT_METRIC).getIntValue()).isEqualTo(10); }
@Test public void get_issues() throws Exception { Issue issue = new TestIssue.Builder() .setKey("ABCD") .setRuleKey(RuleKey.of("xoo", "S01")) .setSeverity(Severity.BLOCKER) .setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED) .setResolution(org.sonar.api.issue.Issue.RESOLUTION_FIXED) .setEffort(Duration.create(10L)) .setType(RuleType.BUG) .build(); underTest.setIssues(Arrays.asList(issue)); assertThat(underTest.getIssues()).hasSize(1); } }
@Test public void fail_with_UOE_when_trying_to_add_same_measures_twice() throws Exception { thrown.expect(UnsupportedOperationException.class); thrown.expectMessage("A measure on metric 'OUTPUT_METRIC' already exists"); underTest.addMeasure(OUTPUT_METRIC, 10); underTest.addMeasure(OUTPUT_METRIC, 20); }
@Test public void get_component() throws Exception { assertThat(underTest.getComponent()).isEqualTo(PROJECT); }
@Test public void get_settings() throws Exception { assertThat(underTest.getSettings()).isEqualTo(settings); }
@Test public void fail_with_IAE_when_trying_to_get_children_measures_on_unknown_metric() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Only metrics in [INPUT_METRIC] can be used to load measures"); underTest.getChildrenMeasures("unknown"); }
@Test public void fail_with_IAE_when_trying_to_get_measure_on_unknown_metric() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Only metrics in [INPUT_METRIC] can be used to load measures"); underTest.getMeasure("unknown"); }
@Test public void get_string_measure() throws Exception { underTest.addInputMeasure(INPUT_METRIC, "text"); assertThat(underTest.getMeasure(INPUT_METRIC).getStringValue()).isEqualTo("text"); }
@Test public void add_long_measure() throws Exception { underTest.addMeasure(OUTPUT_METRIC, 10L); assertThat(underTest.getMeasure(OUTPUT_METRIC).getLongValue()).isEqualTo(10L); }
@Test public void fail_with_IAE_when_trying_to_add_measure_on_input_metric() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Only metrics in [OUTPUT_METRIC] can be used to add measures. Metric 'INPUT_METRIC' is not allowed"); underTest.addMeasure(INPUT_METRIC, 10); }
@Override public void addMeasure(String metricKey, boolean value) { validateAddMeasure(metricKey); componentMeasureByMetricKey.put(metricKey, TestMeasure.createMeasure(value)); }
@Test public void get_long_measure() throws Exception { underTest.addInputMeasure(INPUT_METRIC, 10L); assertThat(underTest.getMeasure(INPUT_METRIC).getLongValue()).isEqualTo(10L); }
@Test public void get_int_children_measures() throws Exception { underTest.addChildrenMeasures(INPUT_METRIC, 10, 20); assertThat(underTest.getChildrenMeasures(INPUT_METRIC)).hasSize(2); }
@Test public void add_int_measure() throws Exception { underTest.addMeasure(OUTPUT_METRIC, 10); assertThat(underTest.getMeasure(OUTPUT_METRIC).getIntValue()).isEqualTo(10); }
@Override @CheckForNull public Measure getMeasure(String metric) { validateInputMetric(metric); return componentMeasureByMetricKey.get(metric); }
@Test public void fail_with_IAE_when_trying_to_add_measure_on_unknown_metric() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Only metrics in [OUTPUT_METRIC] can be used to add measures. Metric 'unknown' is not allowed"); underTest.addMeasure("unknown", 10); }