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

    @Test
    public void testIsPluggableTransportsSupported_Obfs4_returnsTrue() throws Exception {
        Provider p1 = TestSetupHelper.getProvider(
                "https://pt.demo.bitmask.net",
                null,
                null,
                null,
                null,
                "ptdemo.bitmask.eip-service.json");
        assertTrue(p1.supportsPluggableTransports());
    }

    @Test
    public void testIsPluggableTransportsSupported_noObfs4_returnsFalse() throws Exception {
        Provider p1 = TestSetupHelper.getProvider(
                null,
                null,
                null,
                null,
                null,
                "eip-service-two-gateways.json");
        assertFalse(p1.supportsPluggableTransports());
    }

}