-
Notifications
You must be signed in to change notification settings - Fork 3
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
7 changed files
with
136 additions
and
10 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
22 changes: 22 additions & 0 deletions
22
litool-test/src/main/java/io/leaderli/litool/test/RecordBeanInterface.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,22 @@ | ||
package io.leaderli.litool.test; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public interface RecordBeanInterface<B, T> { | ||
|
||
B consume(Consumer<T> call); | ||
|
||
B when(Function<T, Object> call); | ||
|
||
B called(); | ||
|
||
B arg(int index, Object arg); | ||
|
||
B args(Object... args); | ||
|
||
B assertReturn(Object compareReturn); | ||
|
||
T build(); | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
litool-test/src/main/java/io/leaderli/litool/test/RecordBeans.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,68 @@ | ||
package io.leaderli.litool.test; | ||
|
||
import io.leaderli.litool.core.exception.LiAssertUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public class RecordBeans<T> implements RecordBeanInterface<RecordBeans<T>, T> { | ||
private final List<RecordBean<T>> recordBeans = new ArrayList<>(); | ||
private final List<Consumer<RecordBean<T>>> recordBeanAction = new ArrayList<>(); | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
public RecordBeans(Class<? extends T>... mockClasses) { | ||
|
||
for (Class<? extends T> mockClass : mockClasses) { | ||
recordBeans.add(new RecordBean<>((Class<T>) mockClass)); | ||
} | ||
} | ||
|
||
public RecordBeans<T> consume(Consumer<T> consumer) { | ||
recordBeanAction.add(recordbean -> recordbean.consume(consumer)); | ||
return this; | ||
} | ||
|
||
public RecordBeans<T> when(Function<T, Object> function) { | ||
recordBeanAction.add(recordbean -> recordbean.when(function)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RecordBeans<T> called() { | ||
recordBeanAction.add(AbstractRecorder::called); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RecordBeans<T> arg(int index, Object arg) { | ||
recordBeanAction.add(recordbean -> recordbean.arg(index, arg)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RecordBeans<T> args(Object... args) { | ||
recordBeanAction.add(recordbean -> recordbean.args(args)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RecordBeans<T> assertReturn(Object compareReturn) { | ||
recordBeanAction.add(recordbean -> recordbean.assertReturn(compareReturn)); | ||
return this; | ||
} | ||
|
||
public T build() { | ||
T instance = null; | ||
for (RecordBean<T> mockBean : recordBeans) { | ||
recordBeanAction.forEach(action -> action.accept(mockBean)); | ||
instance = mockBean.build(); | ||
} | ||
LiAssertUtil.assertFalse(instance == null, new IllegalArgumentException()); | ||
return instance; | ||
} | ||
|
||
|
||
} |
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