Skip to content

Commit

Permalink
Add tests for new main method launch protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 29, 2023
1 parent dab4c87 commit af5b725
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.commandmode;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class InstanceMainCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectExit(true)
.setRun(true);

@Test
public void testRun() {
Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World");
Assertions.assertThat(config.getExitCode()).isEqualTo(0);
}

@QuarkusMain
public static class HelloWorldMain {

void main(String[] args) {
System.out.println("Hello World");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.commandmode;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class InstanceMainNoArgsCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectExit(true)
.setRun(true);

@Test
public void testRun() {
Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World");
Assertions.assertThat(config.getExitCode()).isEqualTo(0);
}

@QuarkusMain
public static class HelloWorldMain {

void main() {
System.out.println("Hello World");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.commandmode;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class NonPublicStaticMainCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectExit(true)
.setRun(true);

@Test
public void testRun() {
Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World");
Assertions.assertThat(config.getExitCode()).isEqualTo(0);
}

@QuarkusMain
public static class HelloWorldMain {

public static void main(String[] args) {
System.out.println("Hello World");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.commandmode;

import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class PrivateStaticMainCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectedException(IllegalStateException.class);

@Test
public void shouldNeverRun() {
fail();
}

@QuarkusMain
public static class HelloWorldMain {

public static void main2(String[] args) {
System.out.println("Hello World");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.commandmode;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class ProtectedStaticMainNoArgsCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectExit(true)
.setRun(true);

@Test
public void testRun() {
Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World");
Assertions.assertThat(config.getExitCode()).isEqualTo(0);
}

@QuarkusMain
public static class HelloWorldMain {

protected static void main() {
System.out.println("Hello World");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.commandmode;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.test.QuarkusProdModeTest;

public class StaticMainNoArgsCommandModeTestCase {
@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloWorldMain.class))
.setApplicationName("run-exit")
.setApplicationVersion("0.1-SNAPSHOT")
.setExpectExit(true)
.setRun(true);

@Test
public void testRun() {
Assertions.assertThat(config.getStartupConsoleOutput()).contains("Hello World");
Assertions.assertThat(config.getExitCode()).isEqualTo(0);
}

@QuarkusMain
public static class HelloWorldMain {

static void main() {
System.out.println("Hello World");
}
}

}

0 comments on commit af5b725

Please sign in to comment.