Browse code

Chore: sonar & coverage improvements

Thomas Cataldo authored on 11/04/2019 07:00:24
Showing 5 changed files
... ...
@@ -170,7 +170,7 @@ public abstract class CyrusAclService {
170 170
 		@Override
171 171
 		public void setAcl(String mailbox, Map<String, Acl> acl) {
172 172
 			executer.execute(() -> {
173
-				synchronized (mailbox.intern()) {
173
+				synchronized (mailbox.intern()) {// NOSONAR
174 174
 					super.setAclTask(mailbox, acl);
175 175
 					logger.info("ACLs of {} updated.", mailbox);
176 176
 				}
... ...
@@ -72,8 +72,7 @@ public final class MailboxOps {
72 72
 	/**
73 73
 	 * @param domain
74 74
 	 * @param srv
75
-	 * @param mailboxUid
76
-	 *            mailbox container uid
75
+	 * @param mailboxUid mailbox container uid
77 76
 	 */
78 77
 	public static void annotate(Server srv, String mailboxUid) {
79 78
 		try (StoreClient sc = new StoreClient(srv.address(), 1143, "admin0", Token.admin0())) {
... ...
@@ -109,7 +108,7 @@ public final class MailboxOps {
109 108
 		try {
110 109
 			Thread.sleep(2000);
111 110
 		} catch (InterruptedException e) {
112
-			throw new ServerFault(e);
111
+			Thread.currentThread().interrupt();
113 112
 		}
114 113
 	}
115 114
 
116 115
new file mode 100644
... ...
@@ -0,0 +1,44 @@
1
+/* BEGIN LICENSE
2
+  * Copyright © Blue Mind SAS, 2012-2019
3
+  *
4
+  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+  * solution.
6
+  *
7
+  * This program is free software; you can redistribute it and/or modify
8
+  * it under the terms of either the GNU Affero General Public License as
9
+  * published by the Free Software Foundation (version 3 of the License).
10
+  *
11
+  * This program is distributed in the hope that it will be useful,
12
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+  *
15
+  * See LICENSE.txt
16
+  * END LICENSE
17
+  */
18
+package net.bluemind.backend.mail.replica.persistence.tests;
19
+
20
+import static org.junit.Assert.assertEquals;
21
+import static org.junit.Assert.assertNotEquals;
22
+
23
+import org.junit.Test;
24
+
25
+import net.bluemind.backend.mail.replica.persistence.RecordID;
26
+
27
+public class RecordIDTests {
28
+
29
+	@Test
30
+	public void testEquals() {
31
+		RecordID rid1 = new RecordID(1, 2);
32
+		RecordID rid2 = new RecordID(1, 2);
33
+		assertEquals(rid1, rid2);
34
+		assertEquals(rid1, rid1);
35
+		RecordID rid3 = new RecordID(1, 3);
36
+		assertNotEquals(rid1, rid3);
37
+		RecordID rid4 = new RecordID(2, 2);
38
+		assertNotEquals(rid2, rid4);
39
+		assertNotEquals(rid3, new Object());
40
+		assertNotEquals(rid2, rid4);
41
+
42
+	}
43
+
44
+}
... ...
@@ -41,6 +41,7 @@ import java.util.concurrent.TimeoutException;
41 41
 import java.util.concurrent.atomic.AtomicInteger;
42 42
 import java.util.concurrent.atomic.AtomicReference;
43 43
 import java.util.function.Predicate;
44
+import java.util.stream.Collectors;
44 45
 
45 46
 import org.junit.After;
46 47
 import org.junit.Before;
... ...
@@ -1031,6 +1032,19 @@ public class ReplicationStackTests extends AbstractRollingReplicationTests {
1031 1032
 		List<Long> unread = itemsApi.unreadItems();
1032 1033
 		assertNotNull(unread);
1033 1034
 		System.err.println("Found " + unread.size() + " unread item(s).");
1035
+		assertFalse(unread.isEmpty());
1036
+		List<ItemValue<MailboxItem>> refetch = itemsApi.multipleById(unread);
1037
+		List<SeenUpdate> forUpdate = refetch.stream().map(iv -> SeenUpdate.of(iv.internalId, true, true))
1038
+				.collect(Collectors.toList());
1039
+		Ack ack = itemsApi.updateSeens(forUpdate);
1040
+		System.err.println("Got ack " + ack);
1041
+		refetch = itemsApi.multipleById(unread);
1042
+		unread = itemsApi.unreadItems();
1043
+		assertTrue(unread.isEmpty());
1044
+		for (ItemValue<MailboxItem> iv : refetch) {
1045
+			System.err.println("Delete " + iv);
1046
+			itemsApi.deleteById(iv.internalId);
1047
+		}
1034 1048
 	}
1035 1049
 
1036 1050
 	@Test
... ...
@@ -189,20 +189,20 @@ public class ImapMailboxRecordsService extends BaseMailboxRecordsService impleme
189 189
 				flagsUpdate(toDelete.value);
190 190
 			}
191 191
 		} else {
192
-			logger.warn("Nothing to delete.");
192
+			logger.warn("Nothing to delete for id {} in {}.", id, imapFolder);
193 193
 		}
194 194
 	}
195 195
 
196 196
 	@Override
197 197
 	public Ack updateById(long id, MailboxItem mail) {
198 198
 		if (mail.imapUid == 0) {
199
-			logger.warn("Nothing to update for imapUid 0");
199
+			logger.warn("Not updating {} with imapUid 0", id);
200 200
 			return Ack.create(0L);
201 201
 		}
202 202
 		// has the flags changed ?
203 203
 		ItemValue<MailboxItem> current = getCompleteById(id);
204 204
 		if (current.value.otherFlags.contains("$MDNSent") && !mail.otherFlags.contains("$MDNSent")) {
205
-			logger.info("cannot remove flag $MDNSent");
205
+			logger.info("cannot remove flag $MDNSent (on {})", id);
206 206
 			mail.otherFlags.add("$MDNSent");
207 207
 		}
208 208
 		String curFlags = flagsString(current.value);
... ...
@@ -221,7 +221,7 @@ public class ImapMailboxRecordsService extends BaseMailboxRecordsService impleme
221 221
 		} else if (flagsChanged) {
222 222
 			return flagsUpdate(mail);
223 223
 		} else {
224
-			logger.warn("Subject, headers or flags has not changed, doing nothing.");
224
+			logger.warn("Subject/Headers/Flags dit not change, doing nothing on {} {}.", id, mail);
225 225
 			return Ack.create(current.version);
226 226
 		}
227 227
 	}
... ...
@@ -239,7 +239,7 @@ public class ImapMailboxRecordsService extends BaseMailboxRecordsService impleme
239 239
 		Part currentStruct = current.value.body.structure;
240 240
 		Part expectedStruct = newValue.body.structure;
241 241
 		logger.info("Shoud go from:\n{} to\n{}", JsonUtils.asString(currentStruct), JsonUtils.asString(expectedStruct));
242
-		PartsWalker<Object> walker = new PartsWalker<Object>(null);
242
+		PartsWalker<Object> walker = new PartsWalker<>(null);
243 243
 		walker.visit((Object c, Part p) -> {
244 244
 			logger.info("Prepare for part @ {}", p.address);
245 245
 			if (isImapAddress(p.address)) {