Skip to content

Commit 3f612ea

Browse files
committed
## What's changed?
- Add (experimental) support for native interfaces and abstract classes
1 parent a6c854d commit 3f612ea

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ The purpose of this project is to generate full object graphs for use in test su
1515
- [Configuration](#configuration)
1616
- [JUnit5 Support](#junit5-support)
1717
- [Parameterized Tests](#parameterized-tests)
18+
- [Experimental Features](#experimental-features)
1819

1920

2021
## Getting Started
2122
```xml
2223
<dependency>
2324
<groupId>com.github.nylle</groupId>
2425
<artifactId>javafixture</artifactId>
25-
<version>2.9.9</version>
26+
<version>2.10.0</version>
2627
<scope>test</scope>
2728
</dependency>
2829
```
@@ -321,3 +322,21 @@ void testStringLength(String input, @Fixture TestDto fixture) {
321322
The test will be run for every `@TestCase`-annotation injecting the provided and the randomly generated values into the test's arguments.
322323

323324
**The random values will be identical for all test-cases!**
325+
326+
### Experimental Features
327+
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.
328+
329+
```java
330+
@Test
331+
void canCreateGenericObjectFromInterfaceWithMismatchingNumberOfTypeParameters() {
332+
var fixture = new Fixture(Configuration.configure().experimentalInterfaces(true));
333+
334+
var result = fixture.create(new SpecimenType<GenericInterfaceTUWithGenericImplementationU<String, Integer>>() {});
335+
336+
assertThat(result).isInstanceOf(GenericInterfaceTUWithGenericImplementationUImpl.class);
337+
assertThat(result.publicField).isInstanceOf(Integer.class);
338+
assertThat(result.getT()).isInstanceOf(String.class);
339+
assertThat(result.getU()).isInstanceOf(Integer.class);
340+
}
341+
```
342+
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".

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.github.nylle</groupId>
88
<artifactId>javafixture</artifactId>
99
<packaging>jar</packaging>
10-
<version>2.9.9</version>
10+
<version>2.10.0</version>
1111

1212
<name>JavaFixture</name>
1313
<url>https://github.com/Nylle/JavaFixture</url>

0 commit comments

Comments
 (0)