Compare commits

...

3 Commits

Author SHA1 Message Date
金戟
59bcbfdf37 release v0.7.2 2021-12-17 14:39:20 +08:00
Fan Lin
cdad0d2446 Merge pull request #251 from zcbbpo/Fxied-static-instance-reference-issue
fixed static instance reference issue
2021-12-17 13:40:45 +08:00
jimcao
ba5102ffd9 fixed static instance reference issue 2021-12-16 17:26:38 +08:00
20 changed files with 140 additions and 24 deletions

View File

@@ -49,7 +49,7 @@ dependencies {
testImplementation 'androidx.test:runner:1.4.0-alpha05'
testImplementation 'junit:junit:4.+'
testImplementation 'org.robolectric:robolectric:4.5.1'
testImplementation 'com.alibaba.testable:testable-all:0.7.1'
testImplementation 'com.alibaba.testable:testable-all:0.7.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

View File

@@ -13,8 +13,8 @@ repositories {
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
testImplementation('com.alibaba.testable:testable-all:0.7.1')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.1')
testImplementation('com.alibaba.testable:testable-all:0.7.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.2')
}
tasks.withType(JavaCompile) {

View File

@@ -12,7 +12,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.version>5.6.2</junit.version>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
<dependencies>

View File

@@ -0,0 +1,79 @@
package com.alibaba.demo.lambda;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author jim
*/
public class StaticInstanceReference {
private static A a = new A();
public void staticMethodReference() {
//consumesRun(() -> a.doIt());
//A b = new A();
//consumesRun(b::doIt);
consumesRun(a::doIt);
consumesFunction1(a::function1);
consumesFunction2(a::function2);
consumesFunction3(a::function3);
}
private void consumesRun(Runnable r) {
r.run();
}
private <T> void consumesFunction1(Consumer<T> r) {
r.accept(null);
}
private <T, R> void consumesFunction2(Function<T, R> r) {
r.apply(null);
}
private <T1, T2, R> void consumesFunction3(BiFunction<T1, T2, R> r) {
r.apply(null, null);
}
public static class A {
public void doIt() {
}
public void function1(String s) {
}
public Integer function2(String s) {
return 1;
}
public Integer function3(String s, Double d) {
return 1;
}
}
public static class XBean {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
public void foo() {
List<XBean> testList = Collections.emptyList();
//noinspection RedundantOperationOnEmptyContainer
List<Long> response = testList.stream().map(XBean::getId).distinct().collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,30 @@
package com.alibaba.demo.lambda;
import com.alibaba.testable.core.annotation.MockDiagnose;
import com.alibaba.testable.core.annotation.MockInvoke;
import com.alibaba.testable.core.model.LogLevel;
import org.junit.jupiter.api.Test;
import static com.alibaba.testable.core.matcher.InvocationVerifier.verifyInvoked;
/**
* @author jim
*/
public class StaticInstanceReferenceTest {
private StaticInstanceReference instance = new StaticInstanceReference();
//@MockDiagnose(LogLevel.VERBOSE)
public static class Mock {
@MockInvoke(targetClass = StaticInstanceReference.A.class, targetMethod = "doIt")
private void mockDoIt() {
}
}
@Test
public void shouldMockT1() {
instance.staticMethodReference();
verifyInvoked("mockDoIt").withTimes(1);
}
}

View File

@@ -17,8 +17,8 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.junit.jupiter:junit-jupiter:5.6.2")
testImplementation("com.alibaba.testable:testable-all:0.7.1")
testAnnotationProcessor("com.alibaba.testable:testable-processor:0.7.1")
testImplementation("com.alibaba.testable:testable-all:0.7.2")
testAnnotationProcessor("com.alibaba.testable:testable-processor:0.7.2")
}
tasks.withType<KotlinCompile> {

View File

@@ -14,7 +14,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.version>5.6.2</junit.version>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
<dependencies>

View File

@@ -14,8 +14,8 @@ repositories {
dependencies {
testImplementation 'org.codehaus.groovy:groovy-all:3.0.7'
testImplementation 'org.spockframework:spock-core:2.0-M5-groovy-3.0'
testImplementation('com.alibaba.testable:testable-all:0.7.1')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.1')
testImplementation('com.alibaba.testable:testable-all:0.7.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.2')
}
tasks.withType(JavaCompile) {

View File

@@ -12,7 +12,7 @@
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
<dependencyManagement>

View File

@@ -1,5 +1,8 @@
# Release Note
## 0.7.2
- fix an issue cause mock failed with static method reference
## 0.7.1
- fix an issue cause mock class unrecognized after package-mapping

View File

@@ -16,7 +16,7 @@ It is recommended to add a `property` field that identifies the TestableMock ver
```xml
<properties>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
```
@@ -63,8 +63,8 @@ Add dependence of `TestableMock` in `build.gradle` file:
```groovy
dependencies {
testImplementation('com.alibaba.testable:testable-all:0.7.1')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.1')
testImplementation('com.alibaba.testable:testable-all:0.7.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.2')
}
```

View File

@@ -1,5 +1,8 @@
# Release Note
## 0.7.2
- 修复静态方法引用导致Mock报错的问题issue-250
## 0.7.1
- 修复包路径映射时后识别不到Mock类的问题issue-248

View File

@@ -16,7 +16,7 @@
```xml
<properties>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
```
@@ -63,8 +63,8 @@
```groovy
dependencies {
testImplementation('com.alibaba.testable:testable-all:0.7.1')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.1')
testImplementation('com.alibaba.testable:testable-all:0.7.2')
testAnnotationProcessor('com.alibaba.testable:testable-processor:0.7.2')
}
```

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<relativePath>../testable-parent</relativePath>
</parent>
<artifactId>testable-agent</artifactId>

View File

@@ -433,7 +433,8 @@ public class SourceClassHandler extends BaseClassHandler {
mv.visitVarInsn(getLoadType(arg), isStatic ? i : i + 1);
}
mv.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, handle.getOwner(), handle.getName(), desc, false);
// the method call is static ?
mv.visitMethodInsn(Opcodes.H_INVOKESTATIC == tag ? INVOKESTATIC : INVOKEVIRTUAL, handle.getOwner(), handle.getName(), desc, false);
mv.visitInsn(getReturnType(returnType));

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<relativePath>../testable-parent</relativePath>
</parent>
<artifactId>testable-all</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<relativePath>../testable-parent</relativePath>
</parent>
<artifactId>testable-core</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<relativePath>../testable-parent</relativePath>
</parent>
<artifactId>testable-maven-plugin</artifactId>

View File

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<packaging>pom</packaging>
<name>testable-parent</name>
<description>Unit test enhancement toolkit</description>
@@ -42,7 +42,7 @@
<plugin.gpg.version>1.6</plugin.gpg.version>
<plugin.staging.version>1.6.8</plugin.staging.version>
<plugin.maven.version>3.6.0</plugin.maven.version>
<testable.version>0.7.1</testable.version>
<testable.version>0.7.2</testable.version>
</properties>
<profiles>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-parent</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<relativePath>../testable-parent</relativePath>
</parent>
<artifactId>testable-processor</artifactId>