From 51317c4a39d1d69206bf28ed72064f0fe734c06c Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 10 Oct 2012 09:43:11 +0200 Subject: [PATCH] SONAR-3621 Add some unit tests --- .../core/measure/MeasureFilterContext.java | 2 +- .../core/measure/MeasureFilterEngine.java | 2 +- .../measure/MeasureFilterContextTest.java | 2 +- .../core/measure/MeasureFilterEngineTest.java | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterContext.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterContext.java index 5c0ad12b691..9cf990ee4ee 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterContext.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterContext.java @@ -68,7 +68,7 @@ class MeasureFilterContext { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("json", json) + .append("filter", json) .append("sql", sql) .append("user", userId) .toString(); diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java index 2b5da9a1420..253c2875d6f 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java @@ -64,7 +64,7 @@ public class MeasureFilterEngine implements ServerComponent { if (logger.isDebugEnabled()) { StringBuilder log = new StringBuilder(); log.append(SystemUtils.LINE_SEPARATOR); - log.append(" json: ").append(context.getJson()).append(SystemUtils.LINE_SEPARATOR); + log.append(" filter: ").append(context.getJson()).append(SystemUtils.LINE_SEPARATOR); log.append(" sql: ").append(context.getSql()).append(SystemUtils.LINE_SEPARATOR); log.append("results: ").append(rows.size()).append(" rows in ").append(durationMs).append("ms").append(SystemUtils.LINE_SEPARATOR); logger.debug(log.toString()); diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterContextTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterContextTest.java index ffd7fd643e2..4e1174a8170 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterContextTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterContextTest.java @@ -36,6 +36,6 @@ public class MeasureFilterContextTest { context.setJson("{}"); context.setSql("SELECT *"); context.setUserId(50L); - assertThat(context.toString()).isEqualTo("MeasureFilterContext[json={},sql=SELECT *,user=50]"); + assertThat(context.toString()).isEqualTo("MeasureFilterContext[filter={},sql=SELECT *,user=50]"); } } diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterEngineTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterEngineTest.java index b92d173062f..2b08db5c968 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterEngineTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterEngineTest.java @@ -21,13 +21,20 @@ package org.sonar.core.measure; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; +import org.json.simple.parser.ParseException; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.slf4j.Logger; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.*; public class MeasureFilterEngineTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Test public void should_decode_json_and_execute_filter() throws Exception { MeasureFilterDecoder decoder = mock(MeasureFilterDecoder.class); @@ -52,4 +59,17 @@ public class MeasureFilterEngineTest { })); verify(logger).debug(anyString()); } + + @Test + public void throw_definition_of_filter_on_error() throws Exception { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("filter="); + + MeasureFilterDecoder decoder = mock(MeasureFilterDecoder.class); + when(decoder.decode("")).thenThrow(new ParseException(0)); + MeasureFilterExecutor executor = mock(MeasureFilterExecutor.class); + + MeasureFilterEngine engine = new MeasureFilterEngine(decoder, executor); + engine.execute("", 50L); + } } -- 2.39.5