1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import it.niedermann.nextcloud.deck.TestUtil;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.ocs.Capabilities;
import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DeckDatabaseTestUtil;
@RunWith(RobolectricTestRunner.class)
public class AccountDaoTest extends AbstractDaoTest {
@Test
public void testCreate() {
final Account accountToCreate = new Account();
accountToCreate.setName("test@example.com");
accountToCreate.setUserName("test");
accountToCreate.setUrl("https://example.com");
long id = db.getAccountDao().insert(accountToCreate);
final Account account = db.getAccountDao().getAccountByIdDirectly(id);
assertEquals("test", account.getUserName());
assertEquals("https://example.com", account.getUrl());
assertEquals(Integer.valueOf(Capabilities.DEFAULT_COLOR), account.getColor());
assertEquals(Integer.valueOf(Capabilities.DEFAULT_TEXT_COLOR), account.getTextColor());
assertEquals("0.6.4", account.getServerDeckVersion());
assertEquals("https://example.com/index.php/avatar/test/1337", account.getAvatarUrl(1337));
assertEquals(1, db.getAccountDao().countAccountsDirectly());
assertNull(account.getEtag());
assertFalse(account.isMaintenanceEnabled());
}
@Test
public void testGetAccountById() throws InterruptedException {
final Account account = DeckDatabaseTestUtil.createAccount(db.getAccountDao());
assertEquals(account.getName(), TestUtil.getOrAwaitValue(db.getAccountDao().getAccountById(account.getId())).getName());
}
@Test
public void testGetAccountByName() throws InterruptedException {
final Account account = DeckDatabaseTestUtil.createAccount(db.getAccountDao());
assertEquals(account.getUserName(), TestUtil.getOrAwaitValue(db.getAccountDao().getAccountByName(account.getName())).getUserName());
}
@Test
public void testGetAllAccounts() throws InterruptedException {
final int expectedCount = 13;
for (int i = 0; i < expectedCount; i++) {
DeckDatabaseTestUtil.createAccount(db.getAccountDao());
}
assertEquals(expectedCount, TestUtil.getOrAwaitValue(db.getAccountDao().getAllAccounts()).size());
}
@Test
public void testCountAccountsDirectly() {
final int expectedCount = 12;
for (int i = 0; i < expectedCount; i++) {
DeckDatabaseTestUtil.createAccount(db.getAccountDao());
}
assertEquals(expectedCount, db.getAccountDao().countAccountsDirectly());
}
@Test
public void testCountAccounts() throws InterruptedException {
final int expectedCount = 13;
for (int i = 0; i < expectedCount; i++) {
DeckDatabaseTestUtil.createAccount(db.getAccountDao());
}
assertEquals(Integer.valueOf(expectedCount), TestUtil.getOrAwaitValue(db.getAccountDao().countAccounts()));
}
@Test
public void testGetAllAccountsDirectly() {
final int expectedCount = 12;
for (int i = 0; i < expectedCount; i++) {
DeckDatabaseTestUtil.createAccount(db.getAccountDao());
}
assertEquals(expectedCount, db.getAccountDao().getAllAccountsDirectly().size());
}
@Test
public void testGetAccountByNameDirectly() {
final Account account = DeckDatabaseTestUtil.createAccount(db.getAccountDao());
assertEquals(account.getName(), db.getAccountDao().getAccountByNameDirectly(account.getName()).getName());
}
}
|