aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-02-20 22:05:03 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-02-20 22:05:03 +0100
commit726c17ed044d5e23a4ee1465a8a8c487ac1a9646 (patch)
tree8524a33e71c1ade6ee20c777cc2a8155b3d85d1a /sonar-core/src
parentc62f38d64c56ef9215e78b9adeb224cd76bfa4be (diff)
downloadsonarqube-726c17ed044d5e23a4ee1465a8a8c487ac1a9646.tar.gz
sonarqube-726c17ed044d5e23a4ee1465a8a8c487ac1a9646.zip
Add unit tests and fix some quality flaws
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java3
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java54
3 files changed, 57 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java
index 5e9d085372f..7fca0f6773a 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java
@@ -69,7 +69,7 @@ public final class PurgeSnapshotQuery {
}
public PurgeSnapshotQuery setStatus(String[] status) {
- this.status = status;
+ this.status = status; //NOSONAR org.sonar.core.purge.PurgeSnapshotQuery.setStatus(String[]) may expose internal representation
return this;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
index f51b1218c61..826b158b336 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java
@@ -46,8 +46,9 @@ public class PurgeableSnapshotDto implements Comparable<PurgeableSnapshotDto> {
return isLast;
}
- public void setDate(Date date) {
+ public PurgeableSnapshotDto setDate(Date date) {
this.date = date;//NOSONAR May expose internal representation by incorporating reference to mutable object
+ return this;
}
public PurgeableSnapshotDto setSnapshotId(long snapshotId) {
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java
new file mode 100644
index 00000000000..dc21a9868e3
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.persistence;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Test;
+
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.*;
+
+public class BatchSessionTest {
+ @Test
+ public void shouldCommitWhenReachingBatchSize() {
+ SqlSession mybatisSession = mock(SqlSession.class);
+ BatchSession session = new BatchSession(mybatisSession, 10);
+
+ for (int i = 0; i < 9; i++) {
+ session.insert("id" + i);
+ verify(mybatisSession).insert("id" + i);
+ verify(mybatisSession, never()).commit();
+ verify(mybatisSession, never()).commit(anyBoolean());
+ }
+ session.insert("id9");
+ verify(mybatisSession).commit();
+ }
+
+ @Test
+ public void shouldResetCounterAfterCommit() {
+ SqlSession mybatisSession = mock(SqlSession.class);
+ BatchSession session = new BatchSession(mybatisSession, 10);
+
+ for (int i = 0; i < 35; i++) {
+ session.insert("id" + i);
+ }
+ verify(mybatisSession, times(3)).commit();
+ }
+}