mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-24 19:31:17 +08:00
add one to multi test case and refactor demo packages
This commit is contained in:
parent
cfc28467bb
commit
55ccabbb39
@ -1,8 +1,8 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.model.Box;
|
||||
import com.alibaba.testable.demo.model.Color;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.model.Box;
|
||||
import com.alibaba.testable.demo.basic.model.Color;
|
||||
|
||||
/**
|
||||
* 演示父类变量引用子类对象时的Mock场景
|
@ -1,7 +1,7 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
@ -1,6 +1,6 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.model;
|
||||
package com.alibaba.testable.demo.basic.model;
|
||||
|
||||
public class BlackBox extends Box implements Color {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.model;
|
||||
package com.alibaba.testable.demo.basic.model;
|
||||
|
||||
abstract public class Box {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.model;
|
||||
package com.alibaba.testable.demo.basic.model;
|
||||
|
||||
public interface Color {
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
public class ASvc {
|
||||
|
||||
public String demo(String name) {
|
||||
return String.format("a_%s", name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
public class BSvc {
|
||||
|
||||
public String demo(String name) {
|
||||
return String.format("b_%s", name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
public class CSvc {
|
||||
|
||||
public String demo(String name) {
|
||||
return String.format("c_%s", name);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.model.Box;
|
||||
import com.alibaba.testable.demo.model.Color;
|
||||
import com.alibaba.testable.demo.basic.DemoInherit;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.model.Box;
|
||||
import com.alibaba.testable.demo.basic.model.Color;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
|
@ -1,8 +1,9 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
import com.alibaba.testable.core.error.VerifyFailedError;
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.DemoMatcher;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.alibaba.testable.core.matcher.InvokeMatcher.*;
|
@ -1,8 +1,9 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockConstructor;
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
import com.alibaba.testable.demo.model.BlackBox;
|
||||
import com.alibaba.testable.demo.basic.DemoMock;
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.Executors;
|
@ -1,6 +1,7 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.core.accessor.PrivateAccessor;
|
||||
import com.alibaba.testable.demo.basic.DemoPrivateAccess;
|
||||
import com.alibaba.testable.processor.annotation.EnablePrivateAccess;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.alibaba.testable.demo;
|
||||
package com.alibaba.testable.demo.basic;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockConstructor;
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
import com.alibaba.testable.demo.basic.DemoTemplate;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
|
||||
public class ASvcMock {
|
||||
|
||||
@MockMethod(targetClass = String.class, targetMethod = "format")
|
||||
public String a_format(String format, Object... args) {
|
||||
return "a_mock";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
|
||||
public class BSvcMock {
|
||||
|
||||
@MockMethod(targetClass = String.class, targetMethod = "format")
|
||||
public String b_format(String format, Object... args) {
|
||||
return "b_mock";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod;
|
||||
|
||||
public class CSvcMock {
|
||||
|
||||
@MockMethod(targetClass = String.class, targetMethod = "format")
|
||||
public String c_format(String format, Object... args) {
|
||||
return "c_mock";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.alibaba.testable.demo.one2multi;
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
import static com.alibaba.testable.core.matcher.InvokeVerifier.verify;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@MockWith
|
||||
public class OneToMultiSvcTest {
|
||||
|
||||
private ASvc aSvc = new ASvc();
|
||||
private BSvc bSvc = new BSvc();
|
||||
private CSvc cSvc = new CSvc();
|
||||
|
||||
@Test
|
||||
public void should_able_to_test_multi_class_together() {
|
||||
assertEquals("a_mock", aSvc.demo("test"));
|
||||
assertEquals("b_mock", bSvc.demo("test"));
|
||||
assertEquals("c_mock", cSvc.demo("test"));
|
||||
verify("a_format").withTimes(1);
|
||||
verify("b_format").withTimes(1);
|
||||
verify("c_format").withTimes(1);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.model.Box
|
||||
import com.alibaba.testable.demo.model.Color
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.Box
|
||||
import com.alibaba.testable.demo.basic.model.Color
|
||||
|
||||
/**
|
||||
* 演示父类变量引用子类对象时的Mock场景
|
@ -1,6 +1,6 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import java.util.*
|
||||
|
||||
/**
|
@ -1,7 +1,7 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.model.ColorBox
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.ColorBox
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
/**
|
||||
* 演示私有成员访问功能
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.model
|
||||
package com.alibaba.testable.demo.basic.model
|
||||
|
||||
|
||||
class BlackBox(var input: String) : Box(), Color {
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.model
|
||||
package com.alibaba.testable.demo.basic.model
|
||||
|
||||
abstract class Box {
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.alibaba.testable.demo.basic.model
|
||||
|
||||
interface Color {
|
||||
|
||||
val color: String
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.util
|
||||
package com.alibaba.testable.demo.java2kotlin
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.testable.demo.model
|
||||
|
||||
interface Color {
|
||||
|
||||
val color: String
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
class ASvc {
|
||||
|
||||
fun demo(name: String): String {
|
||||
return String.format("a_%s", name)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
class BSvc {
|
||||
|
||||
fun demo(name: String): String {
|
||||
return String.format("b_%s", name)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
class CSvc {
|
||||
|
||||
fun demo(name: String): String {
|
||||
return String.format("c_%s", name)
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
import com.alibaba.testable.core.matcher.InvokeVerifier
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.model.Box
|
||||
import com.alibaba.testable.demo.model.Color
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.Box
|
||||
import com.alibaba.testable.demo.basic.model.Color
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
import com.alibaba.testable.core.error.VerifyFailedError
|
||||
import com.alibaba.testable.core.matcher.InvokeMatcher
|
||||
import com.alibaba.testable.core.matcher.InvokeVerifier
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockConstructor
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
import com.alibaba.testable.core.matcher.InvokeVerifier.verify
|
||||
import com.alibaba.testable.core.tool.TestableTool.SOURCE_METHOD
|
||||
import com.alibaba.testable.core.tool.TestableTool.MOCK_CONTEXT
|
||||
import com.alibaba.testable.demo.model.BlackBox
|
||||
import com.alibaba.testable.demo.model.ColorBox
|
||||
import com.alibaba.testable.demo.basic.model.BlackBox
|
||||
import com.alibaba.testable.demo.basic.model.ColorBox
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.concurrent.Executors
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.core.accessor.PrivateAccessor
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo
|
||||
package com.alibaba.testable.demo.basic
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockConstructor
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.testable.demo.util
|
||||
package com.alibaba.testable.demo.java2kotlin
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
import com.alibaba.testable.core.matcher.InvokeVerifier.verify
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
|
||||
class ASvcMock {
|
||||
|
||||
@MockMethod(targetClass = String::class, targetMethod = "format")
|
||||
fun a_format(format: String, vararg args: Any?): String {
|
||||
return "a_mock"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
|
||||
class BSvcMock {
|
||||
|
||||
@MockMethod(targetClass = String::class, targetMethod = "format")
|
||||
fun b_format(format: String, vararg args: Any?): String {
|
||||
return "b_mock"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockMethod
|
||||
|
||||
class CSvcMock {
|
||||
|
||||
@MockMethod(targetClass = String::class, targetMethod = "format")
|
||||
fun c_format(format: String, vararg args: Any?): String {
|
||||
return "c_mock"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.alibaba.testable.demo.one2multi
|
||||
|
||||
import com.alibaba.testable.core.annotation.MockWith
|
||||
import com.alibaba.testable.core.matcher.InvokeVerifier.verify
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@MockWith
|
||||
class OneToMultiSvcTest {
|
||||
|
||||
private val aSvc = ASvc()
|
||||
private val bSvc = BSvc()
|
||||
private val cSvc = CSvc()
|
||||
|
||||
@Test
|
||||
fun should_able_to_test_multi_class_together() {
|
||||
Assertions.assertEquals("a_mock", aSvc.demo("test"))
|
||||
Assertions.assertEquals("b_mock", bSvc.demo("test"))
|
||||
Assertions.assertEquals("c_mock", cSvc.demo("test"))
|
||||
verify("a_format").withTimes(1)
|
||||
verify("b_format").withTimes(1)
|
||||
verify("c_format").withTimes(1)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user