-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented withFactory option in collection contract
- Loading branch information
Showing
17 changed files
with
564 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
main/java/org/quackery/contract/collection/Assumptions.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
main/java/org/quackery/contract/collection/ConstructorCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.quackery.contract.collection; | ||
|
||
import static org.quackery.AssumptionException.assume; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.util.Collection; | ||
|
||
import org.quackery.AssumptionException; | ||
|
||
public class ConstructorCreator implements Creator { | ||
private final Class<?> type; | ||
|
||
public ConstructorCreator(Class<?> type) { | ||
this.type = type; | ||
} | ||
|
||
public <T> T create(Class<T> cast, Object original) throws ReflectiveOperationException { | ||
assume(cast.isAssignableFrom(type)); | ||
try { | ||
Constructor<?> constructor = type.getConstructor(Collection.class); | ||
return cast.cast(constructor.newInstance(original)); | ||
} catch (NoSuchMethodException e) { | ||
throw new AssumptionException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.quackery.contract.collection; | ||
|
||
public interface Creator { | ||
<T> T create(Class<T> cast, Object original) throws ReflectiveOperationException; | ||
} |
30 changes: 30 additions & 0 deletions
30
main/java/org/quackery/contract/collection/FactoryCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.quackery.contract.collection; | ||
|
||
import static org.quackery.AssumptionException.assume; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Collection; | ||
|
||
import org.quackery.AssumptionException; | ||
|
||
public class FactoryCreator implements Creator { | ||
private final Class<?> type; | ||
private final String methodName; | ||
|
||
public FactoryCreator(Class<?> type, String methodName) { | ||
this.type = type; | ||
this.methodName = methodName; | ||
} | ||
|
||
public <T> T create(Class<T> cast, Object original) throws ReflectiveOperationException { | ||
try { | ||
Method method = type.getMethod(methodName, Collection.class); | ||
assume(cast.isAssignableFrom(method.getReturnType())); | ||
assume(Modifier.isStatic(method.getModifiers())); | ||
return cast.cast(method.invoke(null, original)); | ||
} catch (NoSuchMethodException e) { | ||
throw new AssumptionException(); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
main/java/org/quackery/contract/collection/suite/CollectionMutableSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.