Skip to content

Commit

Permalink
Fix CustomCDIProviderTest in accordance to what new CDI API expects. …
Browse files Browse the repository at this point in the history
…Exclude incorrect TCK SE test.
  • Loading branch information
manovotn committed Dec 4, 2020
1 parent c2c04d4 commit c2656d7
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

package org.jboss.weld.environment.se.test.provider.custom;

import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Vetoed;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.inject.spi.CDIProvider;
import jakarta.enterprise.util.TypeLiteral;

import java.lang.annotation.Annotation;
import java.util.Iterator;

/**
* @author Martin Kouba
Expand All @@ -33,11 +39,59 @@ public class CustomCDIProvider implements CDIProvider {
@Override
public CDI<Object> getCDI() {
isCalled = true;
return null;
// we cannot return just null, CDI checks that
return new CustomCdi();
}

public static void reset() {
isCalled = false;
}

public class CustomCdi extends CDI<Object> {

@Override
public BeanManager getBeanManager() {
return null;
}

@Override
public Instance<Object> select(Annotation... qualifiers) {
return null;
}

@Override
public <U> Instance<U> select(Class<U> subtype, Annotation... qualifiers) {
return null;
}

@Override
public <U> Instance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) {
return null;
}

@Override
public boolean isUnsatisfied() {
return false;
}

@Override
public boolean isAmbiguous() {
return false;
}

@Override
public void destroy(Object instance) {

}

@Override
public Object get() {
return null;
}

@Override
public Iterator<Object> iterator() {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.jboss.weld.environment.se.test.provider.custom;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import jakarta.enterprise.inject.spi.CDI;
Expand All @@ -34,7 +34,9 @@ public void testCustomCDIProvider() {
try {
CustomCDIProvider.reset();
CDI.setCDIProvider(new CustomCDIProvider());
assertNull(CDI.current());
CDI<Object> current = CDI.current();
assertNotNull(current);
assertTrue(current instanceof CustomCDIProvider.CustomCdi);
assertTrue(CustomCDIProvider.isCalled);
} finally {
// Unset the CDIProvider so that other tests are not affected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

package org.jboss.weld.environment.servlet.test.provider;

import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Vetoed;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.inject.spi.CDIProvider;
import jakarta.enterprise.util.TypeLiteral;

import java.lang.annotation.Annotation;
import java.util.Iterator;

/**
* @author Martin Kouba
Expand All @@ -33,11 +39,59 @@ public class CustomCDIProvider implements CDIProvider {
@Override
public CDI<Object> getCDI() {
isCalled = true;
return null;
return new CustomCdi();
}

public static void reset() {
isCalled = false;
}

public class CustomCdi extends CDI<Object> {

@Override
public BeanManager getBeanManager() {
return null;
}

@Override
public Instance<Object> select(Annotation... qualifiers) {
return null;
}

@Override
public <U> Instance<U> select(Class<U> subtype, Annotation... qualifiers) {
return null;
}

@Override
public <U> Instance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers) {
return null;
}

@Override
public boolean isUnsatisfied() {
return false;
}

@Override
public boolean isAmbiguous() {
return false;
}

@Override
public void destroy(Object instance) {

}

@Override
public Object get() {
return null;
}

@Override
public Iterator<Object> iterator() {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.jboss.weld.environment.servlet.test.provider;

import static org.jboss.weld.environment.servlet.test.util.Deployments.baseDeployment;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import jakarta.enterprise.inject.spi.CDI;
Expand All @@ -41,7 +41,9 @@ public void testCustomCDIProvider() {
try {
CustomCDIProvider.reset();
CDI.setCDIProvider(new CustomCDIProvider());
assertNull(CDI.current());
CDI<Object> current = CDI.current();
assertNotNull(current);
assertTrue(current instanceof CustomCDIProvider.CustomCdi);
assertTrue(CustomCDIProvider.isCalled);
} finally {
// Unset the CDIProvider so that other tests are not affected
Expand Down
6 changes: 6 additions & 0 deletions jboss-tck-runner/src/test/tck20/tck-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<!-- Issues in the spec -->

<!-- Issues in the TCK -->
<!-- https://github.com/eclipse-ee4j/cdi-tck/issues/217 -->
<class name="org.jboss.cdi.tck.tests.se.customCDIProvider.CustomCDIProviderTest">
<methods>
<exclude name=".*"/>
</methods>
</class>

<!-- Issues in Weld (the RI) -->

Expand Down

0 comments on commit c2656d7

Please sign in to comment.