Skip to content

Commit

Permalink
add prototype bean behavior in PerClass lifecycle test
Browse files Browse the repository at this point in the history
  • Loading branch information
xvik committed Jun 28, 2024
1 parent 246edae commit 253d27e
Showing 1 changed file with 59 additions and 0 deletions.
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 {}
}

0 comments on commit 253d27e

Please sign in to comment.