Skip to content

Commit 2a7d2a4

Browse files
authored
Refactor tests for clarity and maintainability (#3363)
* test: remove redundant assertions and clarify time-related values with constants * test: remove redundant assertions and clarify time-related values with constants * test: remove redundant assertions and clarify time-related values with constants
1 parent 85b65f2 commit 2a7d2a4

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/test/java/io/lettuce/core/TimeoutOptionsUnitTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ void defaultConnectionTimeout() {
3838

3939
@Test
4040
void fixedConnectionTimeout() {
41+
final long MINUTES = 1;
42+
final long MINUTE_IN_NANOS = TimeUnit.MINUTES.toNanos(MINUTES);
4143

42-
TimeoutOptions timeoutOptions = TimeoutOptions.enabled(Duration.ofMinutes(1));
44+
TimeoutOptions timeoutOptions = TimeoutOptions.enabled(Duration.ofMinutes(MINUTES));
4345

4446
TimeoutSource source = timeoutOptions.getSource();
4547
assertThat(timeoutOptions.isTimeoutCommands()).isTrue();
4648
assertThat(timeoutOptions.isApplyConnectionTimeout()).isFalse();
47-
assertThat(source.getTimeout(null)).isEqualTo(TimeUnit.MINUTES.toNanos(1));
49+
assertThat(source.getTimeout(null)).isEqualTo(MINUTE_IN_NANOS);
4850
}
4951

5052
}

src/test/java/io/lettuce/core/sentinel/SentinelServerCommandIntegrationTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,18 @@ void after() {
8080
}
8181

8282
@Test
83-
public void clientGetSetname() {
83+
public void clientGetNameReturnsNullWhenNotSet() {
8484
assertThat(sentinel.clientGetname()).isNull();
85+
}
86+
87+
@Test
88+
public void clientSetNameWithNonEmptyStringSetsNameAndReturnsOk() {
8589
assertThat(sentinel.clientSetname("test")).isEqualTo("OK");
8690
assertThat(sentinel.clientGetname()).isEqualTo("test");
91+
}
92+
93+
@Test
94+
public void clientSetNameWithEmptyStringClearsNameAndReturnsOk() {
8795
assertThat(sentinel.clientSetname("")).isEqualTo("OK");
8896
assertThat(sentinel.clientGetname()).isNull();
8997
}

0 commit comments

Comments
 (0)