Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Now fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlykotom committed Jan 4, 2018
1 parent ab160e9 commit 6bedc86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
30 changes: 25 additions & 5 deletions valifi/src/main/java/com/mlykotom/valifi/ValiFi.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mlykotom.valifi;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.support.annotation.StringRes;

import com.mlykotom.valifi.exceptions.ValiFiException;
Expand All @@ -18,6 +18,8 @@
import java.util.Set;
import java.util.regex.Pattern;

import static android.support.annotation.RestrictTo.Scope.TESTS;


@SuppressWarnings("unused")
public class ValiFi {
Expand All @@ -28,7 +30,7 @@ public class ValiFi {
private final Context mAppContext;


private ValiFi(Context appContext, ValiFiConfig config) {
private ValiFi(Context appContext, @NonNull ValiFiConfig config) {
mAppContext = appContext;
mParameters = config;
}
Expand All @@ -41,7 +43,7 @@ private ValiFi(Context appContext, ValiFiConfig config) {
* @param appContext for requesting resources, etc.
* @param config overriden parameters, built by {@link Builder}
*/
public static void install(Context appContext, ValiFiConfig config) {
public static void install(@NonNull Context appContext, @NonNull ValiFiConfig config) {
ourInstance = new ValiFi(appContext.getApplicationContext(), config);
}

Expand All @@ -52,8 +54,26 @@ public static void install(Context appContext, ValiFiConfig config) {
*
* @param appContext for requesting resources, etc.
*/
public static void install(Application appContext) {
install(appContext, new Builder().build());
public static void install(@NonNull Context appContext) {
install(appContext.getApplicationContext(), new Builder().build());
}


/**
* Installer for tests without context
*/
@RestrictTo(TESTS)
public static void install() {
ourInstance = new ValiFi(null, new Builder().build());
}


/**
* Installer for tests without context
*/
@RestrictTo(TESTS)
public static void install(@NonNull ValiFiConfig config) {
ourInstance = new ValiFi(null, config);
}


Expand Down
4 changes: 2 additions & 2 deletions valifi/src/test/java/com/mlykotom/valifi/ValiFiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ValiFiTest {
* WARNING: installing without context will crash when getting string, only for tests!
*/
public static void installWithoutContext() {
ValiFi.install(null);
ValiFi.install();
}


Expand Down Expand Up @@ -76,5 +76,5 @@ public void checkErrorResourcesMathStrings() {
assertThat(mField.getErrorRes(ValiFi.Builder.ERROR_RES_USERNAME), is(R.string.validation_error_username));
assertThat(mField.getErrorRes(ValiFi.Builder.ERROR_RES_PASSWORD), is(R.string.validation_error_password));
assertThat(mField.getErrorRes(ValiFi.Builder.ERROR_RES_YEARS_OLDER_THAN), is(R.string.validation_error_older_than_years));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void checkCardOnlyLuhnFailed() {

@Test
public void checkCustomCard() {
ValiFi.install(null, new ValiFi.Builder()
ValiFi.install(new ValiFi.Builder()
.setKnownCardTypes(new ValiFiCardType("Visa Custom", "^4[0-9]{6,}$")) //no default known types
.build());

Expand All @@ -38,7 +38,7 @@ public void checkCustomCard() {


private void prepareNoDefaultTypes() {
ValiFi.install(null, new ValiFi.Builder()
ValiFi.install(new ValiFi.Builder()
.setKnownCardTypes() //no default known types
.build());
}
Expand Down

0 comments on commit 6bedc86

Please sign in to comment.