add one to multi test case and refactor demo packages

This commit is contained in:
金戟 2021-02-21 10:20:59 +08:00
parent cfc28467bb
commit 55ccabbb39
43 changed files with 239 additions and 56 deletions

View File

@ -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场景

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo;
package com.alibaba.testable.demo.basic;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo;
package com.alibaba.testable.demo.basic;
import java.util.*;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.model;
package com.alibaba.testable.demo.basic.model;
public class BlackBox extends Box implements Color {

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.model;
package com.alibaba.testable.demo.basic.model;
abstract public class Box {

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.model;
package com.alibaba.testable.demo.basic.model;
public interface Color {

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi;
public class ASvc {
public String demo(String name) {
return String.format("a_%s", name);
}
}

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi;
public class BSvc {
public String demo(String name) {
return String.format("b_%s", name);
}
}

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi;
public class CSvc {
public String demo(String name) {
return String.format("c_%s", name);
}
}

View File

@ -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;

View File

@ -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.*;

View File

@ -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;

View File

@ -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;

View File

@ -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.*;

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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);
}
}

View File

@ -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场景

View File

@ -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.*
/**

View File

@ -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

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo
package com.alibaba.testable.demo.basic
/**
* 演示私有成员访问功能

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo
package com.alibaba.testable.demo.basic
import java.util.ArrayList
import java.util.HashMap

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.model
package com.alibaba.testable.demo.basic.model
class BlackBox(var input: String) : Box(), Color {

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.model
package com.alibaba.testable.demo.basic.model
abstract class Box {

View File

@ -0,0 +1,7 @@
package com.alibaba.testable.demo.basic.model
interface Color {
val color: String
}

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.demo.util
package com.alibaba.testable.demo.java2kotlin
import java.io.File
import java.io.IOException

View File

@ -1,7 +0,0 @@
package com.alibaba.testable.demo.model
interface Color {
val color: String
}

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi
class ASvc {
fun demo(name: String): String {
return String.format("a_%s", name)
}
}

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi
class BSvc {
fun demo(name: String): String {
return String.format("b_%s", name)
}
}

View File

@ -0,0 +1,9 @@
package com.alibaba.testable.demo.one2multi
class CSvc {
fun demo(name: String): String {
return String.format("c_%s", name)
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"
}
}

View File

@ -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"
}
}

View File

@ -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"
}
}

View File

@ -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)
}
}