Created
September 4, 2015 13:59
-
-
Save gastaldi/46b3f38bc38c5efcc0ba to your computer and use it in GitHub Desktop.
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
package org.jboss.forge.addon.ui.input; | |
import javax.inject.Inject; | |
import org.jboss.arquillian.container.test.api.Deployment; | |
import org.jboss.arquillian.junit.Arquillian; | |
import org.jboss.forge.arquillian.AddonDependencies; | |
import org.jboss.forge.arquillian.archive.AddonArchive; | |
import org.jboss.shrinkwrap.api.ShrinkWrap; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(Arquillian.class) | |
public class MyTest | |
{ | |
@Deployment | |
@AddonDependencies | |
public static AddonArchive getDeployment() | |
{ | |
return ShrinkWrap.create(AddonArchive.class).addClasses(TargetPackage.class, TargetPackageProducer.class) | |
.addBeansXML(); | |
} | |
@Inject | |
private TargetPackage targetPackage; | |
@Test | |
public void test() | |
{ | |
Assert.assertNotNull(targetPackage); | |
Assert.assertEquals("targetPackage", targetPackage.getName()); | |
} | |
} |
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
package org.jboss.forge.addon.ui.input; | |
public interface TargetPackage extends UIInput<String> | |
{ | |
} |
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
package org.jboss.forge.addon.ui.input; | |
import java.lang.reflect.InvocationHandler; | |
import java.lang.reflect.Method; | |
import java.lang.reflect.Proxy; | |
import javax.enterprise.inject.Produces; | |
public class TargetPackageProducer | |
{ | |
// We could @Inject UIInput<String> input in here | |
@Produces | |
public TargetPackage createTargetPackage(InputComponentFactory factory) | |
{ | |
final UIInput<String> input = factory.createInput("targetPackage", String.class); | |
return (TargetPackage) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { TargetPackage.class }, | |
new InvocationHandler() | |
{ | |
@Override | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable | |
{ | |
return method.invoke(input, args); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a @typed(TargetPackage.class) is missing in the @produces method