summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-07-12 13:28:36 +0200
committercyBerta <cyberta@riseup.net>2019-07-12 13:28:36 +0200
commit5ea927f89626cef98495b5fead628cdc01d2a39a (patch)
treeb1090debfa1adbd441f7b07a86027acffde27e28 /app/src/test
parentc5b4f58834c61b11310e443d8852f744a3ae48c3 (diff)
replace 'Bitmask' in strings with variable for a better client customization
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java33
-rw-r--r--app/src/test/resources/error_messages.json12
2 files changed, 25 insertions, 20 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
index c765ab1b..fa9f9252 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
@@ -46,6 +46,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -373,6 +374,7 @@ public class MockHelper {
when(ConfigHelper.getFingerprintFromCertificate(any(X509Certificate.class), anyString())).thenReturn(mockedFingerprint);
when(ConfigHelper.checkErroneousDownload(anyString())).thenCallRealMethod();
when(ConfigHelper.parseX509CertificateFromString(anyString())).thenCallRealMethod();
+ when(ConfigHelper.getProviderFormattedString(any(Resources.class), anyInt())).thenCallRealMethod();
}
public static void mockPreferenceHelper(final Provider providerFromPrefs) {
@@ -402,6 +404,7 @@ public class MockHelper {
when(ConfigHelper.getFingerprintFromCertificate(any(X509Certificate.class), anyString())).thenReturn(mockedFingerprint);
when(ConfigHelper.checkErroneousDownload(anyString())).thenCallRealMethod();
when(ConfigHelper.parseX509CertificateFromString(anyString())).thenCallRealMethod();
+ when(ConfigHelper.getProviderFormattedString(any(Resources.class), anyInt())).thenCallRealMethod();
}
public static void mockProviderApiConnector(final BackendMockProvider.TestBackendErrorCase errorCase) throws IOException {
@@ -421,16 +424,16 @@ public class MockHelper {
JSONObject errorMessages = new JSONObject(TestSetupHelper.getInputAsString(inputStream));
- when(mockedResources.getString(R.string.warning_corrupted_provider_details)).
- thenReturn(errorMessages.getString("warning_corrupted_provider_details"));
+ when(mockedResources.getString(eq(R.string.warning_corrupted_provider_details), anyString())).
+ thenReturn(String.format(errorMessages.getString("warning_corrupted_provider_details"), "Bitmask"));
when(mockedResources.getString(R.string.server_unreachable_message)).
thenReturn(errorMessages.getString("server_unreachable_message"));
when(mockedResources.getString(R.string.error_security_pinnedcertificate)).
thenReturn(errorMessages.getString("error.security.pinnedcertificate"));
- when(mockedResources.getString(R.string.malformed_url)).
- thenReturn(errorMessages.getString("malformed_url"));
- when(mockedResources.getString(R.string.certificate_error)).
- thenReturn(errorMessages.getString("certificate_error"));
+ when(mockedResources.getString(eq(R.string.malformed_url), anyString())).
+ thenReturn(String.format(errorMessages.getString("malformed_url"), "Bitmask"));
+ when(mockedResources.getString(eq(R.string.certificate_error), anyString())).
+ thenReturn(String.format(errorMessages.getString("certificate_error"), "Bitmask"));
when(mockedResources.getString(R.string.error_srp_math_error_user_message)).
thenReturn(errorMessages.getString("error_srp_math_error_user_message"));
when(mockedResources.getString(R.string.error_bad_user_password_user_message)).
@@ -445,14 +448,16 @@ public class MockHelper {
thenReturn(errorMessages.getString("error_json_exception_user_message"));
when(mockedResources.getString(R.string.error_no_such_algorithm_exception_user_message)).
thenReturn(errorMessages.getString("error_no_such_algorithm_exception_user_message"));
- when(mockedResources.getString(R.string.warning_corrupted_provider_details)).
- thenReturn(errorMessages.getString("warning_corrupted_provider_details"));
- when(mockedResources.getString(R.string.warning_corrupted_provider_cert)).
- thenReturn(errorMessages.getString("warning_corrupted_provider_cert"));
- when(mockedResources.getString(R.string.warning_expired_provider_cert)).
- thenReturn(errorMessages.getString("warning_expired_provider_cert"));
- when(mockedResources.getString(R.string.setup_error_text)).
- thenReturn(errorMessages.getString("setup_error_text"));
+ when(mockedResources.getString(eq(R.string.warning_corrupted_provider_details), anyString())).
+ thenReturn(String.format(errorMessages.getString("warning_corrupted_provider_details"), "Bitmask"));
+ when(mockedResources.getString(eq(R.string.warning_corrupted_provider_cert), anyString())).
+ thenReturn(String.format(errorMessages.getString("warning_corrupted_provider_cert"), "Bitmask"));
+ when(mockedResources.getString(eq(R.string.warning_expired_provider_cert), anyString())).
+ thenReturn(String.format(errorMessages.getString("warning_expired_provider_cert"), "Bitmask"));
+ when(mockedResources.getString(eq(R.string.setup_error_text), anyString())).
+ thenReturn(String.format(errorMessages.getString("setup_error_text"), "Bitmask"));
+ when(mockedResources.getString(R.string.app_name)).
+ thenReturn("Bitmask");
return mockedResources;
}
}
diff --git a/app/src/test/resources/error_messages.json b/app/src/test/resources/error_messages.json
index 8430d9e0..e3b92d78 100644
--- a/app/src/test/resources/error_messages.json
+++ b/app/src/test/resources/error_messages.json
@@ -1,8 +1,8 @@
{
"server_unreachable_message": "Server is unreachable, please try again.",
"error.security.pinnedcertificate": "Security error, update the app or choose another provider.",
- "malformed_url": "It doesn't seem to be a Bitmask provider.",
- "certificate_error": "This is not a trusted Bitmask provider.",
+ "malformed_url": "It doesn't seem to be a %s provider.",
+ "certificate_error": "This is not a trusted %s provider.",
"error_srp_math_error_user_message": "Try again: server math error.",
"error_bad_user_password_user_message": "Incorrect username or password.",
"error_not_valid_password_user_message": "It should have at least 8 characters.",
@@ -10,8 +10,8 @@
"error_io_exception_user_message": "Try again: I/O error",
"error_json_exception_user_message": "Try again: Bad response from the server",
"error_no_such_algorithm_exception_user_message": "Encryption algorithm not found. Please update your OS!",
- "warning_corrupted_provider_details": "Stored provider details are corrupted. You can either update Bitmask (recommended) or update the provider details using a commercial CA certificate.",
- "warning_corrupted_provider_cert": "Stored provider certificate is invalid. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.",
- "warning_expired_provider_cert": "Stored provider certificate is expired. You can either update Bitmask (recommended) or update the provider certificate using a commercial CA certificate.",
- "setup_error_text": "There was an error configuring Bitmask with your chosen provider."
+ "warning_corrupted_provider_details": "Stored provider details are corrupted. You can either update %s (recommended) or update the provider details using a commercial CA certificate.",
+ "warning_corrupted_provider_cert": "Stored provider certificate is invalid. You can either update %s (recommended) or update the provider certificate using a commercial CA certificate.",
+ "warning_expired_provider_cert": "Stored provider certificate is expired. You can either update %s (recommended) or update the provider certificate using a commercial CA certificate.",
+ "setup_error_text": "There was an error configuring %s with your chosen provider."
} \ No newline at end of file