Skip to content

Commit

Permalink
refactor: remove ExperimentalAbstractSpecimen
Browse files Browse the repository at this point in the history
This will remove experimental support for finding concrete
implementations for abstract classes and interfaces as an alternative
to proxying. Unfortunately, this experiment failed and will be
discontinued.
  • Loading branch information
Nylle committed Aug 22, 2024
1 parent 1991eb4 commit 14abe3f
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 670 deletions.
64 changes: 0 additions & 64 deletions src/main/java/com/github/nylle/javafixture/ClassPathScanner.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/com/github/nylle/javafixture/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.github.nylle.javafixture;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
Expand All @@ -13,7 +10,6 @@ public class Configuration {
private int minCollectionSize = 2;
private int streamSize = 3;
private boolean usePositiveNumbersOnly = false;
private boolean experimentalInterfaces = false;

private Clock clock = Clock.fixed(Instant.now(), ZoneOffset.UTC);

Expand All @@ -28,7 +24,6 @@ public class Configuration {
* </ul><p>
*/
public Configuration() {
this.experimentalInterfaces = experimentalInterfacesIsEnabled();
}

/**
Expand Down Expand Up @@ -115,10 +110,6 @@ public boolean usePositiveNumbersOnly() {
return this.usePositiveNumbersOnly;
}

public boolean experimentalInterfaces() {
return this.experimentalInterfaces;
}

/**
* @param streamSize the stream size when creating many objects at once
* @return this {@code Configuration}
Expand Down Expand Up @@ -159,11 +150,6 @@ public Configuration usePositiveNumbersOnly(boolean usePositiveNumbersOnly) {
return this;
}

public Configuration experimentalInterfaces(boolean experimentalInterfaces) {
this.experimentalInterfaces = experimentalInterfaces;
return this;
}

/**
* Returns a new fixture with this configuration
*
Expand All @@ -172,15 +158,4 @@ public Configuration experimentalInterfaces(boolean experimentalInterfaces) {
public Fixture fixture() {
return new Fixture(this);
}

private boolean experimentalInterfacesIsEnabled() {
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream("javafixture/com.github.nylle.javafixture.experimetalInterfaces")) {
if (in == null) {
return false;
}
return new BufferedReader(new InputStreamReader(in)).lines().findFirst().map(x -> x.equals("enabled")).orElse(false);
} catch (Exception ex) {
return false;
}
}
}
16 changes: 0 additions & 16 deletions src/main/java/com/github/nylle/javafixture/SpecimenFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.nylle.javafixture.specimen.ArraySpecimen;
import com.github.nylle.javafixture.specimen.CollectionSpecimen;
import com.github.nylle.javafixture.specimen.EnumSpecimen;
import com.github.nylle.javafixture.specimen.ExperimentalAbstractSpecimen;
import com.github.nylle.javafixture.specimen.GenericSpecimen;
import com.github.nylle.javafixture.specimen.InterfaceSpecimen;
import com.github.nylle.javafixture.specimen.MapSpecimen;
Expand Down Expand Up @@ -49,10 +48,6 @@ public <T> ISpecimen<T> build(final SpecimenType<T> type) {
}

if (type.isParameterized() && (type.isInterface() || type.isAbstract())) {
if (context.getConfiguration().experimentalInterfaces()) {
return experimentalAbstract(type);
}

return new GenericSpecimen<>(type, context, this);
}

Expand All @@ -65,17 +60,10 @@ public <T> ISpecimen<T> build(final SpecimenType<T> type) {
}

if (type.isInterface()) {
if (context.getConfiguration().experimentalInterfaces()) {
return experimentalAbstract(type);
}

return new InterfaceSpecimen<>(type, context, this);
}

if (type.isAbstract()) {
if (context.getConfiguration().experimentalInterfaces()) {
return experimentalAbstract(type);
}
return new AbstractSpecimen<>(type, context, this);
}

Expand All @@ -85,9 +73,5 @@ public <T> ISpecimen<T> build(final SpecimenType<T> type) {

return new ObjectSpecimen<>(type, context, this);
}

private <T> ISpecimen<T> experimentalAbstract(SpecimenType<T> interfaceType) {
return new ExperimentalAbstractSpecimen<>(interfaceType, new ClassPathScanner().findAllClassesFor(interfaceType), context, this);
}
}

This file was deleted.

Loading

0 comments on commit 14abe3f

Please sign in to comment.