Skip to content

Add ApplicationScope #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void getBeansByPriority() {
@Test
public void getBeansByPriority_withAnnotation() {

final List<Somei> beans = SystemContext.context().getBeansByPriority(Somei.class, Priority.class);
final List<Somei> beans = ApplicationScope.scope().getBeansByPriority(Somei.class, Priority.class);
assertThat(beans).hasSize(3);

assertThat(beans.get(0)).isInstanceOf(BSomei.class);
Expand All @@ -43,7 +43,7 @@ public void getBeansByPriority_withAnnotation() {
@Test
public void getBeansUnsorted_withPriority() {

final List<Somei> beans = SystemContext.getBeans(Somei.class);
final List<Somei> beans = ApplicationScope.list(Somei.class);
assertThat(beans).hasSize(3);
// can't assert bean order
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.circular;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,13 +10,13 @@ public class CupholderTest {
@Test
void circularDependency_via_providerInterface() {

Cupholder cupholder = SystemContext.getBean(Cupholder.class);
Cupholder cupholder = ApplicationScope.get(Cupholder.class);
String hello = cupholder.hello();

assertThat(hello).isEqualTo("CupHelloSeatHello");

// check circular binding
Seat seat = SystemContext.getBean(Seat.class);
Seat seat = ApplicationScope.get(Seat.class);
Cupholder seatCupholder = seat.getCupholder();

assertThat(seatCupholder).isSameAs(cupholder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import java.util.concurrent.atomic.AtomicReference;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

public class BeanContext_Builder_mockitoSpyTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.coffee;

import io.avaje.inject.ApplicationScope;
import io.avaje.inject.BeanContext;
import io.avaje.inject.SystemContext;
import org.example.coffee.core.DuperPump;
Expand All @@ -12,10 +13,10 @@ public class CoffeeMakerTest {
@Test
public void makeIt_via_SystemContext() {

String makeIt = SystemContext.getBean(CoffeeMaker.class).makeIt();
String makeIt = ApplicationScope.get(CoffeeMaker.class).makeIt();
assertThat(makeIt).isEqualTo("done");

Pump pump = SystemContext.getBean(Pump.class);
Pump pump = ApplicationScope.get(Pump.class);
assertThat(pump).isInstanceOf(DuperPump.class);

Pump pump2 = SystemContext.context().getBean(Pump.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.example.coffee.factory;

import io.avaje.inject.ApplicationScope;
import io.avaje.inject.BeanContext;
import io.avaje.inject.SystemContext;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -22,8 +22,8 @@ void test() {

@Test
void named_case_insensitive() {
Otherthing yellow0 = SystemContext.getBean(Otherthing.class, "yellow");
Otherthing yellow1 = SystemContext.getBean(Otherthing.class, "Yellow");
Otherthing yellow0 = ApplicationScope.get(Otherthing.class, "yellow");
Otherthing yellow1 = ApplicationScope.get(Otherthing.class, "Yellow");

assertThat(yellow0.doOther()).isEqualTo("yellow");
assertThat(yellow1).isSameAs(yellow0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.example.coffee.factory;

import io.avaje.inject.ApplicationScope;
import io.avaje.inject.BeanContext;
import io.avaje.inject.SystemContext;
import org.example.coffee.parent.DesEngi;
import org.junit.jupiter.api.Test;

Expand All @@ -19,19 +19,19 @@ public void methodsCalled() {

@Test
public void factoryMethod_createsConcreteImplementation() {
DesEngi buildDesi = SystemContext.getBean(DesEngi.class, "BuildDesi1");
DesEngi buildDesi = ApplicationScope.get(DesEngi.class, "BuildDesi1");
assertThat(buildDesi.ignite()).isEqualTo("buildEngi1");

DesEngi buildDesi2 = SystemContext.getBean(DesEngi.class, "BuildDesi2");
DesEngi buildDesi2 = ApplicationScope.get(DesEngi.class, "BuildDesi2");
assertThat(buildDesi2.ignite()).isEqualTo("MyEngi");
}

@Test
public void factoryMethod_objectInterface() {
DFact dfact = SystemContext.getBean(DFact.class);
DFact dfact = ApplicationScope.get(DFact.class);
assertThat(dfact).isNotNull();

IDFact idfact = SystemContext.getBean(IDFact.class);
IDFact idfact = ApplicationScope.get(IDFact.class);
assertThat(idfact).isSameAs(dfact);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.example.coffee.generic;

import io.avaje.inject.ApplicationScope;
import io.avaje.inject.BeanContext;
import io.avaje.inject.SystemContext;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -13,7 +13,7 @@ public class HazManagerTest {
@Test
public void find_when_allWired() {

HazManager hazManager = SystemContext.getBean(HazManager.class);
HazManager hazManager = ApplicationScope.get(HazManager.class);
Haz haz = hazManager.find(42L);

assertThat(haz.id).isEqualTo(42L);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.generic;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,7 +10,7 @@ public class MultiGenericConsumerTest {
@Test
public void find() {

MultiGenericConsumer bean = SystemContext.getBean(MultiGenericConsumer.class);
MultiGenericConsumer bean = ApplicationScope.get(MultiGenericConsumer.class);

assertThat(bean.findAndDo(34L)).isEqualTo("found 34 stuff");
assertThat(bean.mushString()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.parent;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.example.coffee.parent.sub.Engi;
import org.example.coffee.parent.sub.PetEngi;
import org.junit.jupiter.api.Test;
Expand All @@ -11,9 +11,9 @@ class ConcreteEngiTest {

@Test
void getBean_usingSuperClassTypeAndName() {
LightPetEngi lightByType = SystemContext.getBean(LightPetEngi.class);
PetEngi lightByName = SystemContext.getBean(PetEngi.class, "Lite");
Engi engiByName = SystemContext.getBean(Engi.class, "Lite");
LightPetEngi lightByType = ApplicationScope.get(LightPetEngi.class);
PetEngi lightByName = ApplicationScope.get(PetEngi.class, "Lite");
Engi engiByName = ApplicationScope.get(Engi.class, "Lite");

assertThat(lightByType.ignite()).isEqualTo("lightPetEngi");
assertThat(lightByName).isSameAs(lightByType);
Expand All @@ -22,15 +22,15 @@ void getBean_usingSuperClassTypeAndName() {

@Test
void getBean_usingSuperClassTypeAndName_other() {
Engi engi = SystemContext.getBean(Engi.class, "Des");
Engi engi = ApplicationScope.get(Engi.class, "Des");
assertThat(engi.ignite()).isEqualTo("desEngi");
//DesEngi desEngi = SystemContext.getBean(DesEngi.class);
//DesEngi desEngi = ApplicationScope.get(DesEngi.class);
//assertThat(desEngi).isSameAs(engi);
}

@Test
void getBean_usingSuperClassTypeAndName_NoImpliedName() {
NoImpliedNameEngi engi = SystemContext.getBean(NoImpliedNameEngi.class);
NoImpliedNameEngi engi = ApplicationScope.get(NoImpliedNameEngi.class);
assertThat(engi.ignite()).isEqualTo("NoImpliedNameEngi");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.parent;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -12,22 +12,22 @@ class ConcreteParentTest {

@Test
void simple_getBean_base() {
Silly bean = SystemContext.getBean(Silly.class);
Silly bean = ApplicationScope.get(Silly.class);
assertThat(bean.con()).isEqualTo("Silly");
}

@Test
void simple_getBean() {
SuperSilly bean = SystemContext.getBean(SuperSilly.class);
SuperSilly bean = ApplicationScope.get(SuperSilly.class);
assertThat(bean.con()).isEqualTo("SuperSilly");
}

@Test
void simple_getBean_viaName() {
Silly beanViaName = SystemContext.getBean(Silly.class, "Super");
Silly beanViaName = ApplicationScope.get(Silly.class, "Super");
assertThat(beanViaName.con()).isEqualTo("SuperSilly");

SuperSilly specificBean = SystemContext.getBean(SuperSilly.class);
SuperSilly specificBean = ApplicationScope.get(SuperSilly.class);
assertThat(specificBean).isSameAs(beanViaName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.primary;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,7 +10,7 @@ public class UserOfPEmailerTest {
@Test
public void email() {

UserOfPEmailer bean = SystemContext.getBean(UserOfPEmailer.class);
UserOfPEmailer bean = ApplicationScope.get(UserOfPEmailer.class);
assertThat(bean.email()).isEqualTo("primary");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.example.coffee.priority.base;

import io.avaje.inject.Priority;

import jakarta.inject.Singleton;

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.example.coffee.priority.base;

import io.avaje.inject.Priority;

import jakarta.inject.Singleton;

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.example.coffee.priority.base;

import io.avaje.inject.Priority;

import jakarta.inject.Singleton;

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.example.coffee.provider;

import org.example.coffee.grind.Grinder;

import jakarta.inject.Provider;
import jakarta.inject.Singleton;
import org.example.coffee.grind.Grinder;

@Singleton
public class AProvProvider implements Provider<AProv> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.provider;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,12 +10,12 @@ class FieldInjectProviderTest {
@Test
void test() {

FieldInjectProvider bean = SystemContext.getBean(FieldInjectProvider.class);
FieldInjectProvider bean = ApplicationScope.get(FieldInjectProvider.class);
AProv aProv = bean.testGet();

assertThat(aProv).isNotNull();

AProv beanDirect = SystemContext.getBean(AProv.class);
AProv beanDirect = ApplicationScope.get(AProv.class);
assertThat(aProv).isSameAs(beanDirect);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.provider;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,18 +10,18 @@ class MethodInjectProviderTest {
@Test
void test() {

MethodInjectProvider bean = SystemContext.getBean(MethodInjectProvider.class);
MethodInjectProvider bean = ApplicationScope.get(MethodInjectProvider.class);
AProv aProv = bean.testGet();

assertThat(aProv).isNotNull();

AProv beanDirect = SystemContext.getBean(AProv.class);
AProv beanDirect = ApplicationScope.get(AProv.class);
assertThat(aProv).isSameAs(beanDirect);
}

@Test
void emptyMethodInjection() {
MethodInjectProvider bean = SystemContext.getBean(MethodInjectProvider.class);
MethodInjectProvider bean = ApplicationScope.get(MethodInjectProvider.class);
assertThat(bean.isEmptyMethodInjection()).isTrue();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.coffee.qualifier;

import jakarta.inject.Qualifier;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.qualifier;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -9,7 +9,7 @@ class FooQualTest {

@Test
void test() {
FooQual bean = SystemContext.getBean(FooQual.class);
FooQual bean = ApplicationScope.get(FooQual.class);
assertThat(bean).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.coffee.qualifier;

import jakarta.inject.Qualifier;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.example.coffee.secondary;

import io.avaje.inject.Secondary;

import jakarta.inject.Singleton;

@Secondary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.example.coffee.secondary;

import io.avaje.inject.SystemContext;
import io.avaje.inject.ApplicationScope;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -10,7 +10,7 @@ public class SecondaryEmailerTest {
@Test
public void wire() {

SEmailer bean = SystemContext.getBean(SEmailer.class);
SEmailer bean = ApplicationScope.get(SEmailer.class);
assertThat(bean.email()).isEqualTo("other");
}

Expand Down
Loading