-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
315 additions
and
151 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
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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/jsonzou/jmockdata/mocker/BaseMocker.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,38 @@ | ||
package com.github.jsonzou.jmockdata.mocker; | ||
|
||
import com.github.jsonzou.jmockdata.MockConfig; | ||
import com.github.jsonzou.jmockdata.Mocker; | ||
import java.lang.reflect.GenericArrayType; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.lang.reflect.TypeVariable; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class BaseMocker<T> implements Mocker<T> { | ||
|
||
private Type type; | ||
|
||
private Type[] genericTypes; | ||
|
||
public BaseMocker(Type type, Type... genericTypes) { | ||
this.type = type; | ||
this.genericTypes = genericTypes; | ||
} | ||
|
||
@Override | ||
public T mock(MockConfig mockConfig) { | ||
Mocker mocker; | ||
if (type instanceof ParameterizedType) { | ||
mocker = new GenericMocker((ParameterizedType) type); | ||
} else if (type instanceof GenericArrayType) { | ||
mocker = new ArrayMocker(type); | ||
} else if (type instanceof TypeVariable) { | ||
Type actualType = mockConfig.getVariableType(((TypeVariable) type).getName()); | ||
mocker = new BaseMocker(actualType); | ||
} else { | ||
mocker = new ClassMocker((Class) type, genericTypes); | ||
} | ||
return (T) mocker.mock(mockConfig); | ||
} | ||
|
||
} |
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.