Skip to content

Commit d2ad9ca

Browse files
Stabilize SetupWizardTest
1 parent bf600a4 commit d2ad9ca

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/src/test/java/jenkins/install/SetupWizardTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.hamcrest.MatcherAssert.assertThat;
2828
import static org.hamcrest.Matchers.containsString;
2929
import static org.hamcrest.Matchers.not;
30+
import static org.junit.jupiter.api.Assertions.fail;
3031

3132
import edu.umd.cs.findbugs.annotations.NonNull;
3233
import hudson.FilePath;
@@ -62,10 +63,10 @@
6263
import org.eclipse.jetty.server.ServerConnector;
6364
import org.eclipse.jetty.util.Callback;
6465
import org.htmlunit.Page;
66+
import org.junit.jupiter.api.AfterEach;
6567
import org.junit.jupiter.api.BeforeEach;
6668
import org.junit.jupiter.api.Tag;
6769
import org.junit.jupiter.api.Test;
68-
import org.junit.jupiter.api.io.TempDir;
6970
import org.jvnet.hudson.test.Issue;
7071
import org.jvnet.hudson.test.JenkinsRule;
7172
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
@@ -78,18 +79,16 @@
7879
@WithJenkins
7980
class SetupWizardTest {
8081

81-
@TempDir
8282
private File tmpdir;
8383

8484
private JenkinsRule j;
8585

8686
@BeforeEach
87-
void setUp(JenkinsRule rule) {
87+
void setUp(JenkinsRule rule) throws Exception {
8888
j = rule;
89-
}
9089

91-
@BeforeEach
92-
void initSetupWizard() throws IOException, InterruptedException {
90+
tmpdir = Files.createTempDirectory("junit-").toFile();
91+
9392
final SetupWizard wizard = j.jenkins.getSetupWizard();
9493
wizard.init(true);
9594

@@ -100,6 +99,11 @@ void initSetupWizard() throws IOException, InterruptedException {
10099
final String password = ostream.toString(StandardCharsets.UTF_8);
101100
}
102101

102+
@AfterEach
103+
void tearDown() {
104+
tmpdir.delete();
105+
}
106+
103107
@Test
104108
void shouldReturnPluginListsByDefault() {
105109
JenkinsRule.WebClient wc = j.createWebClient();
@@ -170,15 +174,13 @@ void shouldProhibitAccessToPluginListWithoutAuth() throws Exception {
170174

171175
private String jsonRequest(JenkinsRule.WebClient wc, String path) {
172176
// Try to call the actions method to retrieve the data
173-
final Page res;
174177
try {
175-
res = wc.goTo(path, null);
178+
final Page res = wc.goTo(path, null);
179+
final String responseJSON = res.getWebResponse().getContentAsString();
180+
return responseJSON;
176181
} catch (Exception ex) {
177-
ex.getMessage();
178-
throw new AssertionError("Cannot get a response from " + path, ex);
182+
return fail("Cannot get a response from " + path, ex);
179183
}
180-
final String responseJSON = res.getWebResponse().getContentAsString();
181-
return responseJSON;
182184
}
183185

184186
private static final class CustomLocalUpdateSite extends UpdateSite {

0 commit comments

Comments
 (0)