Skip to content
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 @@ -96,7 +96,7 @@ public static List<RaftPeer> parseRaftPeers(String peers) {

/** Parse the given string as a {@link RaftGroupId}. */
public static RaftGroupId parseRaftGroupId(String groupId) {
return groupId != null && groupId.isEmpty() ? RaftGroupId.valueOf(UUID.fromString(groupId)) : null;
return groupId != null && !groupId.isEmpty() ? RaftGroupId.valueOf(UUID.fromString(groupId)) : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.ratis.shell.cli;

import org.apache.ratis.protocol.RaftGroupId;
import org.apache.ratis.protocol.RaftPeer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -25,6 +26,7 @@
import java.net.Inet6Address;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.UUID;

public class TestCliUtils {

Expand Down Expand Up @@ -61,4 +63,27 @@ public void testParseRejectsScheme() {
Assertions.assertThrows(IllegalArgumentException.class,
() -> CliUtils.parseInetSocketAddress("http://127.0.0.1:6000"));
}

@Test
public void testParseRaftGroupIdNull() {
Assertions.assertNull(CliUtils.parseRaftGroupId(null));
}

@Test
public void testParseRaftGroupIdEmpty() {
Assertions.assertNull(CliUtils.parseRaftGroupId(""));
}

@Test
public void testParseRaftGroupIdValid() {
final UUID uuid = UUID.randomUUID();
final RaftGroupId groupId = CliUtils.parseRaftGroupId(uuid.toString());
Assertions.assertEquals(RaftGroupId.valueOf(uuid), groupId);
}

@Test
public void testParseRaftGroupIdInvalid() {
Assertions.assertThrows(IllegalArgumentException.class,
() -> CliUtils.parseRaftGroupId("not-a-uuid"));
}
}
Loading