@@ -38,11 +38,7 @@ public abstract class AbstractGitHubWireMockTest {
3838 */
3939 protected GitHub gitHub ;
4040
41- /**
42- * {@link GitHub} instance for use before/after test. Traffic will not be part of snapshot when taken. Should only
43- * be used when isUseProxy() or isTakeSnapShot().
44- */
45- protected GitHub gitHubBeforeAfter ;
41+ private GitHub gitHubBeforeAfter ;
4642
4743 protected final String baseFilesClassPath = this .getClass ().getName ().replace ('.' , '/' );
4844 protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock" ;
@@ -127,10 +123,10 @@ protected void requireProxy(String reason) {
127123 mockGitHub .isUseProxy ());
128124 }
129125
130- protected void verifyAuthenticated () {
126+ protected void verifyAuthenticated (GitHub instance ) {
131127 assertThat (
132128 "GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_USER and GITHUB_PASSWORD environment variables" ,
133- gitHub .isAnonymous (),
129+ instance .isAnonymous (),
134130 is (false ));
135131 }
136132
@@ -172,12 +168,9 @@ protected GHRepository getTempRepository(String name) throws IOException {
172168 String fullName = GITHUB_API_TEST_ORG + '/' + name ;
173169 if (mockGitHub .isUseProxy ()) {
174170
175- // Needs to check if you are authenticated before doing this cleanup and repo creation
176- verifyAuthenticated ();
177-
178171 cleanupRepository (fullName );
179172
180- GHRepository repository = gitHubBeforeAfter .getOrganization (GITHUB_API_TEST_ORG )
173+ GHRepository repository = getGitHubBeforeAfter () .getOrganization (GITHUB_API_TEST_ORG )
181174 .createRepository (name )
182175 .description ("A test repository for testing the github-api project: " + name )
183176 .homepage ("http://github-api.kohsuke.org/" )
@@ -211,7 +204,7 @@ protected void cleanupRepository(String fullName) throws IOException {
211204 if (mockGitHub .isUseProxy ()) {
212205 tempGitHubRepositories .add (fullName );
213206 try {
214- GHRepository repository = gitHubBeforeAfter .getRepository (fullName );
207+ GHRepository repository = getGitHubBeforeAfter () .getRepository (fullName );
215208 if (repository != null ) {
216209 repository .delete ();
217210 }
@@ -222,6 +215,15 @@ protected void cleanupRepository(String fullName) throws IOException {
222215 }
223216 }
224217
218+ /**
219+ * {@link GitHub} instance for use before/after test. Traffic will not be part of snapshot when taken. Should only
220+ * be used when isUseProxy() or isTakeSnapShot().
221+ */
222+ public GitHub getGitHubBeforeAfter () {
223+ verifyAuthenticated (gitHubBeforeAfter );
224+ return gitHubBeforeAfter ;
225+ }
226+
225227 protected void kohsuke () {
226228 // No-op for now
227229 // Generally this means the test is doing something that requires additional access rights
0 commit comments