Skip to content

Commit

Permalink
Jacoco and Test updates (PaystackHQ#131)
Browse files Browse the repository at this point in the history
* Jacoco and Test updates

 - Added Jacoco agents properties file to init jacoco when running the example project
 - Moved the Unit Tests that were in the example project to the SDK module
 - Added the Jacoco build script to the SDK module
 - Removed a filter that does not exist
 - Updated Jacoco exludes
  • Loading branch information
Peter-John-paystack authored Jun 4, 2021
1 parent 28f162f commit 95de07e
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 3 deletions.
6 changes: 3 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea
html.enabled = true
}

def fileFilter = ['**/R.class', '**/R$*.class','jdk.internal.*', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter)
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
executionData.setFrom(fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'
'**/*.exec', '**/*.ec'
]))
}

Expand Down
1 change: 1 addition & 0 deletions example/src/main/resources/jacoco-agent.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output=none
45 changes: 45 additions & 0 deletions paystack/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'jacoco'

jacoco {
toolVersion = "$jacocoVersion"
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
executionData.setFrom(fileTree(dir: project.buildDir, includes: [
'**/*.exec', '**/*.ec'
]))
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
Expand All @@ -13,11 +41,23 @@ android {
versionName rootProject.ext.versionName
consumerProguardFiles 'proguard-rules.pro'
}
buildTypes {
debug {
testCoverageEnabled true
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

dependencies {
Expand All @@ -31,6 +71,11 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlin"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutines"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutines"

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.12.2'
testImplementation 'org.robolectric:robolectric:4.5.1'
testImplementation 'org.mockito:mockito-core:3.8.0'
}

apply from: "https://raw.githubusercontent.com/PaystackHQ/publish-mavencentral/main/maven-publish.gradle"
75 changes: 75 additions & 0 deletions paystack/src/test/java/co/paystack/android/CardTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package co.paystack.android;

import org.junit.Test;

import java.util.Calendar;

import co.paystack.android.model.Card;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

/**
* Test the card class
*/

public class CardTest {

private static final int YEAR = Calendar.getInstance().get(Calendar.YEAR);
private static final int MONTH = Calendar.getInstance().get(Calendar.MONTH);

private static final int YEAR_FUTURE = Calendar.getInstance().get(Calendar.YEAR) + 1;
private static final int YEAR_PAST = Calendar.getInstance().get(Calendar.YEAR) - 2;
private static final int MONTH_PAST = (MONTH > Calendar.getInstance().getMinimum(Calendar.MONTH)) ? MONTH - 1 : Calendar.getInstance().getMaximum(Calendar.MONTH);


private static final String CVC_3 = "123";
private static final String CVC_4 = "1234";

private static final String MASTER_CARD_NUMBER = "5105105105105100";

private static final String DISCOVER_CARD_NUMBER = "6500000000000002";

private static final String VISA_CARD_NUMBER = "4111111111111111";
private static final String VISA_CARD_NUMBER_2 = "4342-5611-1111-1118";

private static final String AMEX_CARD_NUMBER = "341111111111111";

@Test
public void testExpiredCardMonth() throws Exception {
Card card = new Card.Builder(MASTER_CARD_NUMBER, YEAR, MONTH_PAST, "123").build();
assertSame(false, card.validExpiryDate());
}

@Test
public void testExpiredCardYear() throws Exception {
Card card = new Card.Builder(MASTER_CARD_NUMBER, YEAR_PAST, Calendar.DECEMBER + 1, "123").build();
assertSame(false, card.validExpiryDate());
}

@Test
public void canInitializeCardWithBuilder() throws Exception {
Card card = new Card.Builder(MASTER_CARD_NUMBER, 3, YEAR_FUTURE, "123").build();
assertTrue(card.isValid());
}

@Test
public void testTypeDetectionMasterCard() throws Exception {
Card card = new Card(MASTER_CARD_NUMBER, YEAR, MONTH, CVC_3);
assertSame(Card.CardType.MASTERCARD, card.getType());
}

@Test
public void testTypeDetectionAmericanExpress() throws Exception {
Card card = new Card(AMEX_CARD_NUMBER, YEAR, MONTH, CVC_4);
assertSame(Card.CardType.AMERICAN_EXPRESS, card.getType());
}

@Test
public void testTypeDetectionVisaCard() throws Exception {
Card card = new Card(VISA_CARD_NUMBER, YEAR, MONTH, CVC_3);
assertSame(Card.CardType.VISA, card.getType());
}

//TODO: testTypeDetectionDiscoverCard This test was failing and we need to have look at it.
}
23 changes: 23 additions & 0 deletions paystack/src/test/java/co/paystack/android/PaystackSdkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package co.paystack.android;

import org.junit.Test;

/**
* PaystackSdk Test Class
* <p/>
* Tests the paystack sdk
*/

public class PaystackSdkTest {

private static final String TEST_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANIsL+RHqfkBiKGn/D1y1QnNrMkKzxWP\n" +
"2wkeSokw2OJrCI+d6YGJPrHHx+nmb/Qn885/R01Gw6d7M824qofmCvkCAwEAAQ==";

@Test(expected = NullPointerException.class)
public void initPaystackSdkWithNullParamsShouldThrowException() {
PaystackSdk.initialize(null);
}

//TODO: Look at this SDK Unit Test initPaystackSdkWithPaystackActivityShouldPass

}

0 comments on commit 95de07e

Please sign in to comment.