Skip to content

Commit

Permalink
## What's changed?
Browse files Browse the repository at this point in the history
- Add (experimental) support for native interfaces and abstract classes
  • Loading branch information
Nylle committed Nov 19, 2023
1 parent a6c854d commit 3f612ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ The purpose of this project is to generate full object graphs for use in test su
- [Configuration](#configuration)
- [JUnit5 Support](#junit5-support)
- [Parameterized Tests](#parameterized-tests)
- [Experimental Features](#experimental-features)


## Getting Started
```xml
<dependency>
<groupId>com.github.nylle</groupId>
<artifactId>javafixture</artifactId>
<version>2.9.9</version>
<version>2.10.0</version>
<scope>test</scope>
</dependency>
```
Expand Down Expand Up @@ -321,3 +322,21 @@ void testStringLength(String input, @Fixture TestDto fixture) {
The test will be run for every `@TestCase`-annotation injecting the provided and the randomly generated values into the test's arguments.

**The random values will be identical for all test-cases!**

### Experimental Features
Since version 2.10.0, a new experimental feature is available. If you enable `experimentalInterfaces`, Fixture will attempt to find implementations for an interface (or non-abstract subclasses of an abstract class) on your classpath and create those instead of wrapping the interface with a proxy. If no suitable implementation is found, the proxy will be created as a fallback.

```java
@Test
void canCreateGenericObjectFromInterfaceWithMismatchingNumberOfTypeParameters() {
var fixture = new Fixture(Configuration.configure().experimentalInterfaces(true));

var result = fixture.create(new SpecimenType<GenericInterfaceTUWithGenericImplementationU<String, Integer>>() {});

assertThat(result).isInstanceOf(GenericInterfaceTUWithGenericImplementationUImpl.class);
assertThat(result.publicField).isInstanceOf(Integer.class);
assertThat(result.getT()).isInstanceOf(String.class);
assertThat(result.getU()).isInstanceOf(Integer.class);
}
```
This setting is not supported with annotations. However, to enable this feature globally, place a file `javafixture/com.github.nylle.javafixture.experimetalInterfaces` on your classpath with the content "enabled". To disable it, either delete the file or change the content to something else, e.g. "disabled".
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.github.nylle</groupId>
<artifactId>javafixture</artifactId>
<packaging>jar</packaging>
<version>2.9.9</version>
<version>2.10.0</version>

<name>JavaFixture</name>
<url>https://github.com/Nylle/JavaFixture</url>
Expand Down

0 comments on commit 3f612ea

Please sign in to comment.