Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): Improve unit test coverage #676

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,5 @@ public synchronized CosIdState generateAsState() {
lastTimestamp = currentTimestamp;
return new CosIdState(lastTimestamp, machineId, sequence);
}

@Nonnull
@Override
public String generateAsString() {
CosIdState state = generateAsState();
return stateParser.asString(state);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class Radix62CosIdGeneratorTest {
private final Radix62CosIdGenerator radix62CosIdGenerator = new Radix62CosIdGenerator(1);

@Test
void generateAsString() {
String id1 = radix62CosIdGenerator.generateAsString();
Expand All @@ -37,21 +37,21 @@ void generateAsString() {
assertThat(id2.length(), equalTo(id1.length()));
assertThat(radix62CosIdGenerator.getLastTimestamp(), greaterThan(0L));
}

@Test
void generateAsState() {
CosIdState state1 = radix62CosIdGenerator.generateAsState();
CosIdState state2 = radix62CosIdGenerator.generateAsState();
assertThat(state2, greaterThan(state1));
}

@Test
void customizeOverflowMachineId() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Radix62CosIdGenerator(~(-1 << DEFAULT_MACHINE_BIT) + 1);
});
}

@Test
void generateSlow() {
Radix62CosIdGenerator cosIdGenerator = new Radix62CosIdGenerator(DEFAULT_TIMESTAMP_BIT, DEFAULT_MACHINE_BIT, DEFAULT_SEQUENCE_BIT, 1, 2);
Expand All @@ -62,14 +62,24 @@ void generateSlow() {
CosIdState state3 = cosIdGenerator.generateAsState();
assertThat(state3, greaterThan(state2));
assertThat(state2, greaterThan(state1));

assertThat(state1.getSequence(), equalTo(1));
assertThat(state2.getSequence(), equalTo(2));
assertThat(state1.getSequence(), equalTo(1));
}

@Test
public void generateWhenConcurrentString() {
new ConcurrentGenerateStingSpec(new Radix62CosIdGenerator(1)).verify();
}

@Test
public void idConvert() {
Assertions.assertThrows(UnsupportedOperationException.class, radix62CosIdGenerator::idConverter);
}

@Test
public void generate() {
Assertions.assertThrows(UnsupportedOperationException.class, radix62CosIdGenerator::generate);
}
}
Loading