-
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 @when ate class level in modules
If a @when is defined for the whole module, all methods will inherit of the specified condition. Method will ne be allowed to use @when if the module define one at the class level.
- Loading branch information
Showing
5 changed files
with
176 additions
and
50 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
27 changes: 27 additions & 0 deletions
27
...factory-testing/src/test/java/restx/factory/conditional/components/TestClassicModule.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,27 @@ | ||
package restx.factory.conditional.components; | ||
|
||
import javax.inject.Named; | ||
import restx.factory.Module; | ||
import restx.factory.Provides; | ||
|
||
/** | ||
* @author apeyrard | ||
*/ | ||
@Module | ||
public class TestClassicModule { | ||
|
||
@Provides | ||
public TestInterfaces.Resolver prodResolver() { | ||
return new TestInterfaces.Resolver() { | ||
@Override | ||
public String resolve(String constraint) { | ||
return "prod:"+constraint; | ||
} | ||
}; | ||
} | ||
|
||
@Provides @Named("db.type") | ||
public String dbType() { | ||
return "postgres"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
restx-factory-testing/src/test/java/restx/factory/conditional/components/TestDevModule.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,43 @@ | ||
package restx.factory.conditional.components; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
import javax.inject.Named; | ||
import restx.factory.Alternative; | ||
import restx.factory.Module; | ||
import restx.factory.Provides; | ||
import restx.factory.When; | ||
|
||
/** | ||
* @author apeyrard | ||
*/ | ||
@Module(priority = -100) | ||
@When(name = "my-mode", value = "dev") | ||
public class TestDevModule { | ||
|
||
@Alternative(to = TestInterfaces.Resolver.class, named = "prodResolver") | ||
public TestInterfaces.Resolver devResolver() { | ||
return new TestInterfaces.Resolver() { | ||
@Override | ||
public String resolve(String constraint) { | ||
return "dev:"+constraint; | ||
} | ||
}; | ||
} | ||
|
||
@Provides | ||
public TestInterfaces.Workspace workspace() { | ||
return new TestInterfaces.Workspace() { | ||
@Override | ||
public List<String> modules() { | ||
return ImmutableList.of("mod1", "mod2"); | ||
} | ||
}; | ||
} | ||
|
||
@Provides @Named("db.type") | ||
public String dbType() { | ||
return "derby"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
restx-factory-testing/src/test/java/restx/factory/conditional/components/TestInterfaces.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,17 @@ | ||
package restx.factory.conditional.components; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author apeyrard | ||
*/ | ||
public class TestInterfaces { | ||
|
||
public static interface Resolver { | ||
String resolve(String constraint); | ||
} | ||
|
||
public static interface Workspace { | ||
List<String> modules(); | ||
} | ||
} |
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