Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AccountDaoTest.java « dao « db « adapters « sync « persistence « deck « nextcloud « niedermann « it « java « test « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a65756df3e1680451a36b9721cd241e4f77cb4cc (plain)
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
package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

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;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

@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(), DeckDatabaseTestUtil.getOrAwaitValue(db.getAccountDao().getAccountById(account.getId())).getName());
    }

    @Test
    public void testGetAccountByName() throws InterruptedException {
        final Account account = DeckDatabaseTestUtil.createAccount(db.getAccountDao());
        assertEquals(account.getUserName(), DeckDatabaseTestUtil.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, DeckDatabaseTestUtil.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), DeckDatabaseTestUtil.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());
    }
}