]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5801 improve test of SourceLineResultSetIteratorTest
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 23 Nov 2014 22:47:09 +0000 (23:47 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 23 Nov 2014 22:47:09 +0000 (23:47 +0100)
server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineResultSetIteratorTest.java

index ae3f3ad201b2f0e7a34951751955e1840cb870c7..772d7f9ad8eee88107155a290a6ddbac2140b1d5 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.source.index;
 
 import com.google.common.collect.Lists;
-import org.apache.commons.io.Charsets;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -34,6 +33,7 @@ import java.sql.PreparedStatement;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
 
 public class SourceLineResultSetIteratorTest {
 
@@ -91,18 +91,26 @@ public class SourceLineResultSetIteratorTest {
     assertThat(iterator.hasNext()).isFalse();
   }
 
-  @Test(expected = IllegalStateException.class)
+  @Test
   public void should_fail_on_bad_csv() throws Exception {
     db.prepareDbUnit(getClass(), "source-with-scm.xml");
     Connection connection = db.openConnection();
     PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET data = ? WHERE id=1");
-    stmt.setBytes(1, ("plouf").getBytes(Charsets.UTF_8));
+    stmt.setString(1, "plouf");
     stmt.executeUpdate();
     connection.commit();
+    stmt.close();
 
     SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L);
-    assertThat(iterator.hasNext()).isTrue();
-    iterator.next();
+    try {
+      assertThat(iterator.hasNext()).isTrue();
+      iterator.next();
+      fail();
+    } catch (IllegalStateException e) {
+      // ok
+    } finally {
+      iterator.close();
+
+    }
   }
-
 }