Skip to content

Commit ba307dc

Browse files
committed
add coverage for API builder
1 parent e91b7b6 commit ba307dc

File tree

3 files changed

+183
-15
lines changed

3 files changed

+183
-15
lines changed

gradlew.bat

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@if "%DEBUG%" == "" @echo off
2+
@rem ##########################################################################
3+
@rem
4+
@rem Gradle startup script for Windows
5+
@rem
6+
@rem ##########################################################################
7+
8+
@rem Set local scope for the variables with windows NT shell
9+
if "%OS%"=="Windows_NT" setlocal
10+
11+
set DIRNAME=%~dp0
12+
if "%DIRNAME%" == "" set DIRNAME=.
13+
set APP_BASE_NAME=%~n0
14+
set APP_HOME=%DIRNAME%
15+
16+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17+
set DEFAULT_JVM_OPTS="-Xmx64m"
18+
19+
@rem Find java.exe
20+
if defined JAVA_HOME goto findJavaFromJavaHome
21+
22+
set JAVA_EXE=java.exe
23+
%JAVA_EXE% -version >NUL 2>&1
24+
if "%ERRORLEVEL%" == "0" goto init
25+
26+
echo.
27+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28+
echo.
29+
echo Please set the JAVA_HOME variable in your environment to match the
30+
echo location of your Java installation.
31+
32+
goto fail
33+
34+
:findJavaFromJavaHome
35+
set JAVA_HOME=%JAVA_HOME:"=%
36+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37+
38+
if exist "%JAVA_EXE%" goto init
39+
40+
echo.
41+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42+
echo.
43+
echo Please set the JAVA_HOME variable in your environment to match the
44+
echo location of your Java installation.
45+
46+
goto fail
47+
48+
:init
49+
@rem Get command-line arguments, handling Windows variants
50+
51+
if not "%OS%" == "Windows_NT" goto win9xME_args
52+
53+
:win9xME_args
54+
@rem Slurp the command line arguments.
55+
set CMD_LINE_ARGS=
56+
set _SKIP=2
57+
58+
:win9xME_args_slurp
59+
if "x%~1" == "x" goto execute
60+
61+
set CMD_LINE_ARGS=%*
62+
63+
:execute
64+
@rem Setup the command line
65+
66+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67+
68+
@rem Execute Gradle
69+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70+
71+
:end
72+
@rem End local scope for the variables with windows NT shell
73+
if "%ERRORLEVEL%"=="0" goto mainEnd
74+
75+
:fail
76+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77+
rem the _cmd.exe /c_ return code!
78+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79+
exit /b 1
80+
81+
:mainEnd
82+
if "%OS%"=="Windows_NT" endlocal
83+
84+
:omega

src/main/java/ug/sparkpl/momoapi/network/RequestOptions.java

+72-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class RequestOptions {
2424
private final String TARGET_ENVIRONMENT;
2525
private final String CURRENCY;
2626

27-
2827
public RequestOptions(String COLLECTION_API_SECRET, String COLLECTION_PRIMARY_KEY, String COLLECTION_USER_ID, String REMITTANCE_USER_ID, String REMITTANCE_PRIMARY_KEY, String REMITTANCE_API_SECRET, String DISBURSEMENT_API_SECRET, String DISBURSEMENT_PRIMARY_KEY, String DISBURSEMENT_USER_ID, String BASE_URL, String TARGET_ENVIRONMENT, String CURRENCY) {
2928

3029
this.COLLECTION_API_SECRET = COLLECTION_API_SECRET;
@@ -49,6 +48,22 @@ public static Builder builder() {
4948
return new Builder();
5049
}
5150

51+
public Builder toBuilder() {
52+
return new Builder()
53+
.setCollectionPrimaryKey(this.COLLECTION_PRIMARY_KEY)
54+
.setCollectionApiSecret(this.COLLECTION_API_SECRET)
55+
.setCollectionUserId(this.COLLECTION_USER_ID)
56+
.setCurrency(this.CURRENCY)
57+
.setBaseUrl(this.BASE_URL)
58+
.setTargetEnvironment(this.TARGET_ENVIRONMENT)
59+
.setDisbursementApiSecret(this.DISBURSEMENT_API_SECRET)
60+
.setDisbursementPrimaryKey(this.DISBURSEMENT_PRIMARY_KEY)
61+
.setDisbursementUserId(this.DISBURSEMENT_USER_ID)
62+
.setRemittanceApiSecret(this.REMITTANCE_API_SECRET)
63+
.setRemittancePrimaryKey(this.REMITTANCE_PRIMARY_KEY)
64+
.setRemittanceUserId(this.REMITTANCE_USER_ID);
65+
66+
}
5267

5368
public String getCollectionUserId() {
5469
return this.COLLECTION_USER_ID;
@@ -149,67 +164,113 @@ private static String normalizeKey(String key) {
149164
return normalized;
150165
}
151166

167+
public String getCollectionPrimaryKey() {
168+
return this.COLLECTION_PRIMARY_KEY;
169+
}
170+
171+
public Builder setCollectionPrimaryKey(String collectionPrimaryKey) {
172+
this.COLLECTION_PRIMARY_KEY = collectionPrimaryKey;
173+
return this;
174+
}
175+
176+
public String getCollectionUserId() {
177+
return this.COLLECTION_USER_ID;
178+
}
152179

153180
public Builder setCollectionUserId(String collectionUserId) {
154181
this.COLLECTION_USER_ID = collectionUserId;
155182
return this;
156183
}
157184

185+
public String getCollectionApiSecret() {
186+
return this.COLLECTION_API_SECRET;
187+
}
188+
158189
public Builder setCollectionApiSecret(String collectionApiSecret) {
159190
this.COLLECTION_API_SECRET = collectionApiSecret;
160191
return this;
161192
}
162193

163-
public Builder setCollectionPrimaryKey(String collectionPrimaryKey) {
164-
this.COLLECTION_PRIMARY_KEY = collectionPrimaryKey;
194+
public String getRemittancePrimaryKey() {
195+
return this.REMITTANCE_PRIMARY_KEY;
196+
}
197+
198+
public Builder setRemittancePrimaryKey(String remittancePrimaryKey) {
199+
this.REMITTANCE_PRIMARY_KEY = remittancePrimaryKey;
165200
return this;
166201
}
167202

203+
public String getRemittanceUserId() {
204+
return REMITTANCE_USER_ID;
205+
}
206+
168207
public Builder setRemittanceUserId(String remittanceUserId) {
169208
this.REMITTANCE_USER_ID = remittanceUserId;
170209
return this;
171210
}
172211

212+
public String getRemittanceApiSecret() {
213+
return this.REMITTANCE_API_SECRET;
214+
}
215+
173216
public Builder setRemittanceApiSecret(String remittanceApiSecret) {
174217
this.REMITTANCE_API_SECRET = remittanceApiSecret;
175218
return this;
176219
}
177220

178-
public Builder setRemittancePrimaryKey(String remittancePrimaryKey) {
179-
this.REMITTANCE_PRIMARY_KEY = remittancePrimaryKey;
221+
public String getDisbursementPrimaryKey() {
222+
return this.DISBURSEMENT_PRIMARY_KEY;
223+
}
224+
225+
public Builder setDisbursementPrimaryKey(String disbursementPrimaryKey) {
226+
this.DISBURSEMENT_PRIMARY_KEY = disbursementPrimaryKey;
180227
return this;
181228
}
182229

230+
public String getDisbursementUserId() {
231+
return this.DISBURSEMENT_USER_ID;
232+
}
233+
183234
public Builder setDisbursementUserId(String disbursementUserId) {
184235
this.DISBURSEMENT_USER_ID = disbursementUserId;
185236
return this;
186237
}
187238

239+
public String getDisbursementApiSecret() {
240+
return this.DISBURSEMENT_API_SECRET;
241+
}
242+
188243
public Builder setDisbursementApiSecret(String disbursementApiSecret) {
189244
this.DISBURSEMENT_API_SECRET = disbursementApiSecret;
190245
return this;
191246
}
192247

193-
public Builder setDisbursementPrimaryKey(String disbursementPrimaryKey) {
194-
this.DISBURSEMENT_PRIMARY_KEY = disbursementPrimaryKey;
195-
return this;
248+
public String getBaseUrl() {
249+
return this.BASE_URL;
196250
}
197251

198252
public Builder setBaseUrl(String url) {
199253
this.BASE_URL = url;
200254
return this;
201255
}
202256

203-
public Builder setCurrency(String currency) {
204-
this.CURRENCY = CURRENCY;
205-
return this;
257+
public String getTargetEnvironment() {
258+
return this.TARGET_ENVIRONMENT;
206259
}
207260

208261
public Builder setTargetEnvironment(String environment) {
209262
this.TARGET_ENVIRONMENT = environment;
210263
return this;
211264
}
212265

266+
public String getCurrency() {
267+
return this.CURRENCY;
268+
}
269+
270+
public Builder setCurrency(String currency) {
271+
this.CURRENCY = currency;
272+
return this;
273+
}
213274

214275
public RequestOptions build() {
215276
return new RequestOptions(

src/test/java/ug/sparkpl/network/RequestOptionsTest.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,39 @@ public class RequestOptionsTest {
99

1010
@Test
1111
public void testPersistentValuesInToBuilder() {
12-
RequestOptions opts = RequestOptions.builder()
12+
RequestOptions.Builder opts = RequestOptions.builder()
1313
.setCollectionApiSecret("sec")
1414
.setCollectionPrimaryKey("123")
15-
.setCollectionUserId("1234").build();
15+
.setCollectionUserId("1234")
16+
.setCurrency("UGX")
17+
.setTargetEnvironment("test")
18+
.setBaseUrl("new_base")
19+
.setRemittanceUserId("remituid")
20+
.setRemittancePrimaryKey("remKey")
21+
.setRemittanceApiSecret("remSecret")
22+
.setDisbursementUserId("duid")
23+
.setRemittanceApiSecret("dSecret")
24+
.setRemittancePrimaryKey("dKey")
25+
.build().toBuilder();
1626

1727

1828
// assuming these are stable across a given stripe integration
19-
assertEquals("sec", opts.getCollectionApiSecret());
29+
2030
assertEquals("123", opts.getCollectionPrimaryKey());
21-
assertEquals("1234", opts.getRemittanceUserId());
31+
assertEquals("sec", opts.getCollectionApiSecret());
32+
assertEquals("1234", opts.getCollectionUserId());
33+
assertEquals("UGX", opts.getCurrency());
34+
assertEquals("test", opts.getTargetEnvironment());
35+
assertEquals("UGX", opts.getCurrency());
36+
assertEquals("new_base", opts.getBaseUrl());
37+
assertEquals("remituid", opts.getRemittanceUserId());
38+
assertEquals("remKey", opts.getRemittancePrimaryKey());
39+
assertEquals("remSecret", opts.getRemittanceApiSecret());
40+
assertEquals("dKey", opts.getDisbursementPrimaryKey());
41+
assertEquals("dSecret", opts.getDisbursementApiSecret());
42+
assertEquals("duid", opts.getDisbursementUserId());
43+
44+
2245
}
2346

2447
}

0 commit comments

Comments
 (0)