-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASV-149] Extracted verification method from CredentialsValidator val…
…idate() method; Created a test for the same class;
- Loading branch information
1 parent
1d2aef8
commit e0c801b
Showing
2 changed files
with
95 additions
and
15 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
75 changes: 75 additions & 0 deletions
75
...ide-account-manager/src/test/java/cm/aptoide/accountmanager/CredentialsValidatorTest.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,75 @@ | ||
package cm.aptoide.accountmanager; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.validateMockitoUsage; | ||
|
||
/** | ||
* Created by franciscocalado on 02/03/18. | ||
*/ | ||
|
||
public class CredentialsValidatorTest { | ||
|
||
private CredentialsValidator credentialsValidator; | ||
private AptoideCredentials validCredentials; | ||
private AptoideCredentials invalidPasswordCredentials; | ||
private AptoideCredentials emptyEmailCredentials; | ||
private AptoideCredentials emptyPasswordCredentials; | ||
private AptoideCredentials emptyCredentials; | ||
private int result; | ||
|
||
@Before public void setupCredentialsValidator() { | ||
MockitoAnnotations.initMocks(this); | ||
|
||
credentialsValidator = new CredentialsValidator(); | ||
result = -2; | ||
} | ||
|
||
@Test public void validateSuccessTest() { | ||
validCredentials = new AptoideCredentials("test@test.com", "mypasstest1"); | ||
|
||
result = credentialsValidator.validateFields(validCredentials, true); | ||
assertEquals(-1, result); | ||
} | ||
|
||
@Test public void validateEmptyCredentialsErrorTest() { | ||
emptyCredentials = new AptoideCredentials("", ""); | ||
|
||
result = credentialsValidator.validateFields(emptyCredentials, true); | ||
assertEquals(AccountValidationException.EMPTY_EMAIL_AND_PASSWORD, result); | ||
} | ||
|
||
@Test public void validateEmptyEmailCredentialsErrorTest() { | ||
emptyEmailCredentials = new AptoideCredentials("", "test1"); | ||
|
||
result = credentialsValidator.validateFields(emptyEmailCredentials, true); | ||
assertEquals(AccountValidationException.EMPTY_EMAIL, result); | ||
} | ||
|
||
@Test public void validateEmptyPasswordCredentialsErrorTest() { | ||
emptyPasswordCredentials = new AptoideCredentials("test@test.com", ""); | ||
|
||
result = credentialsValidator.validateFields(emptyPasswordCredentials, true); | ||
assertEquals(AccountValidationException.EMPTY_PASSWORD, result); | ||
} | ||
|
||
@Test public void validateInvalidPasswordErrorTest() { | ||
invalidPasswordCredentials = new AptoideCredentials("test", "error"); | ||
|
||
result = credentialsValidator.validateFields(invalidPasswordCredentials, true); | ||
assertEquals(AccountValidationException.INVALID_PASSWORD, result); | ||
} | ||
|
||
@After public void teardownCredentialsValidator() { | ||
credentialsValidator = null; | ||
result = -2; | ||
} | ||
|
||
@After public void validate() { | ||
validateMockitoUsage(); | ||
} | ||
} |