Skip to content

Commit

Permalink
Fix CopyArgs rendering for REPLACE #1777
Browse files Browse the repository at this point in the history
Lettuce now correctly checks if the replace flag was set using a boolean check instead of non-null.
  • Loading branch information
mp911de committed Jun 21, 2021
1 parent 63728f8 commit 9774c2c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/CopyArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CopyArgs implements CompositeArgument {

private Long destinationDb;

private Boolean replace;
private boolean replace;

/**
* Builder entry points for {@link CopyArgs}.
Expand Down Expand Up @@ -95,7 +95,7 @@ public <K, V> void build(CommandArgs<K, V> args) {
args.add(CommandKeyword.DB).add(destinationDb);
}

if(replace != null) {
if (replace) {
args.add(CommandKeyword.REPLACE);
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/io/lettuce/core/CopyArgsUnitTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.lettuce.core;

import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.protocol.CommandArgs;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;

/**
* Unit tests for {@link CopyArgs}.
*
* @author Mark Paluch
*/
class CopyArgsUnitTests {

@Test
void shouldRenderFullArgs() {

CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8);

CopyArgs.Builder.destinationDb(1).replace(true).build(args);

assertThat(args.toCommandString()).isEqualTo("DB 1 REPLACE");
}

@Test
void shouldRenderNoArgs() {

CommandArgs<String, String> args = new CommandArgs<>(StringCodec.UTF8);

CopyArgs.Builder.replace(false).build(args);

assertThat(args.toCommandString()).isEmpty();
}

}

0 comments on commit 9774c2c

Please sign in to comment.