summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
blob: a141edec0c77efa2a0d1ed6a6a6cbe532fe1ec61 (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
package se.leap.bitmaskclient;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

import se.leap.bitmaskclient.testutils.TestSetupHelper;

import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * Created by cyberta on 12.02.18.
 */
public class ProviderTest {

    @Test
    public void testEquals_sameFields_returnsTrue() throws Exception {
        Provider p1 = TestSetupHelper.getConfiguredProvider();
        Provider p2 = TestSetupHelper.getConfiguredProvider();
        assertTrue("Providers should be same:", p1.equals(p2));
    }

    @Test
    public void testEquals_sameFields_returnsFalse() throws Exception {
        Provider p1 = TestSetupHelper.getConfiguredProvider();
        Provider p2 = TestSetupHelper.getConfiguredProvider();
        p2.setMainUrl("http://somethingsdiffer.org");
        assertFalse("Providers should be same:", p1.equals(p2));
    }

    // see ProviderManagerTest testing add(...)
    @Test
    public void testEqualsThroughSetContains_differentFields_returnsFalse() throws Exception {
        Provider p1 = TestSetupHelper.getConfiguredProvider();
        Provider p2 = TestSetupHelper.getConfiguredProvider();
        p2.setMainUrl("http://somethingsdiffer.org");
        Provider p3 = new Provider("https://anotherprovider.net");

        Set<Provider> defaultProviders = new HashSet<>();
        defaultProviders.add(p1);
        defaultProviders.add(p2);

        assertTrue(defaultProviders.contains(p1));
        assertTrue(defaultProviders.contains(p2));
        assertFalse(defaultProviders.contains(p3));
    }
}