Skip to content

Commit

Permalink
fix tests for jdk 21
Browse files Browse the repository at this point in the history
  • Loading branch information
xvik committed Mar 7, 2024
1 parent 6626f0e commit 922f91d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import ru.vyarus.dropwizard.guice.test.builder.TestSupportHolder;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.security.SystemExit;
import uk.org.webcompere.systemstubs.stream.SystemErr;

/**
Expand All @@ -25,27 +24,21 @@
@ExtendWith(SystemStubsExtension.class)
public class StartErrorJupiterTest {

@SystemStub
SystemExit exit;
@SystemStub
SystemErr err;

@Test
// NOTE could be parallelized with some tests, but not with other error tests
void checkStartupFail() throws Exception {
exit.execute(() -> {
ErrorApplication.main("server");
});
Assertions.assertEquals(1, exit.getExitCode());
Assertions.assertThrows(RuntimeException.class, () -> ErrorApplication.main("server"));

Assertions.assertFalse(TestSupportHolder.isContextSet());
}

@Test
// NOTE not parallelizable test!
void checkStartupFailWithOutput() throws Exception {
exit.execute(() -> {
ErrorApplication.main("server");
});
Assertions.assertThrows(RuntimeException.class, () -> ErrorApplication.main("server"));
// strange matching because in java9 @Named value will be quoted and in 8 will not
Assertions.assertTrue(err.getText()
.contains("[Guice/MissingImplementation]: No implementation for String annotated with @Named"));
Expand All @@ -70,6 +63,11 @@ public void initialize(Bootstrap<TestConfiguration> bootstrap) {
@Override
public void run(TestConfiguration configuration, Environment environment) throws Exception {
}

@Override
protected void onFatalError(Throwable t) {
throw new RuntimeException(t);
}
}

public static class ErrorModule extends AbstractModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void checkSetupOutputForAnnotation() {
System.err.println(output);

assertThat(output.replaceAll("\\$\\$Lambda\\$\\d+/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
// jdk 21
.replaceAll("\\$\\$Lambda/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
.replaceAll("\\) {8,}\t", ") \t"))
.contains("Guicey test extensions (Test1.):\n" +
"\n" +
Expand Down Expand Up @@ -82,6 +84,8 @@ void checkSetupOutputForManualRegistration() {
System.err.println(output);

assertThat(output.replaceAll("\\$\\$Lambda\\$\\d+/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
// jdk 21
.replaceAll("\\$\\$Lambda/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
.replaceAll("\\) {8,}\t", ") \t"))
.contains("Guicey test extensions (Test2.):\n" +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void checkSetupOutputForAnnotation() {
System.err.println(output);

assertThat(output.replaceAll("\\$\\$Lambda\\$\\d+/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
// jdk 21
.replaceAll("\\$\\$Lambda/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
.replaceAll("\\) {8,}\t", ") \t"))
.contains("Guicey test extensions (Test1.):\n" +
"\n" +
Expand Down Expand Up @@ -73,6 +75,8 @@ void checkSetupOutputForManualRegistration() {
System.err.println(output);

assertThat(output.replaceAll("\\$\\$Lambda\\$\\d+/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
// jdk 21
.replaceAll("\\$\\$Lambda/\\d+(x[a-z\\d]+)?", "\\$\\$Lambda\\$111/1111111")
.replaceAll("\\) {8,}\t", ") \t"))
.contains("Guicey test extensions (Test2.):\n" +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import io.dropwizard.core.Application
import io.dropwizard.core.Configuration
import io.dropwizard.core.setup.Bootstrap
import io.dropwizard.core.setup.Environment
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.extension.ExtendWith
import ru.vyarus.dropwizard.guice.GuiceBundle
import ru.vyarus.guicey.spa.SpaBundle
import spock.lang.Specification
import uk.org.webcompere.systemstubs.jupiter.SystemStub
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension
import uk.org.webcompere.systemstubs.security.SystemExit
import uk.org.webcompere.systemstubs.stream.SystemErr

/**
Expand All @@ -20,20 +20,15 @@ import uk.org.webcompere.systemstubs.stream.SystemErr
@ExtendWith(SystemStubsExtension)
class MappingClashTest extends Specification {

@SystemStub
SystemExit exit
@SystemStub
SystemErr err

def "Check uri paths clash"() {

when: "starting app"
exit.execute(() -> {
new App().run(['server'] as String[])
});
Assertions.assertThrows(RuntimeException.class, () -> new App().run(['server'] as String[]))

then: "error"
exit.exitCode == 1
err.text.contains("Assets servlet app2 registration clash with already installed servlets on paths: /app/*")
}

Expand All @@ -51,5 +46,10 @@ class MappingClashTest extends Specification {
@Override
void run(Configuration configuration, Environment environment) throws Exception {
}

@Override
protected void onFatalError(Throwable t) {
throw new RuntimeException(t)
}
}
}

0 comments on commit 922f91d

Please sign in to comment.