-
Notifications
You must be signed in to change notification settings - Fork 213
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
30 changed files
with
1,333 additions
and
234 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apply plugin: 'jacoco' | ||
|
||
jacoco { | ||
toolVersion "0.7.6.201602180812" | ||
} | ||
// run ./gradlew clean createDebugCoverageReport jacocoTestReport | ||
|
||
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") { | ||
group = "Reporting" | ||
description = "Generate Jacoco coverage reports" | ||
|
||
reports { | ||
xml.enabled = true | ||
html.enabled = true | ||
} | ||
|
||
def fileFilter = ['**/R.class', | ||
'**/R$*.class', | ||
'**/BuildConfig.*', | ||
'**/Manifest*.*', | ||
'android/**/*.*', | ||
'**/Lambda$*.class', //Retrolambda | ||
'**/Lambda.class', | ||
'**/*Lambda.class', | ||
'**/*Lambda*.class', | ||
'**/*Lambda*.*', | ||
'**/*Builder.*', | ||
'**/*_MembersInjector.class', //Dagger2 generated code | ||
'**/*_MembersInjector*.*', //Dagger2 generated code | ||
'**/*_*Factory*.*', //Dagger2 generated code | ||
'**/*Component*.*', //Dagger2 generated code | ||
'**/*Module*.*' //Dagger2 generated code | ||
] | ||
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) | ||
def mainSrc = "${project.projectDir}/src/main/java" | ||
|
||
sourceDirectories = files([mainSrc]) | ||
classDirectories = files([debugTree]) | ||
executionData = fileTree(dir: project.projectDir, includes: | ||
['**/*.exec' , '**/*.ec']) | ||
} |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="me.ele.amigo"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.VIBRATE"/> | ||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | ||
|
||
</manifest> |
66 changes: 66 additions & 0 deletions
66
amigo-lib/src/androidTest/java/me/ele/amigo/AmigoClassLoaderTest.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,66 @@ | ||
package me.ele.amigo; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import me.ele.amigo.utils.FileUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class AmigoClassLoaderTest { | ||
|
||
@Test | ||
public void testAmigoClassLoader() throws Exception { | ||
AmigoIntegrationTest integrationTest = new AmigoIntegrationTest(); | ||
integrationTest.testRunPatchApplication(); | ||
|
||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
String workingChecksum = Amigo.getWorkingPatchApkChecksum(appContext); | ||
AmigoClassLoader classLoader = AmigoClassLoader.newInstance(appContext, workingChecksum); | ||
Assert.assertNotNull(classLoader.loadClass("me.ele.app.amigo.HomeActivity")); | ||
try { | ||
// load unknown class | ||
classLoader.loadClass("me.ele.app.amigo.HomeActivity1"); | ||
} catch (Exception e) { | ||
Assert.assertEquals(ClassNotFoundException.class, e.getClass()); | ||
} | ||
Assert.assertNotNull(classLoader.findResource("AndroidManifest.xml")); | ||
} | ||
|
||
@Test | ||
public void testJoinPath() throws IOException { | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
File tempDir = new File(appContext.getFilesDir(), "test_join_path"); | ||
FileUtils.removeFile(tempDir); | ||
tempDir.mkdir(); | ||
|
||
Assert.assertEquals(null, AmigoClassLoader.joinPath(tempDir)); | ||
|
||
File file1 = new File(tempDir, "a.txt"); | ||
file1.createNewFile(); | ||
Assert.assertEquals(true, | ||
Arrays.asList(AmigoClassLoader.joinPath(tempDir).split(File.pathSeparator)) | ||
.containsAll(Collections.singletonList(file1.getAbsolutePath()))); | ||
|
||
File file2 = new File(tempDir, "b.txt"); | ||
file2.createNewFile(); | ||
Assert.assertEquals(true, | ||
Arrays.asList(AmigoClassLoader.joinPath(tempDir).split(File.pathSeparator)) | ||
.containsAll( | ||
Arrays.asList(file1.getAbsolutePath(), file2.getAbsolutePath()))); | ||
|
||
File file3 = new File(tempDir, "c.txt"); | ||
file3.createNewFile(); | ||
Assert.assertEquals(true, | ||
Arrays.asList(AmigoClassLoader.joinPath(tempDir).split(File.pathSeparator)) | ||
.containsAll(Arrays.asList(file1.getAbsolutePath(), file2.getAbsolutePath(), | ||
file3.getAbsolutePath()))); | ||
} | ||
} |
Oops, something went wrong.