]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3621 Add some unit tests
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 10 Oct 2012 07:43:11 +0000 (09:43 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 10 Oct 2012 09:41:40 +0000 (11:41 +0200)
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterContext.java
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterEngine.java
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterContextTest.java
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterEngineTest.java

index 5c0ad12b69164952837e1cad7718d4c233068fb1..9cf990ee4eecb6b173b8042cef48eb8fd3b14473 100644 (file)
@@ -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();
index 2b5da9a14201cd6348d8667d852225b754941721..253c2875d6f7dd214cee1dbb46b368cf999a239c 100644 (file)
@@ -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());
index ffd7fd643e25a13629afcc701dcd19955b5c7d9e..4e1174a81707d862238969d78fdd335e64815b3d 100644 (file)
@@ -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]");
   }
 }
index b92d173062fab2aaa93940e3943c7513e60ded27..2b08db5c968a50d7853edb89670017244aaae24b 100644 (file)
@@ -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=<xml>");
+
+    MeasureFilterDecoder decoder = mock(MeasureFilterDecoder.class);
+    when(decoder.decode("<xml>")).thenThrow(new ParseException(0));
+    MeasureFilterExecutor executor = mock(MeasureFilterExecutor.class);
+
+    MeasureFilterEngine engine = new MeasureFilterEngine(decoder, executor);
+    engine.execute("<xml>", 50L);
+  }
 }