Skip to content

Commit 1a53bb1

Browse files
committed
More Quality from SonarQube and unit tests
1 parent 61cefeb commit 1a53bb1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/java/pl/wavesoftware/eid/exceptions/Eid.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public String getUniq() {
191191
return uniq;
192192
}
193193

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

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

229229
private final Random random;
230230

231-
public StdUniqIdGenerator() {
231+
private StdUniqIdGenerator() {
232232
this.random = getUnsecureFastRandom();
233233
}
234234

235235
@Override
236236
public String generateUniqId() {
237-
long first = abs(random.nextLong());
237+
long first = abs(random.nextLong() + 1);
238238
int second = abs(random.nextInt(Integer.MAX_VALUE));
239239
int calc = (int) (first + second);
240240
return Integer.toString(calc, BASE36);

src/test/java/pl/wavesoftware/eid/utils/EidPreconditionsTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ public void testCheckElementIndex() {
151151
EidPreconditions.checkElementIndex(index, size, eid);
152152
}
153153

154+
@Test
155+
public void testCheckElementIndex_SizeInvalid() {
156+
// given
157+
int index = 1;
158+
int size = -5;
159+
// then
160+
thrown.expect(EidIllegalArgumentException.class);
161+
thrown.expectMessage(containsString(eid));
162+
// when
163+
EidPreconditions.checkElementIndex(index, size, eid);
164+
}
165+
166+
@Test
167+
public void testCheckElementIndex_Eid_SizeInvalid() {
168+
// given
169+
int index = 2;
170+
int size = -1;
171+
// then
172+
thrown.expect(EidIllegalArgumentException.class);
173+
thrown.expectMessage(containsString(eid));
174+
// when
175+
EidPreconditions.checkElementIndex(index, size, new Eid(eid));
176+
}
177+
154178
@Test
155179
public void testCheckElementIndex_Positive() {
156180
// given

0 commit comments

Comments
 (0)