45
45
*/
46
46
public class TestUtilities {
47
47
48
+ private static final String GIT_COMMAND = "git" ;
49
+ private static final char [] CHARS = "abcdefghijklmnopqrstuvwxyz" .toCharArray ();
50
+
48
51
private static User defaultUser ;
49
52
50
53
/**
@@ -69,7 +72,7 @@ public static synchronized User getDefaultUser(final String credential, final Bi
69
72
final UserPage userPage = api .adminApi ().listUsers (username , null , null );
70
73
assertThat (userPage ).isNotNull ();
71
74
assertThat (userPage .size () > 0 ).isTrue ();
72
- for (User user : userPage .values ()) {
75
+ for (final User user : userPage .values ()) {
73
76
if (username .equals (user .slug ())) {
74
77
defaultUser = user ;
75
78
break ;
@@ -108,7 +111,7 @@ public static String executionToString(final List<String> args, final Path worki
108
111
* @return Path pointing at generated file.
109
112
* @throws Exception if file could not be written.
110
113
*/
111
- public static Path initGeneratedFile (Path baseDir ) throws Exception {
114
+ public static Path initGeneratedFile (final Path baseDir ) throws Exception {
112
115
assertThat (baseDir ).isNotNull ();
113
116
assertThat (baseDir .toFile ().isDirectory ()).isTrue ();
114
117
@@ -188,7 +191,7 @@ public static synchronized GeneratedTestContents initGeneratedTestContents(final
188
191
189
192
generateGitContentsAndPush (generatedFileDir , generatedEndpoint );
190
193
191
- } catch (Exception e ) {
194
+ } catch (final Exception e ) {
192
195
throw Throwables .propagate (e );
193
196
}
194
197
@@ -202,48 +205,55 @@ public static synchronized GeneratedTestContents initGeneratedTestContents(final
202
205
* @param gitRepoURL git repository URL with embedded credentials.
203
206
* @throws Exception if git repository could not be created or files added.
204
207
*/
205
- public static void generateGitContentsAndPush (File gitDirectory , String gitRepoURL ) throws Exception {
208
+ public static void generateGitContentsAndPush (final File gitDirectory , final String gitRepoURL ) throws Exception {
206
209
207
210
// 1.) initialize git repository
208
- String initGit = TestUtilities .executionToString (Arrays .asList ("git" , "init" ), gitDirectory .toPath ());
211
+ final String initGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "init" ), gitDirectory .toPath ());
209
212
System .out .println ("git-init: " + initGit .trim ());
210
213
211
214
// 2.) create some random files and commit them
212
215
for (int i = 0 ; i < 3 ; i ++) {
213
216
Path genFile = initGeneratedFile (gitDirectory .toPath ());
214
- String addGit = TestUtilities .executionToString (Arrays .asList ("git" , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
217
+ String addGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
215
218
System .out .println ("git-add-1: " + addGit .trim ());
216
- String commitGit = TestUtilities .executionToString (Arrays .asList ("git" , "commit" , "-m" , "added" ), gitDirectory .toPath ());
219
+ String commitGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "commit" , "-m" , "added" ), gitDirectory .toPath ());
217
220
System .out .println ("git-commit-1: " + commitGit .trim ());
218
221
219
222
// edit file again and create another commit
220
223
genFile = Files .write (genFile , Arrays .asList (randomString ()), Charset .forName ("UTF-8" ));
221
- addGit = TestUtilities .executionToString (Arrays .asList ("git" , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
224
+ addGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
222
225
System .out .println ("git-add-2: " + addGit .trim ());
223
- commitGit = TestUtilities .executionToString (Arrays .asList ("git" , "commit" , "-m" , "added" ), gitDirectory .toPath ());
226
+ commitGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "commit" , "-m" , "added" ), gitDirectory .toPath ());
224
227
System .out .println ("git-commit-2: " + commitGit .trim ());
225
228
}
226
229
227
230
// 3.) push changes to remote repository
228
- String pushGit = TestUtilities .executionToString (Arrays .asList ("git" , "push" , "--set-upstream" , gitRepoURL , "master" ), gitDirectory .toPath ());
231
+ final String pushGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND ,
232
+ "push" ,
233
+ "--set-upstream" ,
234
+ gitRepoURL ,
235
+ "master" ), gitDirectory .toPath ());
229
236
System .out .println ("git-push: " + pushGit );
230
237
231
238
// 4.) create branch
232
- String generatedBranchName = randomString ();
233
- String branchGit = TestUtilities .executionToString (Arrays .asList ("git" , "checkout" , "-b" , generatedBranchName ), gitDirectory .toPath ());
239
+ final String generatedBranchName = randomString ();
240
+ final String branchGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND ,
241
+ "checkout" , "-b" ,
242
+ generatedBranchName ),
243
+ gitDirectory .toPath ());
234
244
System .out .println ("git-branch: " + branchGit .trim ());
235
245
236
246
237
247
// 5.) generate random file for new branch
238
- Path genFile = initGeneratedFile (gitDirectory .toPath ());
239
- String addGit = TestUtilities .executionToString (Arrays .asList ("git" , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
248
+ final Path genFile = initGeneratedFile (gitDirectory .toPath ());
249
+ final String addGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "add" , genFile .toFile ().getPath ()), gitDirectory .toPath ());
240
250
System .out .println ("git-branch-add: " + addGit .trim ());
241
- String commitGit = TestUtilities .executionToString (Arrays .asList ("git" , "commit" , "-m" , "added" ), gitDirectory .toPath ());
251
+ final String commitGit = TestUtilities .executionToString (Arrays .asList (GIT_COMMAND , "commit" , "-m" , "added" ), gitDirectory .toPath ());
242
252
System .out .println ("git-branch-commit: " + commitGit .trim ());
243
253
244
254
// 6.) push branch
245
- List <String > args = Arrays .asList ("git" , "push" , "-u" , gitRepoURL , generatedBranchName );
246
- String pushBranchGit = TestUtilities .executionToString (args , gitDirectory .toPath ());
255
+ final List <String > args = Arrays .asList (GIT_COMMAND , "push" , "-u" , gitRepoURL , generatedBranchName );
256
+ final String pushBranchGit = TestUtilities .executionToString (args , gitDirectory .toPath ());
247
257
System .out .println ("git-branch-push: " + pushBranchGit );
248
258
}
249
259
@@ -253,7 +263,8 @@ public static void generateGitContentsAndPush(File gitDirectory, String gitRepoU
253
263
* @param api BitbucketApi object
254
264
* @param generatedTestContents to terminate.
255
265
*/
256
- public static synchronized void terminateGeneratedTestContents (final BitbucketApi api , final GeneratedTestContents generatedTestContents ) {
266
+ public static synchronized void terminateGeneratedTestContents (final BitbucketApi api ,
267
+ final GeneratedTestContents generatedTestContents ) {
257
268
assertThat (api ).isNotNull ();
258
269
assertThat (generatedTestContents ).isNotNull ();
259
270
@@ -281,11 +292,10 @@ public static synchronized void terminateGeneratedTestContents(final BitbucketAp
281
292
* @return random String.
282
293
*/
283
294
public static String randomStringLettersOnly () {
284
- char [] chars = "abcdefghijklmnopqrstuvwxyz" .toCharArray ();
285
- StringBuilder sb = new StringBuilder ();
286
- Random random = new Random ();
295
+ final StringBuilder sb = new StringBuilder ();
296
+ final Random random = new Random ();
287
297
for (int i = 0 ; i < 10 ; i ++) {
288
- char randomChar = chars [random .nextInt (chars .length )];
298
+ final char randomChar = CHARS [random .nextInt (CHARS .length )];
289
299
sb .append (randomChar );
290
300
}
291
301
return sb .toString ().toUpperCase ();
0 commit comments