Skip to content

Commit fd22b62

Browse files
committed
Polishing.
Simplify invocation chain, simplify tests. See #1248 Original pull request: #1249.
1 parent 27618cd commit fd22b62

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/WriteOptions.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @author Lukasz Antoniak
3737
* @author Tomasz Lelek
3838
* @author Sam Lightfoot
39+
* @author Thomas Strauß
3940
* @see QueryOptions
4041
*/
4142
public class WriteOptions extends QueryOptions {
@@ -327,12 +328,7 @@ public WriteOptionsBuilder withTracing() {
327328
* @return {@code this} {@link WriteOptionsBuilder}
328329
*/
329330
public WriteOptionsBuilder ttl(int ttl) {
330-
331-
Assert.isTrue(ttl >= 0, "TTL must be greater than equal to zero");
332-
333-
this.ttl = Duration.ofSeconds(ttl);
334-
335-
return this;
331+
return ttl(Duration.ofSeconds(ttl));
336332
}
337333

338334
/**

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/WriteOptionsUnitTests.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ void buildWriteOptions() {
6262
assertThat(writeOptions.getTracing()).isTrue();
6363
assertThat(writeOptions.getKeyspace()).isEqualTo(CqlIdentifier.fromCql("my_keyspace"));
6464
assertThat(writeOptions.isIdempotent()).isEqualTo(true);
65-
assertThat(writeOptions.getRoutingKeyspace()).isEqualTo(
66-
CqlIdentifier.fromCql("routing_keyspace"));
65+
assertThat(writeOptions.getRoutingKeyspace()).isEqualTo(CqlIdentifier.fromCql("routing_keyspace"));
6766
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
6867
}
6968

@@ -104,36 +103,20 @@ void buildWriteOptionsMutate() {
104103
assertThat(mutated.getPageSize()).isEqualTo(10);
105104
assertThat(mutated.getTracing()).isTrue();
106105
assertThat(writeOptions.isIdempotent()).isEqualTo(true);
107-
assertThat(writeOptions.getRoutingKeyspace()).isEqualTo(
108-
CqlIdentifier.fromCql("routing_keyspace"));
106+
assertThat(writeOptions.getRoutingKeyspace()).isEqualTo(CqlIdentifier.fromCql("routing_keyspace"));
109107
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
110108
}
111109

112110
@Test // GH-1248
113111
void buildWriteOptionsWithTtlDurationZero() {
114-
try {
115-
WriteOptions writeOptions = WriteOptions.builder()
116-
.ttl(Duration.ZERO)
117-
.build();
118-
119-
fail("WiteOptionsBuilder must not allow zero TTL");
120-
}
121-
catch (Exception e) {
122-
// expected behavior
123-
}
112+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
113+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
124114
}
125115

126116
@Test // GH-1248
127117
void buildWriteOptionsWithTtlNegativeDuration() {
128-
try {
129-
WriteOptions writeOptions = WriteOptions.builder()
130-
.ttl(Duration.of(-1, ChronoUnit.MICROS))
131-
.build();
132-
133-
fail("WiteOptionsBuilder must not allow negative TTL");
134-
}
135-
catch (Exception e) {
136-
// expected behavior
137-
}
118+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
119+
assertThatIllegalArgumentException()
120+
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
138121
}
139122
}

0 commit comments

Comments
 (0)