]> source.dussan.org Git - sonarqube.git/commitdiff
Add some UT
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 20 Jun 2013 14:26:27 +0000 (16:26 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 20 Jun 2013 14:26:27 +0000 (16:26 +0200)
sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java

index 59ed2b33055a7951ec47abd74c6144fbf87d973e..54d592260e8d51b7428fa6edcf1822675d91d401 100644 (file)
@@ -305,6 +305,25 @@ public class InternalRubyIssueServiceTest {
     assertThat(issueFilter.description()).isEqualTo("Long term issues");
   }
 
+  @Test
+  public void should_not_create_issue_filter() {
+    Result result = service.createIssueFilter(Maps.<String, String>newHashMap());
+    assertThat(result.ok()).isFalse();
+    verify(issueFilterService, never()).save(any(DefaultIssueFilter.class), any(UserSession.class));
+  }
+
+  @Test
+  public void should_return_error_on_create_issue_filter() {
+    Map<String, String> parameters = newHashMap();
+    parameters.put("name", "Long term");
+    parameters.put("description", "Long term issues");
+
+    doThrow(new RuntimeException("Error")).when(issueFilterService).save(any(DefaultIssueFilter.class), any(UserSession.class));
+    Result result = service.createIssueFilter(parameters);
+    assertThat(result.ok()).isFalse();
+    assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+  }
+
   @Test
   public void should_update_issue_filter() {
     Map<String, String> parameters = newHashMap();
@@ -323,6 +342,26 @@ public class InternalRubyIssueServiceTest {
     assertThat(issueFilter.description()).isEqualTo("Long term issues");
   }
 
+  @Test
+  public void should_not_update_issue_filter() {
+    Result result = service.updateIssueFilter(Maps.<String, String>newHashMap());
+    assertThat(result.ok()).isFalse();
+    verify(issueFilterService, never()).update(any(DefaultIssueFilter.class), any(UserSession.class));
+  }
+
+  @Test
+  public void should_return_error_on_update_issue_filter() {
+    Map<String, String> parameters = newHashMap();
+    parameters.put("id", "10");
+    parameters.put("name", "Long term");
+    parameters.put("description", "Long term issues");
+
+    doThrow(new RuntimeException("Error")).when(issueFilterService).update(any(DefaultIssueFilter.class), any(UserSession.class));
+    Result result = service.updateIssueFilter(parameters);
+    assertThat(result.ok()).isFalse();
+    assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+  }
+
   @Test
   public void should_update_data() {
     Map<String, Object> data = newHashMap();
@@ -336,6 +375,14 @@ public class InternalRubyIssueServiceTest {
     assertThat(result.ok()).isTrue();
   }
 
+  @Test
+  public void should_return_error_on_delete_issue_filter() {
+    doThrow(new RuntimeException("Error")).when(issueFilterService).delete(anyLong(), any(UserSession.class));
+    Result result = service.deleteIssueFilter(1L);
+    assertThat(result.ok()).isFalse();
+    assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+  }
+
   @Test
   public void should_copy_issue_filter() {
     Map<String, String> parameters = newHashMap();
@@ -352,6 +399,25 @@ public class InternalRubyIssueServiceTest {
     assertThat(issueFilter.description()).isEqualTo("Copy of Long term issues");
   }
 
+  @Test
+  public void should_not_copy_issue_filter() {
+    Result result = service.copyIssueFilter(1L, Maps.<String, String>newHashMap());
+    assertThat(result.ok()).isFalse();
+    verify(issueFilterService, never()).copy(anyLong(), any(DefaultIssueFilter.class), any(UserSession.class));
+  }
+
+  @Test
+  public void should_return_error_on_copy_issue_filter() {
+    Map<String, String> parameters = newHashMap();
+    parameters.put("name", "Copy of Long term");
+    parameters.put("description", "Copy of Long term issues");
+
+    doThrow(new RuntimeException("Error")).when(issueFilterService).copy(anyLong(), any(DefaultIssueFilter.class), any(UserSession.class));
+    Result result = service.copyIssueFilter(1L, parameters);
+    assertThat(result.ok()).isFalse();
+    assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+  }
+
   @Test
   public void should_get_error_on_issue_filter_result_when_no_name() {
     Map<String, String> parameters = newHashMap();
@@ -443,10 +509,19 @@ public class InternalRubyIssueServiceTest {
 
   @Test
   public void should_toggle_favourite_issue_filter() {
-    service.toggleFavouriteIssueFilter(10L);
+    Result result = service.toggleFavouriteIssueFilter(10L);
+    assertThat(result.ok()).isTrue();
     verify(issueFilterService).toggleFavouriteIssueFilter(eq(10L), any(UserSession.class));
   }
 
+  @Test
+  public void should_return_error_on_toggle_favourite_issue_filter() {
+    doThrow(new RuntimeException("Error")).when(issueFilterService).toggleFavouriteIssueFilter(eq(10L), any(UserSession.class));
+    Result result = service.toggleFavouriteIssueFilter(10L);
+    assertThat(result.ok()).isFalse();
+    assertThat(((Result.Message) result.errors().get(0)).text()).contains("Error");
+  }
+
   @Test
   public void should_check_is_user_is_authorized_to_see_issue_filter() {
     DefaultIssueFilter issueFilter = new DefaultIssueFilter();