-
Notifications
You must be signed in to change notification settings - Fork 2
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
19 changed files
with
115 additions
and
62 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
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
49 changes: 42 additions & 7 deletions
49
...ades/server/domain/launchdatabase/UsernameAndPasswordCredentialsGeneratorServiceTest.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 |
---|---|---|
@@ -1,29 +1,64 @@ | ||
package pl.gov.coi.cascades.server.domain.launchdatabase; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import pl.gov.coi.cascades.contract.domain.UsernameAndPasswordCredentials; | ||
import pl.gov.coi.cascades.server.domain.launchdatabase.UsernameAndPasswordCredentialsGeneratorService; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* @author <a href="agnieszka.celuch@coi.gov.pl">Agnieszka Celuch</a> | ||
* @since 07.03.17. | ||
*/ | ||
public class UsernameAndPasswordCredentialsGeneratorServiceTest { | ||
|
||
private static final int PASSWORD_LENGTH = 24; | ||
|
||
@Rule | ||
public MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
@Mock | ||
private Random randomGeneratorMock; | ||
|
||
@Test | ||
public void testGenerate() throws Exception { | ||
public void testGenerateRandomCredentials() { | ||
// given | ||
UsernameAndPasswordCredentialsGeneratorService credentials = new UsernameAndPasswordCredentialsGeneratorService(); | ||
UsernameAndPasswordCredentialsGeneratorService credentials = new UsernameAndPasswordCredentialsGeneratorService(new SecureRandom()); | ||
|
||
// when | ||
UsernameAndPasswordCredentials actual = credentials.generate(); | ||
UsernameAndPasswordCredentials firstGeneration = credentials.generate(); | ||
UsernameAndPasswordCredentials secondGeneration = credentials.generate(); | ||
|
||
// then | ||
checkGeneratedDataIsRandom(firstGeneration, secondGeneration); | ||
} | ||
|
||
@Test | ||
public void testUsePassedGenerator() { | ||
//given | ||
UsernameAndPasswordCredentialsGeneratorService credentials = new UsernameAndPasswordCredentialsGeneratorService(randomGeneratorMock); | ||
|
||
//when | ||
credentials.generate(); | ||
|
||
// then | ||
assertThat(actual).isNotNull(); | ||
assertThat(actual.getUsername()).hasSize(8); | ||
assertThat(actual.getPassword()).hasSize(24); | ||
verify(randomGeneratorMock, times(PASSWORD_LENGTH)).nextInt(any(Integer.class)); | ||
} | ||
|
||
private void checkGeneratedDataIsRandom(UsernameAndPasswordCredentials firstGeneration, UsernameAndPasswordCredentials secondGeneration) { | ||
assertThat(firstGeneration.getUsername()).isNotEqualTo(secondGeneration.getUsername()); | ||
assertThat(firstGeneration.getPassword()).isNotEqualTo(secondGeneration.getPassword()); | ||
} | ||
|
||
} |
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
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
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
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
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
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
Oops, something went wrong.