-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to disable managed objects lifecycle for lightweight gui…
…cey tests (start/stop methods on managed objects not called; might be useful for tests with mocks): * new GuiceyTestSupport().disableManagedLifecycle() * @TestGuiceyApp(.., managedLifecycle = false) * TestGuiceyAppExtension.forApp(..).disableManagedLifecycle() * TestSupport.build(App.class).runCoreWithoutManaged(..)
- Loading branch information
Showing
10 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...src/test/groovy/ru/vyarus/dropwizard/guice/test/general/BuilderRunCoreWithoutManaged.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ru.vyarus.dropwizard.guice.test.general; | ||
|
||
import io.dropwizard.lifecycle.Managed; | ||
import jakarta.inject.Singleton; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import ru.vyarus.dropwizard.guice.GuiceBundle; | ||
import ru.vyarus.dropwizard.guice.support.DefaultTestApp; | ||
import ru.vyarus.dropwizard.guice.test.TestSupport; | ||
|
||
/** | ||
* @author Vyacheslav Rusakov | ||
* @since 22.02.2025 | ||
*/ | ||
public class BuilderRunCoreWithoutManaged { | ||
|
||
@Test | ||
void testCoreRun() throws Exception { | ||
|
||
UnusedManaged managed = TestSupport.build(App.class) | ||
.runCore(injector -> injector.getInstance(UnusedManaged.class)); | ||
|
||
Assertions.assertTrue(managed.started); | ||
Assertions.assertTrue(managed.stopped); | ||
} | ||
|
||
@Test | ||
void testCoreRunWithoutManagedLifecycle() throws Exception { | ||
|
||
UnusedManaged managed = TestSupport.build(App.class) | ||
.runCoreWithoutManaged(injector -> injector.getInstance(UnusedManaged.class)); | ||
|
||
Assertions.assertFalse(managed.started); | ||
Assertions.assertFalse(managed.stopped); | ||
} | ||
|
||
public static class App extends DefaultTestApp { | ||
@Override | ||
protected GuiceBundle configure() { | ||
return GuiceBundle.builder() | ||
.extensions(UnusedManaged.class) | ||
.build(); | ||
} | ||
} | ||
|
||
@Singleton | ||
public static class UnusedManaged implements Managed { | ||
public boolean started = false; | ||
public boolean stopped = false; | ||
|
||
@Override | ||
public void start() throws Exception { | ||
started = true; | ||
} | ||
|
||
@Override | ||
public void stop() throws Exception { | ||
stopped = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...t/groovy/ru/vyarus/dropwizard/guice/test/jupiter/guicey/NoManagedLifecycleManualTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ru.vyarus.dropwizard.guice.test.jupiter.guicey; | ||
|
||
import com.google.inject.Inject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import ru.vyarus.dropwizard.guice.test.general.BuilderRunCoreWithoutManaged; | ||
import ru.vyarus.dropwizard.guice.test.jupiter.ext.TestGuiceyAppExtension; | ||
|
||
/** | ||
* @author Vyacheslav Rusakov | ||
* @since 22.02.2025 | ||
*/ | ||
public class NoManagedLifecycleManualTest { | ||
|
||
@RegisterExtension | ||
static TestGuiceyAppExtension ext = TestGuiceyAppExtension.forApp(BuilderRunCoreWithoutManaged.App.class) | ||
.disableManagedLifecycle() | ||
.create(); | ||
|
||
@Inject | ||
BuilderRunCoreWithoutManaged.UnusedManaged managed; | ||
|
||
@Test | ||
void testManagedNotStarted() { | ||
Assertions.assertFalse(managed.started); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...rc/test/groovy/ru/vyarus/dropwizard/guice/test/jupiter/guicey/NoManagedLifecycleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ru.vyarus.dropwizard.guice.test.jupiter.guicey; | ||
|
||
import com.google.inject.Inject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import ru.vyarus.dropwizard.guice.test.general.BuilderRunCoreWithoutManaged; | ||
import ru.vyarus.dropwizard.guice.test.jupiter.TestGuiceyApp; | ||
|
||
/** | ||
* @author Vyacheslav Rusakov | ||
* @since 22.02.2025 | ||
*/ | ||
@TestGuiceyApp(value = BuilderRunCoreWithoutManaged.App.class, managedLifecycle = false) | ||
public class NoManagedLifecycleTest { | ||
|
||
@Inject | ||
BuilderRunCoreWithoutManaged.UnusedManaged managed; | ||
|
||
@Test | ||
void testManagedNotStarted() { | ||
Assertions.assertFalse(managed.started); | ||
} | ||
} |