Add test case for GroupKey.java (#744)

pull/745/head
baymax55 2 years ago committed by GitHub
parent 43f3a07815
commit c0f0cbd14a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,7 +41,7 @@ public class GroupKey {
for (int i = 1; i < params.length - 1; i++) {
groupKey.append(params[i]).append(GROUP_KEY_DELIMITER);
}
groupKey.append(params[params.length]);
groupKey.append(params[params.length - 1]);
return groupKey.toString();
}

@ -17,5 +17,67 @@
package cn.hippo4j.common.toolkit;
public final class GroupKeyTest {
}
import org.checkerframework.checker.units.qual.A;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class GroupKeyTest {
@Test
public void getKey() {
String dataId = "dataId";
String group = "group";
String datumStr = "datumStr";
String expected = "dataId+group+datumStr";
String key = GroupKey.getKey(dataId, group, datumStr);
Assert.isTrue(key.equals(expected));
}
@Test
public void testGetKey() {
String dataId = "dataId";
String group = "group";
String expected = "dataId+group";
String key = GroupKey.getKey(dataId, group);
Assert.isTrue(key.equals(expected));
}
@Test
public void testGetKey1() {
String[] strings = {"dataId", "group", "datumStr"};
String expected = "dataId+group+datumStr";
String key = GroupKey.getKey(strings);
Assert.isTrue(key.equals(expected));
}
@Test
public void getKeyTenant() {
String dataId = "dataId";
String group = "group";
String datumStr = "datumStr";
String expected = "dataId+group+datumStr";
String keyTenant = GroupKey.getKeyTenant(dataId, group, datumStr);
Assert.isTrue(keyTenant.equals(expected));
}
@Test
public void parseKey() {
String groupKey = "prescription+dynamic-threadpool-example+message-consume+12";
String[] strings = GroupKey.parseKey(groupKey);
Assert.isTrue(strings.length == 4);
}
@Test
public void urlEncode() {
String str = "hello+World%";
String expected = "hello%2BWorld%25";
StringBuilder stringBuilder = new StringBuilder();
GroupKey.urlEncode(str, stringBuilder);
Assert.isTrue(stringBuilder.toString().contains(expected));
}
}
Loading…
Cancel
Save