-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Alternative to be used in modules
Alternative becomes a synonym of Provides, it was already a synonym of Component, but was not availabe in modules.
- Loading branch information
Showing
4 changed files
with
308 additions
and
19 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
103 changes: 103 additions & 0 deletions
103
...esting/src/test/java/restx/factory/alternative/components/TestAlternativesFromModule.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,103 @@ | ||
package restx.factory.alternative.components; | ||
|
||
import javax.inject.Named; | ||
import restx.factory.Alternative; | ||
import restx.factory.Component; | ||
import restx.factory.Module; | ||
import restx.factory.Provides; | ||
import restx.factory.When; | ||
|
||
/** | ||
* @author apeyrard | ||
*/ | ||
@Module | ||
public class TestAlternativesFromModule { | ||
|
||
public static interface Calculation { | ||
int calculate(int a, int b); | ||
} | ||
|
||
@Provides | ||
public Calculation addition() { | ||
return new Calculation() { | ||
@Override | ||
public int calculate(int a, int b) { | ||
return a + b; | ||
} | ||
}; | ||
} | ||
|
||
@Alternative(to = Calculation.class, named = "addition") | ||
@When(name = "restx.test.alternatives", value = "true") | ||
public Calculation multiplication() { | ||
return new Calculation() { | ||
@Override | ||
public int calculate(int a, int b) { | ||
return a * b; | ||
} | ||
}; | ||
} | ||
|
||
public static interface Flag { | ||
boolean value(); | ||
} | ||
|
||
@Provides | ||
@Named("SomeFlag") | ||
public Flag alwaysTrue() { | ||
return new Flag() { | ||
@Override | ||
public boolean value() { | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
@Alternative(to = Flag.class, named = "SomeFlag") | ||
@When(name = "restx.test.alternatives", value = "true") | ||
public Flag alwaysFalse() { | ||
return new Flag() { | ||
@Override | ||
public boolean value() { | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
public static interface Priority { | ||
int value(); | ||
} | ||
|
||
@Provides | ||
public Priority priority() { | ||
return new Priority() { | ||
@Override | ||
public int value() { | ||
return Integer.MAX_VALUE; | ||
} | ||
}; | ||
} | ||
|
||
@Alternative(to = Priority.class, named = "priority", priority = -2000) | ||
@When(name = "restx.test.alternatives", value = "true") | ||
public Priority nilPriority() { | ||
return new Priority() { | ||
@Override | ||
public int value() { | ||
return 0; | ||
} | ||
}; | ||
} | ||
|
||
|
||
@Alternative(to = Priority.class, named = "priority", priority = -3000) | ||
@When(name = "restx.test.alternatives", value = "true") | ||
public Priority minPriority() { | ||
return new Priority() { | ||
@Override | ||
public int value() { | ||
return Integer.MIN_VALUE; | ||
} | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.