This commit is contained in:
Looly
2020-04-11 10:38:07 +08:00
parent 47be0f4f79
commit 73fd3b849f
21 changed files with 128 additions and 122 deletions

View File

@@ -1,5 +1,7 @@
package cn.hutool.core.clone;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.junit.Assert;
import org.junit.Test;
@@ -17,7 +19,10 @@ public class CloneTest {
Cat cat = new Cat();
Cat cat2 = cat.clone();
Assert.assertEquals(cat, cat2);
}
@Test
public void cloneTest2(){
//继承CloneSupport类
Dog dog = new Dog();
Dog dog2 = dog.clone();
@@ -30,7 +35,8 @@ public class CloneTest {
* @author Looly
*
*/
private static class Cat implements Cloneable<Cat>{
@Data
static class Cat implements Cloneable<Cat>{
private String name = "miaomiao";
private int age = 2;
@@ -42,35 +48,6 @@ public class CloneTest {
throw new CloneRuntimeException(e);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Cat other = (Cat) obj;
if (age != other.age) {
return false;
}
if (name == null) {
return other.name == null;
} else return name.equals(other.name);
}
}
/**
@@ -78,37 +55,10 @@ public class CloneTest {
* @author Looly
*
*/
private static class Dog extends CloneSupport<Dog>{
@EqualsAndHashCode(callSuper = false)
@Data
static class Dog extends CloneSupport<Dog>{
private String name = "wangwang";
private int age = 3;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Dog other = (Dog) obj;
if (age != other.age) {
return false;
}
if (name == null) {
return other.name == null;
} else return name.equals(other.name);
}
}
}

View File

@@ -179,6 +179,7 @@ public class CollUtilTest {
map.put("c", "3");
final String[] result = new String[1];
//noinspection deprecation
CollUtil.forEach(map, (key, value, index) -> {
if (key.equals("a")) {
result[0] = value;

View File

@@ -16,25 +16,25 @@ public class IterUtilTest {
@Test
public void fieldValueMapTest() {
ArrayList<Car> carList = CollUtil.newArrayList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList, "carNumber");
Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
Assert.assertEquals("奔驰", carNameMap.get("345").getCarName());
Assert.assertEquals("路虎", carNameMap.get("567").getCarName());
}
@Test
public void joinTest() {
ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
String join = IterUtil.join(list, ":");
String join = IterUtil.join(list.iterator(), ":");
Assert.assertEquals("1:2:3:4", join);
ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4);
String join1 = IterUtil.join(list1, ":");
String join1 = IterUtil.join(list1.iterator(), ":");
Assert.assertEquals("1:2:3:4", join1);
ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
String join2 = IterUtil.join(list2, ":", "\"", "\"");
String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
}

View File

@@ -3,16 +3,14 @@ package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.convert.NumberWordFormater;
public class NumberWordFormatTest {
@Test
public void formatTest() {
String format = NumberWordFormater.format(100.23);
String format = NumberWordFormatter.format(100.23);
Assert.assertEquals("ONE HUNDRED AND CENTS TWENTY THREE ONLY", format);
String format2 = NumberWordFormater.format("2100.00");
String format2 = NumberWordFormatter.format("2100.00");
Assert.assertEquals("TWO THOUSAND ONE HUNDRED AND CENTS ONLY", format2);
}
}