Skip to content

Commit 87937b3

Browse files
committed
refactor: rename instantiators to reflect interface
1 parent b9421db commit 87937b3

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

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

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

3-
import com.github.nylle.javafixture.instantiation.Builder;
3+
import com.github.nylle.javafixture.instantiation.BuilderInstantiator;
44

55
import java.lang.reflect.Constructor;
66
import java.lang.reflect.Method;
@@ -226,12 +226,12 @@ public List<Method> getFactoryMethods() {
226226
.collect(Collectors.toList());
227227
}
228228

229-
public List<Builder<T>> findBuilders() {
229+
public List<BuilderInstantiator<T>> findBuilders() {
230230
return Stream.of(asClass().getDeclaredMethods())
231231
.filter(m -> Modifier.isStatic(m.getModifiers()))
232232
.filter(m -> Modifier.isPublic(m.getModifiers()))
233233
.filter(m -> !m.getReturnType().equals(asClass()))
234-
.map(m -> Builder.create(m, this))
234+
.map(m -> BuilderInstantiator.create(m, this))
235235
.filter(b -> b != null)
236236
.collect(toList());
237237
}

src/main/java/com/github/nylle/javafixture/instantiation/Builder.java renamed to src/main/java/com/github/nylle/javafixture/instantiation/BuilderInstantiator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414

1515
import static java.util.stream.Collectors.toList;
1616

17-
public class Builder<T> implements Instantiator<T> {
17+
public class BuilderInstantiator<T> implements Instantiator<T> {
1818

1919
private final Method buildMethod;
2020
private final Method builderMethod;
2121

22-
private Builder(Method builderMethod, Method buildMethod) {
22+
private BuilderInstantiator(Method builderMethod, Method buildMethod) {
2323
this.builderMethod = builderMethod;
2424
this.buildMethod = buildMethod;
2525
}
2626

27-
public static <T> Builder<T> create(Method builderMethodCandidate, SpecimenType<T> targetType) {
27+
public static <T> BuilderInstantiator<T> create(Method builderMethodCandidate, SpecimenType<T> targetType) {
2828
return findBuildMethod(builderMethodCandidate.getReturnType(), targetType.asClass())
29-
.map(x -> new Builder<T>(builderMethodCandidate, x))
29+
.map(x -> new BuilderInstantiator<T>(builderMethodCandidate, x))
3030
.orElse(null);
3131
}
3232

src/main/java/com/github/nylle/javafixture/instantiation/Constructor.java renamed to src/main/java/com/github/nylle/javafixture/instantiation/ConstructorInstantiator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
import static java.util.Arrays.stream;
1313

14-
public class Constructor<T> implements Instantiator<T> {
14+
public class ConstructorInstantiator<T> implements Instantiator<T> {
1515

1616
private final java.lang.reflect.Constructor<T> constructor;
1717

18-
private Constructor(java.lang.reflect.Constructor<T> constructor) {
18+
private ConstructorInstantiator(java.lang.reflect.Constructor<T> constructor) {
1919
this.constructor = constructor;
2020
}
2121

22-
public static <T> Constructor<T> create(java.lang.reflect.Constructor<T> constructor) {
23-
return new Constructor<>(constructor);
22+
public static <T> ConstructorInstantiator<T> create(java.lang.reflect.Constructor<T> constructor) {
23+
return new ConstructorInstantiator<>(constructor);
2424
}
2525

2626
public T invoke(SpecimenFactory specimenFactory, CustomizationContext customizationContext) {

src/main/java/com/github/nylle/javafixture/instantiation/FactoryMethod.java renamed to src/main/java/com/github/nylle/javafixture/instantiation/FactoryMethodInstantiator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12-
public class FactoryMethod<T> implements Instantiator<T> {
12+
public class FactoryMethodInstantiator<T> implements Instantiator<T> {
1313

1414
private final Method factoryMethod;
1515
private final SpecimenType<T> targetType;
1616

17-
public FactoryMethod(Method factoryMethod, SpecimenType<T> targetType) {
17+
public FactoryMethodInstantiator(Method factoryMethod, SpecimenType<T> targetType) {
1818
this.factoryMethod = factoryMethod;
1919
this.targetType = targetType;
2020
}
2121

22-
public static <T> FactoryMethod<T> create(Method factoryMethod, SpecimenType<T> targetType) {
23-
return new FactoryMethod<>(factoryMethod, targetType);
22+
public static <T> FactoryMethodInstantiator<T> create(Method factoryMethod, SpecimenType<T> targetType) {
23+
return new FactoryMethodInstantiator<>(factoryMethod, targetType);
2424
}
2525

2626
public T invoke(SpecimenFactory specimenFactory, CustomizationContext customizationContext) {

src/test/java/com/github/nylle/javafixture/instantiation/BuilderTest.java renamed to src/test/java/com/github/nylle/javafixture/instantiation/BuilderInstantiatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
import static org.assertj.core.api.Assertions.assertThat;
1212

13-
class BuilderTest {
13+
class BuilderInstantiatorTest {
1414

1515
@Test
1616
void invokeReturnsBuiltObjectWithAllMethodsCalled() throws NoSuchMethodException {
17-
var sut = Builder.create(ClassWithBuilder.class.getMethod("builder"), SpecimenType.fromClass(ClassWithBuilder.class));
17+
var sut = BuilderInstantiator.create(ClassWithBuilder.class.getMethod("builder"), SpecimenType.fromClass(ClassWithBuilder.class));
1818

1919
var result = sut.invoke(new SpecimenFactory(new Context(new Configuration())), CustomizationContext.noContext());
2020

src/test/java/com/github/nylle/javafixture/instantiation/ConstructorTest.java renamed to src/test/java/com/github/nylle/javafixture/instantiation/ConstructorInstantiatorTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
1818

19-
class ConstructorTest {
19+
class ConstructorInstantiatorTest {
2020

2121
@Test
2222
@DisplayName("returns instance")
2323
void canCreateInstanceFromConstructor() throws NoSuchMethodException {
24-
var sut = Constructor.create(TestObjectWithGenericConstructor.class.getConstructor(String.class, Optional.class));
24+
var sut = ConstructorInstantiator.create(TestObjectWithGenericConstructor.class.getConstructor(String.class, Optional.class));
2525

2626
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of(), Map.of(), false));
2727

@@ -33,7 +33,7 @@ void canCreateInstanceFromConstructor() throws NoSuchMethodException {
3333
@Test
3434
@DisplayName("fields not set by constructor are null")
3535
void fieldsNotSetByConstructorAreNull() throws NoSuchMethodException {
36-
var sut = Constructor.create(TestObjectWithGenericConstructor.class.getConstructor(String.class, Optional.class));
36+
var sut = ConstructorInstantiator.create(TestObjectWithGenericConstructor.class.getConstructor(String.class, Optional.class));
3737

3838
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of(), Map.of(), false));
3939

@@ -44,7 +44,7 @@ void fieldsNotSetByConstructorAreNull() throws NoSuchMethodException {
4444
@Test
4545
@DisplayName("arguments can be customized")
4646
void argumentsCanBeCustomized() throws NoSuchMethodException {
47-
var sut = Constructor.create(TestObject.class.getConstructor(String.class, List.class, Map.class));
47+
var sut = ConstructorInstantiator.create(TestObject.class.getConstructor(String.class, List.class, Map.class));
4848

4949
// use arg0, because .class files do not store formal parameter names by default
5050
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of(), Map.of("arg0", "customized"), true));
@@ -55,7 +55,7 @@ void argumentsCanBeCustomized() throws NoSuchMethodException {
5555
@Test
5656
@DisplayName("using constructor is used for all instances")
5757
void usingConstructorIsRecursive() throws NoSuchMethodException {
58-
var sut = Constructor.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
58+
var sut = ConstructorInstantiator.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
5959

6060
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of(), Map.of(), true));
6161

@@ -67,7 +67,7 @@ void usingConstructorIsRecursive() throws NoSuchMethodException {
6767
@Test
6868
@DisplayName("customized arguments are only used for the top level object (no nested objects)")
6969
void constructorArgumentsAreUsedOnce() throws NoSuchMethodException {
70-
var sut = Constructor.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
70+
var sut = ConstructorInstantiator.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
7171

7272
// use arg0, because .class files do not store formal parameter names by default
7373
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of(), Map.of("arg0", 2), true));
@@ -78,7 +78,7 @@ void constructorArgumentsAreUsedOnce() throws NoSuchMethodException {
7878
@Test
7979
@DisplayName("customized arguments are used for exclusion, too")
8080
void ignoredConstructorArgsAreRespected() throws NoSuchMethodException {
81-
var sut = Constructor.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
81+
var sut = ConstructorInstantiator.create(TestObjectWithConstructedField.class.getConstructor(int.class, TestObjectWithGenericConstructor.class));
8282

8383
// use arg0, because .class files do not store formal parameter names by default
8484
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), new CustomizationContext(List.of("arg0"), Map.of(), true));

src/test/java/com/github/nylle/javafixture/instantiation/FactoryMethodTest.java renamed to src/test/java/com/github/nylle/javafixture/instantiation/FactoryMethodInstantiatorTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import static com.github.nylle.javafixture.SpecimenType.fromClass;
1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21-
class FactoryMethodTest {
21+
class FactoryMethodInstantiatorTest {
2222

2323
@Test
2424
@DisplayName("returns instance of class using factory method without arguments")
2525
void factoryMethodWithoutArgument() throws NoSuchMethodException {
26-
var sut = FactoryMethod.<FactoryMethodWithoutArgument>create(FactoryMethodWithoutArgument.class.getDeclaredMethod("factoryMethod"), fromClass(FactoryMethodWithoutArgument.class));
26+
var sut = FactoryMethodInstantiator.<FactoryMethodWithoutArgument>create(FactoryMethodWithoutArgument.class.getDeclaredMethod("factoryMethod"), fromClass(FactoryMethodWithoutArgument.class));
2727

2828
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
2929

@@ -33,7 +33,7 @@ void factoryMethodWithoutArgument() throws NoSuchMethodException {
3333
@Test
3434
@DisplayName("returns instance of class using factory method with arguments")
3535
void returnsInstanceOfClassUsingFactoryMethodWithArguments() throws NoSuchMethodException {
36-
var sut = FactoryMethod.<FactoryMethodWithArgument>create(FactoryMethodWithArgument.class.getDeclaredMethod("factoryMethod", int.class), fromClass(FactoryMethodWithArgument.class));
36+
var sut = FactoryMethodInstantiator.<FactoryMethodWithArgument>create(FactoryMethodWithArgument.class.getDeclaredMethod("factoryMethod", int.class), fromClass(FactoryMethodWithArgument.class));
3737

3838
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
3939

@@ -43,7 +43,7 @@ void returnsInstanceOfClassUsingFactoryMethodWithArguments() throws NoSuchMethod
4343
@Test
4444
@DisplayName("returns instance of class using factory method with generic argument")
4545
void factoryMethodWithGenericArgument() throws NoSuchMethodException {
46-
var sut = FactoryMethod.create(FactoryMethodWithGenericArgument.class.getDeclaredMethod("factoryMethod", Object.class), new SpecimenType<FactoryMethodWithGenericArgument<Integer>>() {});
46+
var sut = FactoryMethodInstantiator.create(FactoryMethodWithGenericArgument.class.getDeclaredMethod("factoryMethod", Object.class), new SpecimenType<FactoryMethodWithGenericArgument<Integer>>() {});
4747

4848
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
4949

@@ -53,7 +53,7 @@ void factoryMethodWithGenericArgument() throws NoSuchMethodException {
5353
@Test
5454
@DisplayName("returns instance of abstract class using factory method without arguments")
5555
void returnsInstanceOfAbstractClassUsingFactoryMethod() throws NoSuchMethodException {
56-
var sut = FactoryMethod.create(Charset.class.getDeclaredMethod("defaultCharset"), new SpecimenType<Charset>() {});
56+
var sut = FactoryMethodInstantiator.create(Charset.class.getDeclaredMethod("defaultCharset"), new SpecimenType<Charset>() {});
5757

5858
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
5959

@@ -63,7 +63,7 @@ void returnsInstanceOfAbstractClassUsingFactoryMethod() throws NoSuchMethodExcep
6363
@Test
6464
@DisplayName("returns instance of Optional using factory method with arguments")
6565
void createOptionalWithArgument() throws NoSuchMethodException {
66-
var sut = FactoryMethod.create(Optional.class.getDeclaredMethod("of", Object.class), new SpecimenType<Optional<String>>() {});
66+
var sut = FactoryMethodInstantiator.create(Optional.class.getDeclaredMethod("of", Object.class), new SpecimenType<Optional<String>>() {});
6767

6868
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
6969

@@ -75,7 +75,7 @@ void createOptionalWithArgument() throws NoSuchMethodException {
7575
@Test
7676
@DisplayName("returns instance of Optional using factory method without arguments")
7777
void createOptionalWithoutArgument() throws NoSuchMethodException {
78-
var sut = FactoryMethod.create(Optional.class.getDeclaredMethod("empty"), new SpecimenType<Optional<String>>() {});
78+
var sut = FactoryMethodInstantiator.create(Optional.class.getDeclaredMethod("empty"), new SpecimenType<Optional<String>>() {});
7979

8080
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
8181

@@ -86,7 +86,7 @@ void createOptionalWithoutArgument() throws NoSuchMethodException {
8686
@Test
8787
@DisplayName("returns instance of generic class using generic method without arguments")
8888
void genericNoArgumentFactoryMethod() throws NoSuchMethodException {
89-
var sut = FactoryMethod.create(GenericClassWithFactoryMethodWithoutArgument.class.getDeclaredMethod("factoryMethod"), new SpecimenType<GenericClassWithFactoryMethodWithoutArgument<Integer>>() {});
89+
var sut = FactoryMethodInstantiator.create(GenericClassWithFactoryMethodWithoutArgument.class.getDeclaredMethod("factoryMethod"), new SpecimenType<GenericClassWithFactoryMethodWithoutArgument<Integer>>() {});
9090

9191
var actual = sut.invoke(new SpecimenFactory(new Context(Configuration.configure())), noContext());
9292

0 commit comments

Comments
 (0)