-
Notifications
You must be signed in to change notification settings - Fork 24
Add @Priority and make it the default #73
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
inject-test/src/test/java/org/example/coffee/list/A2Somei.java
This file contains hidden or 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,14 @@ | ||
package org.example.coffee.list; | ||
|
||
import javax.annotation.Priority; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Priority(22) | ||
public class A2Somei implements Somei { | ||
|
||
@Override | ||
public String some() { | ||
return "a"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
inject-test/src/test/java/org/example/coffee/priority/base/ABasei.java
This file contains hidden or 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,15 @@ | ||
package org.example.coffee.priority.base; | ||
|
||
import io.avaje.inject.Priority; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Priority(42) | ||
public class ABasei implements BaseIface { | ||
|
||
@Override | ||
public String other() { | ||
return "a"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
inject-test/src/test/java/org/example/coffee/priority/base/BBasei.java
This file contains hidden or 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,15 @@ | ||
package org.example.coffee.priority.base; | ||
|
||
import io.avaje.inject.Priority; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Priority(7) | ||
public class BBasei implements BaseIface { | ||
|
||
@Override | ||
public String other() { | ||
return "b"; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
inject-test/src/test/java/org/example/coffee/priority/base/BaseIface.java
This file contains hidden or 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,6 @@ | ||
package org.example.coffee.priority.base; | ||
|
||
public interface BaseIface { | ||
|
||
String other(); | ||
} |
15 changes: 15 additions & 0 deletions
15
inject-test/src/test/java/org/example/coffee/priority/base/CBasei.java
This file contains hidden or 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,15 @@ | ||
package org.example.coffee.priority.base; | ||
|
||
import io.avaje.inject.Priority; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Priority(1) | ||
public class CBasei implements BaseIface { | ||
|
||
@Override | ||
public String other() { | ||
return "a"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit, but should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it should, it will be nice to fix it - thanks |
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
inject-test/src/test/java/org/example/coffee/priority/base/PriorityTest.java
This file contains hidden or 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,36 @@ | ||
package org.example.coffee.priority.base; | ||
|
||
import io.avaje.inject.BeanContext; | ||
import io.avaje.inject.SystemContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class PriorityTest { | ||
|
||
@Test | ||
void getBeansByPriority() { | ||
final BeanContext context = SystemContext.context(); | ||
|
||
final List<BaseIface> beans = context.getBeansByPriority(BaseIface.class); | ||
assertExpectedOrder(beans); | ||
} | ||
|
||
@Test | ||
void sortByPriority() { | ||
final BeanContext context = SystemContext.context(); | ||
|
||
final List<BaseIface> beans = context.getBeans(BaseIface.class); | ||
final List<BaseIface> sorted = context.sortByPriority(beans); | ||
|
||
assertExpectedOrder(sorted); | ||
} | ||
|
||
private void assertExpectedOrder(List<BaseIface> sorted) { | ||
assertThat(sorted.get(0)).isInstanceOf(CBasei.class); | ||
assertThat(sorted.get(1)).isInstanceOf(BBasei.class); | ||
assertThat(sorted.get(2)).isInstanceOf(ABasei.class); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../org/example/coffee/priority/AOtheri.java → ...ample/coffee/priority/custom/AOtheri.java
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.coffee.priority; | ||
package org.example.coffee.priority.custom; | ||
|
||
import javax.inject.Singleton; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../org/example/coffee/priority/BOtheri.java → ...ample/coffee/priority/custom/BOtheri.java
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.coffee.priority; | ||
package org.example.coffee.priority.custom; | ||
|
||
import javax.inject.Singleton; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../org/example/coffee/priority/COtheri.java → ...ample/coffee/priority/custom/COtheri.java
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.coffee.priority; | ||
package org.example.coffee.priority.custom; | ||
|
||
import javax.inject.Singleton; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ample/coffee/priority/CustomPriority.java → ...offee/priority/custom/CustomPriority.java
This file contains hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
...g/example/coffee/priority/OtherIface.java → ...le/coffee/priority/custom/OtherIface.java
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.coffee.priority; | ||
package org.example.coffee.priority.custom; | ||
|
||
public interface OtherIface { | ||
|
||
|
This file contains hidden or 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 io.avaje.inject; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* The <code>Priority</code> annotation can be applied to classes to indicate | ||
* in what order they should be returned via @{@link SystemContext#getBeansByPriority(Class)}. | ||
* <p> | ||
* Beans can be returned using other Priority annotation such as <code>javax.annotation.Priority</code> | ||
* or any custom priority annotation that has an <code>int value()</code> attribute. | ||
* </p> | ||
* | ||
* @see BeanContext#getBeansByPriority(Class) | ||
* @see BeanContext#getBeansByPriority(Class, Class) | ||
* @see BeanContext#sortByPriority(List, Class) | ||
*/ | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target(TYPE) | ||
public @interface Priority { | ||
int value(); | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test looks identical to
getBeansByPriority_withAnnotation
: should one of them be removed or tweaked?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll merge and sort that out - thanks.