Skip to content

Commit 162d5fa

Browse files
Add UUID-based UserId generation
1 parent f5279bf commit 162d5fa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

testutil/src/main/java/org/spine3/test/Tests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package org.spine3.test;
2222

2323
import com.google.protobuf.Timestamp;
24+
import org.spine3.base.Identifiers;
2425
import org.spine3.protobuf.Timestamps;
2526
import org.spine3.users.UserId;
2627

@@ -114,6 +115,13 @@ public static UserId newUserId(String value) {
114115
.build();
115116
}
116117

118+
/**
119+
* Generates a new UUID-based {@code UserId}.
120+
*/
121+
public static UserId newUserUuid() {
122+
return newUserId(Identifiers.newUuid());
123+
}
124+
117125
/** The provider of current time, which is always the same. */
118126
public static class FrozenMadHatterParty implements Timestamps.Provider {
119127
private final Timestamp frozenTime;

testutil/src/test/java/org/spine3/test/TestsShould.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public void create_UserId_by_string() {
8484
assertEquals(expected, userId);
8585
}
8686

87+
@Test
88+
public void create_new_UUID_based_UserId() {
89+
assertFalse(Tests.newUserUuid().getValue().isEmpty());
90+
}
91+
8792
@Test(expected = NullPointerException.class)
8893
public void do_not_accept_null_UseId_value() {
8994
newUserId(Tests.<String>nullRef());

0 commit comments

Comments
 (0)