2424import static org .junit .Assume .assumeFalse ;
2525import static org .junit .Assume .assumeTrue ;
2626
27+ // TODO: Auto-generated Javadoc
2728/**
29+ * The Class AbstractGitHubWireMockTest.
30+ *
2831 * @author Liam Newman
2932 */
3033public abstract class AbstractGitHubWireMockTest {
3134
3235 private final GitHubBuilder githubBuilder = createGitHubBuilder ();
3336
37+ /** The Constant GITHUB_API_TEST_ORG. */
3438 final static String GITHUB_API_TEST_ORG = "hub4j-test-org" ;
3539
40+ /** The Constant STUBBED_USER_LOGIN. */
3641 final static String STUBBED_USER_LOGIN = "placeholder-user" ;
42+
43+ /** The Constant STUBBED_USER_PASSWORD. */
3744 final static String STUBBED_USER_PASSWORD = "placeholder-password" ;
3845
46+ /** The use default git hub. */
3947 protected boolean useDefaultGitHub = true ;
4048
49+ /** The temp git hub repositories. */
4150 protected final Set <String > tempGitHubRepositories = new HashSet <>();
4251
4352 /**
@@ -47,18 +56,31 @@ public abstract class AbstractGitHubWireMockTest {
4756
4857 private GitHub nonRecordingGitHub ;
4958
59+ /** The base files class path. */
5060 protected final String baseFilesClassPath = this .getClass ().getName ().replace ('.' , '/' );
61+
62+ /** The base record path. */
5163 protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock" ;
5264
65+ /** The mock git hub. */
5366 @ Rule
5467 public final GitHubWireMockRule mockGitHub ;
5568
69+ /** The templating. */
5670 protected final TemplatingHelper templating = new TemplatingHelper ();
5771
72+ /**
73+ * Instantiates a new abstract git hub wire mock test.
74+ */
5875 public AbstractGitHubWireMockTest () {
5976 mockGitHub = new GitHubWireMockRule (this .getWireMockOptions ());
6077 }
6178
79+ /**
80+ * Gets the wire mock options.
81+ *
82+ * @return the wire mock options
83+ */
6284 protected WireMockConfiguration getWireMockOptions () {
6385 return WireMockConfiguration .options ().dynamicPort ().usingFilesUnderDirectory (baseRecordPath );
6486 }
@@ -93,6 +115,11 @@ private static GitHubBuilder createGitHubBuilder() {
93115 return builder .withRateLimitHandler (RateLimitHandler .FAIL );
94116 }
95117
118+ /**
119+ * Gets the git hub builder.
120+ *
121+ * @return the git hub builder
122+ */
96123 protected GitHubBuilder getGitHubBuilder () {
97124 GitHubBuilder builder = githubBuilder .clone ();
98125
@@ -106,6 +133,11 @@ protected GitHubBuilder getGitHubBuilder() {
106133 return builder ;
107134 }
108135
136+ /**
137+ * Wire mock setup.
138+ *
139+ * @throws Exception the exception
140+ */
109141 @ Before
110142 public void wireMockSetup () throws Exception {
111143 GitHubBuilder builder = getGitHubBuilder ().withEndpoint (mockGitHub .apiServer ().baseUrl ());
@@ -121,27 +153,51 @@ public void wireMockSetup() throws Exception {
121153 }
122154 }
123155
156+ /**
157+ * Snapshot not allowed.
158+ */
124159 protected void snapshotNotAllowed () {
125160 assumeFalse ("Test contains hand written mappings. Only valid when not taking a snapshot." ,
126161 mockGitHub .isTakeSnapshot ());
127162 }
128163
164+ /**
165+ * Require proxy.
166+ *
167+ * @param reason the reason
168+ */
129169 protected void requireProxy (String reason ) {
130170 assumeTrue ("Test only valid when proxying (-Dtest.github.useProxy to enable): " + reason ,
131171 mockGitHub .isUseProxy ());
132172 }
133173
174+ /**
175+ * Verify authenticated.
176+ *
177+ * @param instance the instance
178+ */
134179 protected void verifyAuthenticated (GitHub instance ) {
135180 assertThat (
136181 "GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_LOGIN and GITHUB_PASSWORD environment variables" ,
137182 instance .isAnonymous (),
138183 Matchers .is (false ));
139184 }
140185
186+ /**
187+ * Gets the user.
188+ *
189+ * @return the user
190+ */
141191 protected GHUser getUser () {
142192 return getUser (gitHub );
143193 }
144194
195+ /**
196+ * Gets the user.
197+ *
198+ * @param gitHub the git hub
199+ * @return the user
200+ */
145201 protected static GHUser getUser (GitHub gitHub ) {
146202 try {
147203 return gitHub .getMyself ();
@@ -196,6 +252,11 @@ protected GHRepository getTempRepository(String name) throws IOException {
196252 return gitHub .getRepository (fullName );
197253 }
198254
255+ /**
256+ * Cleanup temp repositories.
257+ *
258+ * @throws IOException Signals that an I/O exception has occurred.
259+ */
199260 @ Before
200261 @ After
201262 public void cleanupTempRepositories () throws IOException {
@@ -206,6 +267,12 @@ public void cleanupTempRepositories() throws IOException {
206267 }
207268 }
208269
270+ /**
271+ * Cleanup repository.
272+ *
273+ * @param fullName the full name
274+ * @throws IOException Signals that an I/O exception has occurred.
275+ */
209276 protected void cleanupRepository (String fullName ) throws IOException {
210277 if (mockGitHub .isUseProxy ()) {
211278 tempGitHubRepositories .add (fullName );
@@ -232,6 +299,9 @@ public GitHub getNonRecordingGitHub() {
232299 return nonRecordingGitHub ;
233300 }
234301
302+ /**
303+ * Kohsuke.
304+ */
235305 protected void kohsuke () {
236306 // No-op for now
237307 // Generally this means the test is doing something that requires additional access rights
@@ -255,28 +325,68 @@ private String getOrganization() throws IOException {
255325 return mockGitHub .isTestWithOrg () ? GITHUB_API_TEST_ORG : gitHub .getMyself ().getLogin ();
256326 }
257327
328+ /**
329+ * Fail.
330+ */
258331 public static void fail () {
259332 Assert .fail ();
260333 }
334+
335+ /**
336+ * Fail.
337+ *
338+ * @param reason the reason
339+ */
261340 public static void fail (String reason ) {
262341 Assert .fail (reason );
263342 }
264343
344+ /**
345+ * Assert that.
346+ *
347+ * @param <T> the generic type
348+ * @param actual the actual
349+ * @param matcher the matcher
350+ */
265351 public static <T > void assertThat (T actual , Matcher <? super T > matcher ) {
266352 MatcherAssert .assertThat ("" , actual , matcher );
267353 }
268354
355+ /**
356+ * Assert that.
357+ *
358+ * @param <T> the generic type
359+ * @param reason the reason
360+ * @param actual the actual
361+ * @param matcher the matcher
362+ */
269363 public static <T > void assertThat (String reason , T actual , Matcher <? super T > matcher ) {
270364 MatcherAssert .assertThat (reason , actual , matcher );
271365 }
272366
367+ /**
368+ * Assert that.
369+ *
370+ * @param reason the reason
371+ * @param assertion the assertion
372+ */
273373 public static void assertThat (String reason , boolean assertion ) {
274374 MatcherAssert .assertThat (reason , assertion );
275375 }
276376
377+ /**
378+ * The Class TemplatingHelper.
379+ */
277380 protected static class TemplatingHelper {
381+
382+ /** The test start date. */
278383 public Date testStartDate = new Date ();
279384
385+ /**
386+ * New response transformer.
387+ *
388+ * @return the response template transformer
389+ */
280390 public ResponseTemplateTransformer newResponseTransformer () {
281391 testStartDate = new Date ();
282392 return ResponseTemplateTransformer .builder ()
0 commit comments