Skip to content

Commit

Permalink
More Quality from SonarQube and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jul 19, 2015
1 parent 61cefeb commit 1a53bb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/pl/wavesoftware/eid/exceptions/Eid.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public String getUniq() {
return uniq;
}

static void validateFormat(String format, int numSpecifiers) throws IllegalArgumentException {
static void validateFormat(String format, int numSpecifiers) {
if (format == null) {
throw new IllegalArgumentException("Format can't be null, but just recieved one");
}
Expand All @@ -212,7 +212,7 @@ static void validateFormat(String format, int numSpecifiers) throws IllegalArgum
* It is used to generate unique ID for each EID object. It's mustn't be secure becouse it just indicate EID object while
* logging.
*/
public static interface UniqIdGenerator {
public interface UniqIdGenerator {

/**
* Generates a uniq string ID
Expand All @@ -228,13 +228,13 @@ private static class StdUniqIdGenerator implements UniqIdGenerator {

private final Random random;

public StdUniqIdGenerator() {
private StdUniqIdGenerator() {
this.random = getUnsecureFastRandom();
}

@Override
public String generateUniqId() {
long first = abs(random.nextLong());
long first = abs(random.nextLong() + 1);
int second = abs(random.nextInt(Integer.MAX_VALUE));
int calc = (int) (first + second);
return Integer.toString(calc, BASE36);
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ public void testCheckElementIndex() {
EidPreconditions.checkElementIndex(index, size, eid);
}

@Test
public void testCheckElementIndex_SizeInvalid() {
// given
int index = 1;
int size = -5;
// then
thrown.expect(EidIllegalArgumentException.class);
thrown.expectMessage(containsString(eid));
// when
EidPreconditions.checkElementIndex(index, size, eid);
}

@Test
public void testCheckElementIndex_Eid_SizeInvalid() {
// given
int index = 2;
int size = -1;
// then
thrown.expect(EidIllegalArgumentException.class);
thrown.expectMessage(containsString(eid));
// when
EidPreconditions.checkElementIndex(index, size, new Eid(eid));
}

@Test
public void testCheckElementIndex_Positive() {
// given
Expand Down

0 comments on commit 1a53bb1

Please sign in to comment.