mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-24 03:10:14 +08:00
add demo case for access private method with interface parameter
This commit is contained in:
parent
d6ac715f57
commit
44fed6ce8b
@ -1,5 +1,7 @@
|
||||
package com.alibaba.testable.demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 演示私有成员访问功能
|
||||
* Demonstrate private member access functionality
|
||||
@ -22,15 +24,15 @@ public class DemoPrivateAccess {
|
||||
/**
|
||||
* private static method
|
||||
*/
|
||||
private static String privateStaticFunc(String s, int i) {
|
||||
return s + " + " + i;
|
||||
private static String privateStaticFunc(String str, int i) {
|
||||
return str + " + " + i;
|
||||
}
|
||||
|
||||
/**
|
||||
* private member method
|
||||
*/
|
||||
private String privateFunc(String s, int i) {
|
||||
return s + " - " + i;
|
||||
private String privateFunc(List<String> list, String str, int i) {
|
||||
return list.stream().reduce((a, s) -> a + s).orElse("") + " + " + str + " + " + i;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import com.alibaba.testable.core.accessor.PrivateAccessor;
|
||||
import com.alibaba.testable.processor.annotation.EnablePrivateAccess;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@ -17,8 +20,9 @@ class DemoPrivateAccessTest {
|
||||
|
||||
@Test
|
||||
void should_able_to_access_private_method() {
|
||||
assertEquals("hello - 1", demoPrivateAccess.privateFunc("hello", 1));
|
||||
assertEquals("hello - 1", PrivateAccessor.invoke(demoPrivateAccess, "privateFunc", "hello", 1));
|
||||
List<String> list = new ArrayList<String>() {{ add("a"); add("b"); add("c"); }};
|
||||
assertEquals("abc + hello + 1", demoPrivateAccess.privateFunc(list, "hello", 1));
|
||||
assertEquals("abc + hello + 1", PrivateAccessor.invoke(demoPrivateAccess, "privateFunc", list, "hello", 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user