Skip to content

Commit 0dae413

Browse files
committed
Polishing.
Simplify invocation chain, simplify tests. See #1248 Original pull request: #1249.
1 parent d46d6a4 commit 0dae413

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @author Mark Paluch
3535
* @author Lukasz Antoniak
3636
* @author Tomasz Lelek
37+
* @author Thomas Strauß
3738
* @see QueryOptions
3839
*/
3940
public class WriteOptions extends QueryOptions {
@@ -46,8 +47,7 @@ public class WriteOptions extends QueryOptions {
4647

4748
protected WriteOptions(@Nullable ConsistencyLevel consistencyLevel, ExecutionProfileResolver executionProfileResolver,
4849
@Nullable CqlIdentifier keyspace, @Nullable Integer pageSize, @Nullable ConsistencyLevel serialConsistencyLevel,
49-
Duration timeout, Duration ttl,
50-
@Nullable Long timestamp, @Nullable Boolean tracing) {
50+
Duration timeout, Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing) {
5151

5252
super(consistencyLevel, executionProfileResolver, keyspace, pageSize, serialConsistencyLevel, timeout, tracing);
5353

@@ -293,12 +293,7 @@ public WriteOptionsBuilder withTracing() {
293293
* @return {@code this} {@link WriteOptionsBuilder}
294294
*/
295295
public WriteOptionsBuilder ttl(int ttl) {
296-
297-
Assert.isTrue(ttl >= 0, "TTL must be greater than equal to zero");
298-
299-
this.ttl = Duration.ofSeconds(ttl);
300-
301-
return this;
296+
return ttl(Duration.ofSeconds(ttl));
302297
}
303298

304299
/**

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,14 @@ void buildWriteOptionsMutate() {
9494

9595
@Test // GH-1248
9696
void buildWriteOptionsWithTtlDurationZero() {
97-
try {
98-
WriteOptions writeOptions = WriteOptions.builder()
99-
.ttl(Duration.ZERO)
100-
.build();
101-
102-
fail("WiteOptionsBuilder must not allow zero TTL");
103-
}
104-
catch (Exception e) {
105-
// expected behavior
106-
}
97+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
98+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
10799
}
108100

109101
@Test // GH-1248
110102
void buildWriteOptionsWithTtlNegativeDuration() {
111-
try {
112-
WriteOptions writeOptions = WriteOptions.builder()
113-
.ttl(Duration.of(-1, ChronoUnit.MICROS))
114-
.build();
115-
116-
fail("WiteOptionsBuilder must not allow negative TTL");
117-
}
118-
catch (Exception e) {
119-
// expected behavior
120-
}
103+
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
104+
assertThatIllegalArgumentException()
105+
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
121106
}
122107
}

0 commit comments

Comments
 (0)