summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/utils/SecureRandomTest.java
blob: c4098c2ff9d95ca17a0bfe63bf8cc0bfe1e296d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.gitblit.utils;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.junit.Test;

public class SecureRandomTest {

	@Test
	public void testRandomBytes() {
		SecureRandom sr = new SecureRandom();
		byte[] bytes1 = sr.randomBytes(10);
		assertEquals(10, bytes1.length);
		byte[] bytes2 = sr.randomBytes(10);
		assertEquals(10, bytes2.length);
		assertFalse(Arrays.equals(bytes1, bytes2));

		assertEquals(0, sr.randomBytes(0).length);
		assertEquals(200, sr.randomBytes(200).length);
	}

	@Test
	public void testNextBytes() {
		SecureRandom sr = new SecureRandom();
		byte[] bytes1 = new byte[32];
		sr.nextBytes(bytes1);
		byte[] bytes2 = new byte[32];
		sr.nextBytes(bytes2);
		assertFalse(Arrays.equals(bytes1, bytes2));
	}
}