Skip to content

Commit

Permalink
Assignability tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa authored and jharting committed Apr 22, 2012
1 parent 9510730 commit 4e53d71
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 0 deletions.
@@ -0,0 +1,86 @@
package org.jboss.weld.tests.assignability;

import junit.framework.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.BeanArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.TypeLiteral;
import javax.inject.Inject;
import java.util.Set;

/**
*
*/
@RunWith(Arquillian.class)
public class AssignabilityTest {

@Inject
private BeanManager beanManager;

@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(BeanArchive.class)
.addPackage(AssignabilityTest.class.getPackage());
}


@Test
public void testAssignability1() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<Order>>() {
}.getType());

Assert.assertEquals(1, beans.size());
}

@Test
public void testAssignability2() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<User>>() {
}.getType());
Assert.assertEquals(2, beans.size());
}

@Test
public void testAssignability3() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<?>>() {
}.getType());
System.err.println("beans = " + beans);
Assert.assertEquals(2, beans.size());
}

@Test
public void testAssignability4() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<? extends Persistent>>() {
}.getType());
Assert.assertEquals(2, beans.size());
}

@Test
public <X extends Persistent> void testAssignability5() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<X>>() {
}.getType());
Assert.assertEquals(2, beans.size());
}

@Test
public void testAssignability6() {
Set<Bean<?>> beans = beanManager.getBeans(new TypeLiteral<Dao<? extends User>>() {
}.getType());
Assert.assertEquals(2, beans.size());
}

@Ignore("WELD-1054")
@Test
public void testAssignability7() {
Set<Bean<?>> beans = beanManager.getBeans(Dao.class);
Assert.assertEquals(0, beans.size());
}

}
@@ -0,0 +1,11 @@
package org.jboss.weld.tests.assignability;

/**
*
*/
public class Dao<T extends Persistent> {

public String getType() {
return "Dao";
}
}
@@ -0,0 +1,7 @@
package org.jboss.weld.tests.assignability;

/**
*
*/
public class Order implements Persistent {
}
@@ -0,0 +1,7 @@
package org.jboss.weld.tests.assignability;

/**
*
*/
public interface Persistent {
}
@@ -0,0 +1,7 @@
package org.jboss.weld.tests.assignability;

/**
*
*/
public class User implements Persistent {
}
@@ -0,0 +1,12 @@
package org.jboss.weld.tests.assignability;

/**
*
*/
public class UserDao extends Dao<User> {

@Override
public String getType() {
return "UserDao";
}
}

0 comments on commit 4e53d71

Please sign in to comment.