Skip to content

Commit a6c854d

Browse files
committed
feat: allow global experimentalInterfaces
...by putting a file "javafixture/com.github.nylle.javafixture.experimetalInterfaces" onto your class path, with the content "enabled".
1 parent 70f7f2b commit a6c854d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/java/com/github/nylle/javafixture/Configuration.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.github.nylle.javafixture;
22

3+
import java.io.BufferedReader;
4+
import java.io.InputStream;
5+
import java.io.InputStreamReader;
36
import java.time.Clock;
47
import java.time.Instant;
58
import java.time.ZoneOffset;
@@ -25,6 +28,7 @@ public class Configuration {
2528
* </ul><p>
2629
*/
2730
public Configuration() {
31+
this.experimentalInterfaces = experimentalInterfacesIsEnabled();
2832
}
2933

3034
/**
@@ -35,6 +39,7 @@ public Configuration() {
3539
* @param streamSize the exact size of the result stream when creating many objects at once
3640
*/
3741
public Configuration(final int maxCollectionSize, final int minCollectionSize, final int streamSize) {
42+
this();
3843
this.maxCollectionSize = maxCollectionSize;
3944
this.minCollectionSize = minCollectionSize;
4045
this.streamSize = streamSize;
@@ -50,9 +55,7 @@ public Configuration(final int maxCollectionSize, final int minCollectionSize, f
5055
* @param usePositiveNumbersOnly whether to generate only positive numbers including 0
5156
*/
5257
public Configuration(final int maxCollectionSize, final int minCollectionSize, final int streamSize, final boolean usePositiveNumbersOnly) {
53-
this.maxCollectionSize = maxCollectionSize;
54-
this.minCollectionSize = minCollectionSize;
55-
this.streamSize = streamSize;
58+
this(maxCollectionSize, minCollectionSize, streamSize);
5659
this.usePositiveNumbersOnly = usePositiveNumbersOnly;
5760
}
5861

@@ -169,4 +172,15 @@ public Configuration experimentalInterfaces(boolean experimentalInterfaces) {
169172
public Fixture fixture() {
170173
return new Fixture(this);
171174
}
175+
176+
private boolean experimentalInterfacesIsEnabled() {
177+
try(InputStream in = this.getClass().getClassLoader().getResourceAsStream("javafixture/com.github.nylle.javafixture.experimetalInterfaces")) {
178+
if(in == null) {
179+
return false;
180+
}
181+
return new BufferedReader(new InputStreamReader(in)).lines().findFirst().map(x -> x.equals("enabled")).orElse(false);
182+
} catch(Exception ex) {
183+
return false;
184+
}
185+
}
172186
}

0 commit comments

Comments
 (0)