-
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.
Merge pull request #143 from gneokleo/master
Adding tests for RandomStringUtils
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
compute/src/main/java/com/chatalytics/compute/chat/dao/local/LocalChatDao.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
2 changes: 1 addition & 1 deletion
2
...m/chatalytics/core/RandomStringUtils.java → ...talytics/core/util/RandomStringUtils.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,4 +1,4 @@ | ||
package com.chatalytics.core; | ||
package com.chatalytics.core.util; | ||
|
||
import java.util.Random; | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
core/src/test/java/com/chatalytics/core/util/RandomStringUtilsTest.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,44 @@ | ||
package com.chatalytics.core.util; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Random; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Matchers.anyInt; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Tests {@link RandomStringUtils} | ||
* | ||
* @author giannis | ||
* | ||
*/ | ||
public class RandomStringUtilsTest { | ||
|
||
@Test | ||
public void testGenerateRandomAlphaNumericString() { | ||
int length = 10; | ||
String result = RandomStringUtils.generateRandomAlphaNumericString(length); | ||
assertEquals(length, result.length()); | ||
|
||
length = 0; | ||
result = RandomStringUtils.generateRandomAlphaNumericString(length); | ||
assertEquals(length, result.length()); | ||
} | ||
|
||
@Test | ||
public void testGenerateRandomAlphaNumericString_withProvidedRandom() { | ||
int length = 10; | ||
StringBuilder strBuilder = new StringBuilder(); | ||
for (int i = 0; i < length; i++) { | ||
strBuilder.append("a"); | ||
} | ||
Random rand = mock(Random.class); | ||
when(rand.nextInt(anyInt())).thenReturn(0); | ||
String result = RandomStringUtils.generateRandomAlphaNumericString(length, rand); | ||
assertEquals(length, result.length()); | ||
assertEquals(strBuilder.toString(), result); | ||
} | ||
} |