Coder Social home page Coder Social logo

guhilling / cdi-test Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 4.0 1.98 MB

JUnit extension for easy and efficient testing of CDI components

Home Page: http://guhilling.github.io/cdi-test/

License: Apache License 2.0

Java 98.48% CSS 0.01% SCSS 0.09% HTML 1.42%
cdi java javaee8 junit

cdi-test's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar erdlet avatar fseemann avatar ghilling avatar guhilling avatar muestefa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cdi-test's Issues

Use slf4j in cdi-test classes

Is your feature request related to a problem? Please describe.
Handling proper log output and proper levels is still awful with idk logging.

Describe the solution you'd like
Use slf4j as log "frontend" and probably log4j2 as the default backend. backend can be replaced if necessary. Everybody is using slf4j-api anyway no this shouldn't lead to any problems.

Describe alternatives you've considered
Keep using idk logging.

Support Java 8 / Documentation should express required Java version

Is your feature request related to a problem? Please describe.
Some days ago I noticed cdi-test and today was the day I wanted to use it. After setting up my project and my first test I executed it I got the following error messages:

cannot access de.hilling.junit.cdi.CdiTestJunitExtension bad class file: ...\de\hilling\junit\cdi\cdi-test-core\3.2.1\cdi-test-core-3.2.1.jar(de/hilling/junit/cdi/CdiTestJunitExtension.class) class file has wrong version 55.0, should be 52.0

The error claims that the Extension class is written in Java 11 and therefore is not compatible to Java 8 (which I have to use at work). I then checked the documentation twice, but didn't find a notice about the required version and that it is not compatible to the (minimum) Java version required by JUnit Jupiter.

Describe the solution you'd like
Solution I like? Make it compatible to Java 8 ;)

Describe alternatives you've considered
A clear and concise notice / warning that Java 11 is required.

Enhance Javadoc

Is your feature request related to a problem? Please describe.
Package-Info
Doc all classes

Check for proper setup of test cases

Is your feature request related to a problem? Please describe.
The only supported cdi feature for test cases is field injection. This should be verified during test setup.
Also some other things like test class visibility etc. could be checked.
Right now things might "silently" go wrong although throwing an exception or at least issuing a warning should be not problem.

Describe the solution you'd like
Create a verifier for all of the test classes.

Describe alternatives you've considered
None.

Additional context
None

Allow injection of mocks of the same type

Hello.

I'm trying to replace cdi-unit by cdi-test. I already managed to make it work for several cases, however I hit in a situation where I need several mocks of the same type on the same test.
Due to a validation in cdi-test we can't inject mocks with the same type.

I would like that we use another attribute as a discriminator, allowing several mocks of the same type to be injected. Maybe mocks with a given name, could be injected with @Named or a qualifier with the same name as the mock.

No workaround came to my mind.

The code where it is blocking the injection:

    @Override
    public synchronized void onMockCreated(Object mock, MockCreationSettings settings) {
        final Class<?> typeToMock = settings.getTypeToMock();
        final Map<Class<?>, Object> mocks = currentMockSet();
        if (mocks.containsKey(typeToMock)) {
            throw new CdiTestException("mock " + typeToMock + " already in set");
        }
        try {
            mocks.put(typeToMock, mock);
        } catch (UnsupportedOperationException uoe) {
            // IGNORE
        }
    }

Documentation uses non existing version 3.2.

Describe the bug

The dependency information inside the documentation uses version 3.2.2 of cdi-test, but this version was never released according to GitHub releases and Maven central.

To Reproduce
Read dependency information in the docs.

Expected behavior
The dependency information / documentation is in line with the current release or the version is left out and a reminder like "Don't forget to add a version information" is added.

Additional context
Not relevant.

Support UserTransaction and PersistenceContext

Is your feature request related to a problem? Please describe.
I want to be able to test @transactional cdi components.

Describe the solution you'd like
Use Weld JTA and JPA integration with Narayana.

Describe alternatives you've considered
Use Atomikos instead of Narayana? But the documentation and samples for Narayana are sufficient now and it's used in Wildly anyway.

Additional context
The "old" solution (cdi-jee) will remain as-is.

Support for MockK

I'd like to use Kotlin and the MockK library to generate mocks for cdi-test, but cdi-test doesn't seem to pick up de annotated mocks.
I'd like some hints as to how I can extend cdi-test to support MockK mocks.
Mockito seeems to work as described, but I like the Kotlin DSL of MockK better and would like to use that instead.
Any hints would be appreciated, I'll start taking a look myself though.

Don't create 2 instances of test class

Describe the bug
A second instance is created for injection.
This might lead to problems if state is maintained in the constructor of the test class.

To Reproduce
Run any test.

Expected behavior
create only one instance. Maybe use a generated class for injection.

Migrate to Weld 5 and latest Jakarta

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context about the feature request here.

Support JDK 17

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context about the feature request here.

Enhance documentation

Is your feature request related to a problem? Please describe.

  • Tutorial
  • FAQ
  • Pitfalls
  • Structure

When starting SimpleTest.java getting WELD-001456: Argument bean must not be null

Describe the bug
Whenever I try to run SimpleTest.java as shown here

https://github.com/guhilling/cdi-test

I'm getting the exception below.

To Reproduce
Steps to reproduce the behavior:

  1. Run Test
  2. See error

Expected behavior
Test should run.

Additional context
Gradle project (v7.4)
JDK 17
Windows 10

Exception
org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument bean must not be null at org.jboss.weld.util.Preconditions.checkArgumentNotNull(Preconditions.java:40) at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:708) at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:64) at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:87) at de.hilling.junit.cdi.ContextControlWrapper.getContextualReference(ContextControlWrapper.java:58) at de.hilling.junit.cdi.CdiTestJunitExtension.beforeEach(CdiTestJunitExtension.java:83) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$2(TestMethodTestDescriptor.java:163) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$6(TestMethodTestDescriptor.java:199) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:199) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachCallbacks(TestMethodTestDescriptor.java:162) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:129) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:95) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:91) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:60) at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.