Skip to content

Commit

Permalink
Fix abstractExtends in InterfacePlugin does not support interface
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Jan 13, 2025
1 parent dcd98dd commit eae634d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public <T> InterfacePlugin abstractClassExtends(
Class<T> abstractClassType,
List<Class<? extends T>> implementations
) {
if (!Modifier.isAbstract(abstractClassType.getModifiers())) {
if (!(Modifier.isAbstract(abstractClassType.getModifiers())
&& !Modifier.isInterface(abstractClassType.getModifiers()))) {
throw new IllegalArgumentException(
"abstractClassExtends option first parameter should be abstract class. "
+ abstractClassType.getTypeName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;

import lombok.EqualsAndHashCode;
import lombok.Value;

class InterfaceTestSpecs {
Expand Down Expand Up @@ -61,4 +62,14 @@ public List<InterfaceObject> getObject() {
public static class InterfaceWrapperObject {
InterfaceObject value;
}

abstract static class AbstractClassObject {
abstract Object getObject();
}

@EqualsAndHashCode(callSuper = true)
@Value
public static class AbstractClassStringChildObject extends AbstractClassObject {
String object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -92,6 +93,8 @@
import com.navercorp.fixturemonkey.tests.java.ImmutableRecursiveTypeSpecs.SelfRecursiveListObject;
import com.navercorp.fixturemonkey.tests.java.ImmutableRecursiveTypeSpecs.SelfRecursiveMapObject;
import com.navercorp.fixturemonkey.tests.java.ImmutableRecursiveTypeSpecs.SelfRecursiveObject;
import com.navercorp.fixturemonkey.tests.java.InterfaceTestSpecs.AbstractClassObject;
import com.navercorp.fixturemonkey.tests.java.InterfaceTestSpecs.AbstractClassStringChildObject;
import com.navercorp.fixturemonkey.tests.java.InterfaceTestSpecs.InterfaceIntegerObject;
import com.navercorp.fixturemonkey.tests.java.InterfaceTestSpecs.InterfaceListObject;
import com.navercorp.fixturemonkey.tests.java.InterfaceTestSpecs.InterfaceObject;
Expand Down Expand Up @@ -1410,4 +1413,53 @@ void constructorValidator() {

then(actual.getValue()).isEqualTo(100);
}

@RepeatedTest(TEST_COUNT)
void abstractClassExtends() {
FixtureMonkey sut = FixtureMonkey.builder()
.plugin(
new InterfacePlugin()
.abstractClassExtends(
AbstractClassObject.class,
Collections.singletonList(AbstractClassStringChildObject.class))
)
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.build();

AbstractClassObject actual = sut.giveMeOne(AbstractClassObject.class);

then(actual).isExactlyInstanceOf(AbstractClassStringChildObject.class);
}

@Test
void abstractExtendsInterfaceThrows() {
thenThrownBy(
() -> FixtureMonkey.builder()
.plugin(
new InterfacePlugin()
.abstractClassExtends(
InterfaceObject.class,
Collections.singletonList(InterfaceStringObject.class))
)
.build()
)
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("should be abstract class");
}

@Test
void interfaceImplementsAbstractClassThrows() {
thenThrownBy(
() -> FixtureMonkey.builder()
.plugin(
new InterfacePlugin()
.interfaceImplements(
AbstractClassObject.class,
Collections.singletonList(AbstractClassStringChildObject.class))
)
.build()
)
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("should be interface");
}
}

0 comments on commit eae634d

Please sign in to comment.