Skip to content
Merged
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':ui', ':common', ':receipt', ':userrepository'
include ':ui', ':common', ':receipt', ':userrepository', ':transfermethodrepository'
//add libraries here
1 change: 1 addition & 0 deletions transfermethodrepository/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
8 changes: 8 additions & 0 deletions transfermethodrepository/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apply from: "$rootProject.projectDir/android-library.gradle"
apply from: "$rootProject.projectDir/publish.gradle"

dependencies {
androidTestImplementation "androidx.test:rules:$testRulesVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
}
78 changes: 78 additions & 0 deletions transfermethodrepository/config/jacoco-settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apply plugin: 'jacoco'

final def jacocoVersion = "0.8.2"

jacoco {
toolVersion = jacocoVersion
}

android {
testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}

def fileFilter = ['**/BuildConfig.*']

def debugClassPaths = [
'**/intermediates/javac/debug/*/classes/**'
]

final def coverageSourceDirs = ["$project.projectDir/src/main/java/*"]

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

group = 'Reporting'
description = 'Generate Jacoco coverage reports.'
reports {
html {
enabled = true
destination file("$project.buildDir/reports/jacoco")
}
}

classDirectories = fileTree(
dir: "${buildDir}",
includes: debugClassPaths,
excludes: fileFilter
)

additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files("${project.buildDir}/jacoco/testDebugUnitTest.exec")
}

task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: 'jacocoTestReport') {

group = 'Verification'
classDirectories = fileTree(
dir: "${buildDir}",
includes: debugClassPaths,
excludes: fileFilter
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files("${project.buildDir}/jacoco/testDebugUnitTest.exec")

violationRules {
setFailOnViolation(true)

rule {
element = 'CLASS'
limit {
value = 'COVEREDRATIO'
counter = 'BRANCH'
minimum = 0.65
}
}
}
}

6 changes: 6 additions & 0 deletions transfermethodrepository/config/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="RtlEnabled">
<ignore regexp="(AndroidManifest).xml"/>
</issue>
</lint>
21 changes: 21 additions & 0 deletions transfermethodrepository/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions transfermethodrepository/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest
package="com.hyperwallet.android.ui.transfermethod.repository"/>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import android.os.Handler;

Expand All @@ -39,7 +39,7 @@
import com.hyperwallet.android.model.graphql.HyperwalletTransferMethodConfigurationKey;
import com.hyperwallet.android.model.graphql.query.HyperwalletTransferMethodConfigurationFieldQuery;
import com.hyperwallet.android.model.graphql.query.HyperwalletTransferMethodConfigurationKeysQuery;
import com.hyperwallet.android.ui.common.util.EspressoIdlingResource;
import com.hyperwallet.android.ui.transfermethod.repository.util.EspressoIdlingResource;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -50,7 +50,8 @@ public class TransferMethodConfigurationRepositoryImpl implements TransferMethod
private final Map<FieldMapKey, HyperwalletTransferMethodConfigurationField> mFieldMap;
private HyperwalletTransferMethodConfigurationKey mTransferMethodConfigurationKey;

TransferMethodConfigurationRepositoryImpl() {
//todo use default modifier after RepositoryFactory is removed
public TransferMethodConfigurationRepositoryImpl() {
mHandler = new Handler();
mFieldMap = new HashMap<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import androidx.annotation.NonNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.hyperwallet.android.ui.transfermethod.repository;

public class TransferMethodRepositoryFactory {
private static TransferMethodRepositoryFactory sInstance;
private TransferMethodRepository mTransferMethodRepository;
private TransferMethodConfigurationRepository mTransferMethodConfigurationRepository;

private TransferMethodRepositoryFactory() {
mTransferMethodRepository = new TransferMethodRepositoryImpl();
mTransferMethodConfigurationRepository = new TransferMethodConfigurationRepositoryImpl();
}

public static synchronized TransferMethodRepositoryFactory getInstance() {
if (sInstance == null) {
sInstance = new TransferMethodRepositoryFactory();
}
return sInstance;
}

public static void clearInstance() {
sInstance = null;
}

public TransferMethodRepository getTransferMethodRepository() {
return mTransferMethodRepository;
}

public TransferMethodConfigurationRepository getTransferMethodConfigurationRepository() {
return mTransferMethodConfigurationRepository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TOKEN;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hyperwallet.android.ui.transfermethod.repository.util;

import androidx.test.espresso.IdlingResource;
import androidx.test.espresso.idling.CountingIdlingResource;

public class EspressoIdlingResource {

private static final String RESOURCE = "GLOBAL";

private static CountingIdlingResource mCountingIdlingResource =
new CountingIdlingResource(RESOURCE);

public static void increment() {
mCountingIdlingResource.increment();
}

public static void decrement() {
mCountingIdlingResource.decrement();
}

public static IdlingResource getIdlingResource() {
return mCountingIdlingResource;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import com.hyperwallet.android.ui.transfermethod.repository.FieldMapKey;

import org.junit.Test;

public class FieldMapKeyTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
Expand Down Expand Up @@ -32,7 +32,7 @@
import com.hyperwallet.android.model.graphql.keyed.HyperwalletTransferMethodConfigurationKeyResult;
import com.hyperwallet.android.model.graphql.query.HyperwalletTransferMethodConfigurationFieldQuery;
import com.hyperwallet.android.model.graphql.query.HyperwalletTransferMethodConfigurationKeysQuery;
import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager;
import com.hyperwallet.android.ui.transfermethod.repository.rule.HyperwalletExternalResourceManager;
import com.hyperwallet.android.util.JsonUtils;

import org.hamcrest.collection.IsEmptyCollection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.hyperwallet.android.ui.transfermethod.repository;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

public class TransferMethodRepositoryFactoryTest {
@Test
public void testGetInstance_verifyRepositoriesInitialized() {
TransferMethodRepositoryFactory repositoryFactory = TransferMethodRepositoryFactory.getInstance();
assertThat(repositoryFactory, is(notNullValue()));
assertThat(repositoryFactory.getTransferMethodRepository(), is(notNullValue()));
assertThat(repositoryFactory.getTransferMethodConfigurationRepository(), is(notNullValue()));
}

@Test
public void testClearInstance_verifyRepositoryCleared() {
TransferMethodRepositoryFactory repositoryFactory = TransferMethodRepositoryFactory.getInstance();

TransferMethodRepository transferMethodRepository = repositoryFactory.getTransferMethodRepository();
TransferMethodConfigurationRepository configurationRepository =
repositoryFactory.getTransferMethodConfigurationRepository();
TransferMethodRepositoryFactory currentRepositoryFactory = TransferMethodRepositoryFactory.getInstance();
assertThat(repositoryFactory, is(currentRepositoryFactory));
assertThat(transferMethodRepository, is(currentRepositoryFactory.getTransferMethodRepository()));
assertThat(configurationRepository, is(currentRepositoryFactory.getTransferMethodConfigurationRepository()));

TransferMethodRepositoryFactory.clearInstance();

TransferMethodRepositoryFactory anotherRepositoryFactory = TransferMethodRepositoryFactory.getInstance();
assertThat(repositoryFactory, is(not(anotherRepositoryFactory)));
assertThat(transferMethodRepository, is(not(anotherRepositoryFactory.getTransferMethodRepository())));
assertThat(configurationRepository,
is(not(anotherRepositoryFactory.getTransferMethodConfigurationRepository())));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hyperwallet.android.ui.repository;
package com.hyperwallet.android.ui.transfermethod.repository;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.hyperwallet.android.ui.transfermethod.repository.rule;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

public class HyperwalletExternalResourceManager extends TestWatcher {

private static final String EMPTY = "";
private ClassLoader classLoader;
private Logger logger;

@Override
protected void starting(Description description) {
super.starting(description);
classLoader = description.getTestClass().getClassLoader();
logger = Logger.getLogger(description.getTestClass().getName());
}


public String getResourceContent(final String resourceName) {
if (resourceName == null) {
throw new IllegalArgumentException("Parameter resourceName cannot be null");
}

return getContent(resourceName);
}

private String getContent(final String resourceName) {

URL resource = classLoader.getResource(resourceName);
InputStream inputStream = null;
Writer writer = new StringWriter();
String resourceContent = EMPTY;
if (resource != null) {
try {
inputStream = resource.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line = reader.readLine();
while (line != null) {
writer.write(line);
line = reader.readLine();
}
resourceContent = writer.toString();

} catch (Exception e) {
logger.log(Level.WARNING, "There was an error loading an external resource", e);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
logger.log(Level.SEVERE, "There was an error closing input stream", e);
}
try {
writer.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "There was an error closing writer", e);
}
}
}
return resourceContent;
}
}
Loading