-
-
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 prototype bean behavior in PerClass lifecycle test
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...groovy/ru/vyarus/dropwizard/guice/test/jupiter/guicey/PerClassPrototypeInjectionTest.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,59 @@ | ||
package ru.vyarus.dropwizard.guice.test.jupiter.guicey; | ||
|
||
import io.dropwizard.core.Application; | ||
import io.dropwizard.core.Configuration; | ||
import io.dropwizard.core.setup.Bootstrap; | ||
import io.dropwizard.core.setup.Environment; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import ru.vyarus.dropwizard.guice.GuiceBundle; | ||
import ru.vyarus.dropwizard.guice.test.jupiter.TestGuiceyApp; | ||
|
||
/** | ||
* @author Vyacheslav Rusakov | ||
* @since 28.06.2024 | ||
*/ | ||
@TestGuiceyApp(PerClassPrototypeInjectionTest.App.class) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class PerClassPrototypeInjectionTest { | ||
|
||
@Inject | ||
Bean bean; | ||
|
||
static int testId; | ||
static int beanId; | ||
|
||
@Test | ||
@Order(1) | ||
void injectTest1() { | ||
Assertions.assertNotNull(bean); | ||
testId = System.identityHashCode(this); | ||
beanId = System.identityHashCode(bean); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void injectTest2() { | ||
Assertions.assertNotNull(bean); | ||
Assertions.assertEquals(testId, System.identityHashCode(this)); | ||
Assertions.assertNotEquals(beanId, System.identityHashCode(bean)); | ||
} | ||
|
||
public static class App extends Application<Configuration> { | ||
|
||
@Override | ||
public void initialize(Bootstrap<Configuration> bootstrap) { | ||
bootstrap.addBundle(GuiceBundle.builder().build()); | ||
} | ||
|
||
@Override | ||
public void run(Configuration configuration, Environment environment) throws Exception { | ||
} | ||
} | ||
|
||
// prototype scope | ||
public static class Bean {} | ||
} |