tharak-android 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/README.md +1 -0
  2. package/build.gradle +45 -0
  3. package/consumer-rules.pro +0 -0
  4. package/libs/vital-sdk.aar +0 -0
  5. package/package.json +22 -0
  6. package/proguard-rules.pro +21 -0
  7. package/src/androidTest/androidTest.iml +11 -0
  8. package/src/androidTest/java/org/tharak/core/ExampleInstrumentedTest.java +27 -0
  9. package/src/androidTest/java/org/thiragatisoft/core/ExampleInstrumentedTest.java +26 -0
  10. package/src/main/AndroidManifest.xml +5 -0
  11. package/src/main/java/org/thiragatisoft/core/AppUtils.java +31 -0
  12. package/src/main/java/org/thiragatisoft/core/FileSelector.java +162 -0
  13. package/src/main/java/org/thiragatisoft/core/MainActivity.java +27 -0
  14. package/src/main/java/org/thiragatisoft/core/RestClient.java +298 -0
  15. package/src/main/java/org/thiragatisoft/core/VitalActivity.java +612 -0
  16. package/src/main/java/org/thiragatisoft/core/VitalsPlugin.java +15 -0
  17. package/src/main/java/org/thiragatisoft/core/VolleyMultipartRequest.java +218 -0
  18. package/src/main/java/org/thiragatisoft/core/http/CapacitorCookieManager.java +175 -0
  19. package/src/main/java/org/thiragatisoft/core/http/CapacitorHttpUrlConnection.java +408 -0
  20. package/src/main/java/org/thiragatisoft/core/http/FilesystemUtils.java +65 -0
  21. package/src/main/java/org/thiragatisoft/core/http/FormUploader.java +219 -0
  22. package/src/main/java/org/thiragatisoft/core/http/Http.java +275 -0
  23. package/src/main/java/org/thiragatisoft/core/http/HttpRequestHandler.java +515 -0
  24. package/src/main/java/org/thiragatisoft/core/http/ICapacitorHttpUrlConnection.java +15 -0
  25. package/src/main/java/org/thiragatisoft/core/http/JSValue.java +68 -0
  26. package/src/main/java/org/thiragatisoft/core/http/MimeType.java +17 -0
  27. package/src/main/main.iml +12 -0
  28. package/src/test/java/org/tharak/ExampleUnitTest.java +17 -0
  29. package/src/test/java/org/tharak/JSObjectTest.java +209 -0
  30. package/src/test/java/org/tharak/PluginMethodHandleTest.java +44 -0
  31. package/src/test/java/org/tharak/util/HostMaskTest.java +70 -0
  32. package/src/test/java/org/thiragatisoft/core/ExampleUnitTest.java +17 -0
  33. package/src/test/test.iml +11 -0
@@ -0,0 +1,209 @@
1
+ package com.getcapacitor;
2
+
3
+ import org.json.JSONException;
4
+ import org.junit.Test;
5
+
6
+ import static org.junit.Assert.*;
7
+
8
+ public class JSObjectTest {
9
+
10
+ @Test
11
+ public void getStringReturnsNull_WhenJSObject_IsConstructed_WithNoInitialJSONObject() {
12
+ JSObject jsObject = new JSObject();
13
+
14
+ String actualValue = jsObject.getString("should be null");
15
+
16
+ assertNull(actualValue);
17
+ }
18
+
19
+ @Test
20
+ public void getStringReturnsExpectedValue_WhenJSObject_IsConstructed_WithAValidJSONObject() throws JSONException {
21
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": \"this is the key value\"}");
22
+
23
+ String expectedValue = jsObject.getString("thisKeyExists");
24
+ String actualValue = "this is the key value";
25
+
26
+ assertEquals(expectedValue, actualValue);
27
+ }
28
+
29
+ @Test
30
+ public void getStringReturnsDefaultValue_WhenJSObject_IsConstructed_WithNoInitialJSONObject() throws JSONException {
31
+ JSObject jsObject = new JSObject();
32
+
33
+ String expectedValue = jsObject.getString("thisKeyDoesNotExist", "default value");
34
+ String actualValue = "default value";
35
+
36
+ assertEquals(expectedValue, actualValue);
37
+ }
38
+
39
+ @Test
40
+ public void getStringReturnsDefaultValue_WhenJSObject_IsConstructed_WithAValueAsInteger() throws JSONException {
41
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": 1}");
42
+
43
+ String expectedValue = jsObject.getString("thisKeyExists", "default value");
44
+ String actualValue = "default value";
45
+
46
+ assertEquals(expectedValue, actualValue);
47
+ }
48
+
49
+ @Test
50
+ public void getIntegerReturnsNull_WhenJSObject_IsConstructed_WithNoInitialJSONObject() {
51
+ JSObject jsObject = new JSObject();
52
+
53
+ Integer actualValue = jsObject.getInteger("should be null");
54
+
55
+ assertNull(actualValue);
56
+ }
57
+
58
+ @Test
59
+ public void getIntegerReturnsExpectedValue_WhenJSObject_IsConstructed_WithAValidJSONObject() throws JSONException {
60
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": 1}");
61
+
62
+ Integer expectedValue = jsObject.getInteger("thisKeyExists");
63
+ Integer actualValue = 1;
64
+
65
+ assertEquals(expectedValue, actualValue);
66
+ }
67
+
68
+ @Test
69
+ public void getIntegerReturnsDefaultValue_WhenJSObject_IsConstructed_WithNoInitialJSONObject() throws JSONException {
70
+ JSObject jsObject = new JSObject();
71
+
72
+ Integer expectedValue = jsObject.getInteger("thisKeyDoesNotExist", 1);
73
+ Integer actualValue = 1;
74
+
75
+ assertEquals(expectedValue, actualValue);
76
+ }
77
+
78
+ @Test
79
+ public void getStringReturnsDefaultValue_WhenJSObject_IsConstructed_WithAValueAsString() throws JSONException {
80
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": \"not an integer\"}");
81
+
82
+ Integer expectedValue = jsObject.getInteger("thisKeyExists", 1);
83
+ Integer actualValue = 1;
84
+
85
+ assertEquals(expectedValue, actualValue);
86
+ }
87
+
88
+ @Test
89
+ public void getBoolReturnsNull_WhenJSObject_IsConstructed_WithNoInitialJSONObject() {
90
+ JSObject jsObject = new JSObject();
91
+
92
+ Boolean actualValue = jsObject.getBool("should be null");
93
+
94
+ assertNull(actualValue);
95
+ }
96
+
97
+ @Test
98
+ public void getBoolReturnsExpectedValue_WhenJSObject_IsConstructed_WithAValidJSONObject() throws JSONException {
99
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": true}");
100
+
101
+ Boolean expectedValue = jsObject.getBool("thisKeyExists");
102
+ Boolean actualValue = true;
103
+
104
+ assertEquals(expectedValue, actualValue);
105
+ }
106
+
107
+ @Test
108
+ public void getBooleanReturnsDefaultValue_WhenJSObject_IsConstructed_WithNoInitialJSONObject() throws JSONException {
109
+ JSObject jsObject = new JSObject();
110
+
111
+ Boolean expectedValue = jsObject.getBoolean("thisKeyDoesNotExist", true);
112
+ Boolean actualValue = true;
113
+
114
+ assertEquals(expectedValue, actualValue);
115
+ }
116
+
117
+ @Test
118
+ public void getBooleanReturnsDefaultValue_WhenJSObject_IsConstructed_WithAValueAsString() throws JSONException {
119
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": \"not an integer\"}");
120
+
121
+ Boolean expectedValue = jsObject.getBoolean("thisKeyExists", true);
122
+ Boolean actualValue = true;
123
+
124
+ assertEquals(expectedValue, actualValue);
125
+ }
126
+
127
+ @Test
128
+ public void getJSObjectReturnsNull_WhenJSObject_IsConstructed_WithNoInitialJSONObject() {
129
+ JSObject jsObject = new JSObject();
130
+
131
+ JSObject actualValue = jsObject.getJSObject("should be null");
132
+
133
+ assertNull(actualValue);
134
+ }
135
+
136
+ @Test
137
+ public void getJsObjectReturnsExpectedValue_WhenJSObject_IsConstructed_WithAValidJSONObject() throws JSONException {
138
+ JSObject jsObject = new JSObject("{\"thisKeyExists\": { \"innerObjectKey\": \"innerObjectValue\" }}");
139
+
140
+ String actualValue = jsObject.getJSObject("thisKeyExists").getString("innerObjectKey");
141
+ String expectedValue = "innerObjectValue";
142
+
143
+ assertEquals(expectedValue, actualValue);
144
+ }
145
+
146
+ @Test
147
+ public void getJSObjectReturnsDefaultValue_WhenJSObject_IsConstructed_WithNoInitialJSONObject() throws JSONException {
148
+ JSObject jsObject = new JSObject();
149
+
150
+ String actualValue = jsObject.getJSObject("thisKeyExists", new JSObject("{\"thisKeyExists\": \"default string\"}")).getString("thisKeyExists");
151
+ String expectedValue = "default string";
152
+
153
+ assertEquals(expectedValue, actualValue);
154
+ }
155
+
156
+ @Test
157
+ public void putBoolean_AddsValueToJSObject_UnderCorrectKey() {
158
+ JSObject jsObject = new JSObject();
159
+ jsObject.put("bool", true);
160
+
161
+ Boolean actualValue = jsObject.getBool("bool");
162
+
163
+ assertTrue(actualValue);
164
+ }
165
+
166
+ @Test
167
+ public void putInteger_AddsValueToJSObject_UnderCorrectKey() {
168
+ JSObject jsObject = new JSObject();
169
+ jsObject.put("integer", 1);
170
+
171
+ Integer expectedValue = 1;
172
+ Integer actualValue = jsObject.getInteger("integer");
173
+
174
+ assertEquals(actualValue, expectedValue);
175
+ }
176
+
177
+ @Test
178
+ public void putLong_AddsValueToJSObject_UnderCorrectKey() throws JSONException {
179
+ JSObject jsObject = new JSObject();
180
+ jsObject.put("long", 1l);
181
+
182
+ Long expectedValue = 1l;
183
+ Long actualValue = jsObject.getLong("long");
184
+
185
+ assertEquals(actualValue, expectedValue);
186
+ }
187
+
188
+ @Test
189
+ public void putDouble_AddsValueToJSObject_UnderCorrectKey() throws JSONException {
190
+ JSObject jsObject = new JSObject();
191
+ jsObject.put("double", 1d);
192
+
193
+ Double expectedValue = 1d;
194
+ Double actualValue = jsObject.getDouble("double");
195
+
196
+ assertEquals(actualValue, expectedValue);
197
+ }
198
+
199
+ @Test
200
+ public void putString_AddsValueToJSObject_UnderCorrectKey() throws JSONException {
201
+ JSObject jsObject = new JSObject();
202
+ jsObject.put("string", "test");
203
+
204
+ String expectedValue = "test";
205
+ String actualValue = jsObject.getString("string");
206
+
207
+ assertEquals(actualValue, expectedValue);
208
+ }
209
+ }
@@ -0,0 +1,44 @@
1
+ package com.getcapacitor;
2
+
3
+ import org.junit.Test;
4
+
5
+ import java.lang.reflect.Method;
6
+
7
+ import static org.junit.Assert.assertEquals;
8
+ import static org.mockito.BDDMockito.given;
9
+ import static org.mockito.Mockito.mock;
10
+
11
+ public class PluginMethodHandleTest {
12
+ @Test
13
+ public void getNameReturnsMethodName() {
14
+ PluginMethod pluginMethod = mock(PluginMethod.class);
15
+ Method mockMethod = mock(Method.class);
16
+
17
+ given(mockMethod.getName()).willReturn("methodName");
18
+ PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod);
19
+
20
+ assertEquals(pluginMethodHandle.getName(), "methodName");
21
+ }
22
+
23
+ @Test
24
+ public void getMethodHandleReturnsMethodHandle() {
25
+ PluginMethod pluginMethod = mock(PluginMethod.class);
26
+ Method mockMethod = mock(Method.class);
27
+
28
+ given(pluginMethod.returnType()).willReturn("returnType");
29
+ PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod);
30
+
31
+ assertEquals(pluginMethodHandle.getReturnType(), "returnType");
32
+ }
33
+
34
+
35
+ @Test
36
+ public void getMethodReturnsMethod() {
37
+ PluginMethod pluginMethod = mock(PluginMethod.class);
38
+ Method mockMethod = mock(Method.class);
39
+
40
+ PluginMethodHandle pluginMethodHandle = new PluginMethodHandle(mockMethod, pluginMethod);
41
+
42
+ assertEquals(pluginMethodHandle.getMethod(), mockMethod);
43
+ }
44
+ }
@@ -0,0 +1,70 @@
1
+ package com.getcapacitor.util;
2
+
3
+ import static org.junit.Assert.*;
4
+
5
+ import org.junit.Test;
6
+
7
+ import com.getcapacitor.util.HostMask.Util;
8
+
9
+ public class HostMaskTest {
10
+
11
+ @Test
12
+ public void testParser() {
13
+ assertEquals(HostMask.Any.class, HostMask.Parser.parse("*,example.org,*.example.org".split(",")).getClass());
14
+ assertEquals(HostMask.Simple.class, HostMask.Parser.parse("*").getClass());
15
+ assertEquals(HostMask.Nothing.class, HostMask.Parser.parse((String) null).getClass());
16
+ }
17
+
18
+ @Test
19
+ public void testAny() {
20
+ HostMask mask = HostMask.Any.parse("*", "*.example.org", "example.org");
21
+ assertTrue(mask.matches("org"));
22
+ assertTrue(mask.matches("example.org"));
23
+ assertTrue(mask.matches("www.example.org"));
24
+ assertFalse(mask.matches("imap.mail.example.org"));
25
+ assertFalse(mask.matches("another.org"));
26
+ assertFalse(mask.matches("www.another.org"));
27
+ assertFalse(mask.matches(null));
28
+ }
29
+
30
+
31
+ @Test
32
+ public void testSimple() {
33
+ HostMask mask = HostMask.Simple.parse("*.org");
34
+ assertTrue(mask.matches("example.org"));
35
+ assertFalse(mask.matches("org"));
36
+ assertFalse(mask.matches("www.example.org"));
37
+ assertFalse("Null host never matches", mask.matches(null));
38
+ }
39
+
40
+ @Test
41
+ public void testSimpleExample1() {
42
+ HostMask mask = HostMask.Simple.parse("*.example.org");
43
+ assertFalse("Null host never matches", mask.matches("example.org"));
44
+ }
45
+
46
+ @Test
47
+ public void testSimpleExample2() {
48
+ HostMask mask = HostMask.Simple.parse("*");
49
+ assertFalse("Single star does not match with 2nd level domain", mask.matches("example.org"));
50
+ }
51
+
52
+ @Test
53
+ public void test192168ForLocalTestingSakes() {
54
+ HostMask mask = HostMask.Simple.parse("192.168.*.*");
55
+ assertTrue("Matches 192.168.*.*", mask.matches("192.168.2.5"));
56
+ assertFalse("Matches NOT 192.168.*.*", mask.matches("192.66.2.5"));
57
+ }
58
+
59
+ @Test
60
+ public void testUtil() {
61
+ assertTrue("Everything matches *", Util.matches("*", "*"));
62
+ assertTrue("Everything matches *", Util.matches("*", "org"));
63
+ assertTrue(Util.matches("org", "org"));
64
+ assertTrue("Match is case insensitive", Util.matches("ORG", "org"));
65
+ assertFalse("Nothing matches null mask", Util.matches(null, "org"));
66
+ assertFalse("Nothing matches null mask", Util.matches(null, null));
67
+ }
68
+
69
+
70
+ }
@@ -0,0 +1,17 @@
1
+ package org.thiragatisoft.core;
2
+
3
+ import org.junit.Test;
4
+
5
+ import static org.junit.Assert.*;
6
+
7
+ /**
8
+ * Example local unit test, which will execute on the development machine (host).
9
+ *
10
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11
+ */
12
+ public class ExampleUnitTest {
13
+ @Test
14
+ public void addition_isCorrect() {
15
+ assertEquals(4, 2 + 2);
16
+ }
17
+ }
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/java/org/tharak" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>