summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap/bitmaskclient/testutils/answers/BackendAnswerFabric.java
blob: 00e276f4413b62f2e7855cfa1247cb6ab7ef29df (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
/**
 * Copyright (c) 2018 LEAP Encryption Access Project and contributers
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package se.leap.bitmaskclient.testutils.answers;

import org.mockito.stubbing.Answer;

/**
 * Created by cyberta on 09.01.18.
 */

public class BackendAnswerFabric {
    /**
     * This enum can be useful to provide different responses from a mocked ProviderApiConnector
     * in order to test different error scenarios
     */
    public enum TestBackendErrorCase {
        NO_ERROR,
        ERROR_NO_RESPONSE_BODY,         // => NullPointerException
        ERROR_DNS_RESOLUTION_ERROR,     // => UnkownHostException
        ERROR_SOCKET_TIMEOUT,           // => SocketTimeoutException
        ERROR_WRONG_PROTOCOL,           // => MalformedURLException
        ERROR_CERTIFICATE_INVALID,      // => SSLHandshakeException
        ERROR_WRONG_PORT,               // => ConnectException
        ERROR_PAYLOAD_MISSING,          // => IllegalArgumentException
        ERROR_TLS_1_2_NOT_SUPPORTED,    // => UnknownServiceException
        ERROR_UNKNOWN_IO_EXCEPTION,     // => IOException
        ERROR_NO_ACCESS,
        ERROR_INVALID_SESSION_TOKEN,
        ERROR_NO_CONNECTION,
        ERROR_WRONG_SRP_CREDENTIALS
    }

    public static Answer<String> getAnswerForErrorcase(TestBackendErrorCase errorCase) {
        switch (errorCase) {
            case NO_ERROR:
                return new NoErrorAnswer();
            case ERROR_NO_RESPONSE_BODY:
                break;
            case ERROR_DNS_RESOLUTION_ERROR:
                break;
            case ERROR_SOCKET_TIMEOUT:
                break;
            case ERROR_WRONG_PROTOCOL:
                break;
            case ERROR_CERTIFICATE_INVALID:
                break;
            case ERROR_WRONG_PORT:
                break;
            case ERROR_PAYLOAD_MISSING:
                break;
            case ERROR_TLS_1_2_NOT_SUPPORTED:
                break;
            case ERROR_UNKNOWN_IO_EXCEPTION:
                break;
            case ERROR_NO_ACCESS:
                break;
            case ERROR_INVALID_SESSION_TOKEN:
                break;
            case ERROR_NO_CONNECTION:
                break;
            case ERROR_WRONG_SRP_CREDENTIALS:
                break;
        }
        return null;
    }

}