mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -14,8 +14,8 @@ public class IterChainTest {
|
||||
|
||||
@Test
|
||||
public void testAddChain() {
|
||||
Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
IterChain<Integer> iterChain = new IterChain<>();
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter1));
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter2));
|
||||
@@ -27,7 +27,7 @@ public class IterChainTest {
|
||||
|
||||
@Test
|
||||
public void testHasNext() {
|
||||
IterChain<Integer> iterChain = new IterChain<>();
|
||||
final IterChain<Integer> iterChain = new IterChain<>();
|
||||
Assert.assertFalse(iterChain.hasNext());
|
||||
Assert.assertFalse(iterChain.addChain(Collections.emptyIterator()).hasNext());
|
||||
Assert.assertTrue(iterChain.addChain(Arrays.asList(3, 4).iterator()).hasNext());
|
||||
@@ -35,9 +35,9 @@ public class IterChainTest {
|
||||
|
||||
@Test
|
||||
public void testNext() {
|
||||
Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
IterChain<Integer> iterChain = new IterChain<>();
|
||||
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
final IterChain<Integer> iterChain = new IterChain<>();
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter1));
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter2));
|
||||
Assert.assertEquals((Integer)1, iterChain.next());
|
||||
@@ -48,20 +48,20 @@ public class IterChainTest {
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
IterChain<Integer> iterChain = new IterChain<>();
|
||||
final IterChain<Integer> iterChain = new IterChain<>();
|
||||
iterChain.addChain(Arrays.asList(1, 2).iterator());
|
||||
Assert.assertThrows(IllegalStateException.class, iterChain::remove);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
IterChain<Integer> iterChain = new IterChain<>();
|
||||
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
|
||||
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
|
||||
final IterChain<Integer> iterChain = new IterChain<>();
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter1));
|
||||
Assert.assertSame(iterChain, iterChain.addChain(iter2));
|
||||
|
||||
Iterator<Iterator<Integer>> iterators = iterChain.iterator();
|
||||
final Iterator<Iterator<Integer>> iterators = iterChain.iterator();
|
||||
Assert.assertSame(iter1, iterators.next());
|
||||
Assert.assertSame(iter2, iterators.next());
|
||||
}
|
||||
|
@@ -446,6 +446,10 @@ public class FileUtilTest {
|
||||
Assert.assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", mimeType);
|
||||
mimeType = FileUtil.getMimeType("test.pptx");
|
||||
Assert.assertEquals("application/vnd.openxmlformats-officedocument.presentationml.presentation", mimeType);
|
||||
|
||||
// pr#2617@Github
|
||||
mimeType = FileUtil.getMimeType("test.wgt");
|
||||
Assert.assertEquals("application/widget", mimeType);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -4,20 +4,20 @@ import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MurMurHashTest {
|
||||
public class MurmurHashTest {
|
||||
|
||||
@Test
|
||||
public void hash32Test() {
|
||||
int hv = MurmurHash.hash32(StrUtil.utf8Bytes("你"));
|
||||
Assert.assertEquals(222142701, hv);
|
||||
Assert.assertEquals(-1898877446, hv);
|
||||
|
||||
hv = MurmurHash.hash32(StrUtil.utf8Bytes("你好"));
|
||||
Assert.assertEquals(1188098267, hv);
|
||||
Assert.assertEquals(337357348, hv);
|
||||
|
||||
hv = MurmurHash.hash32(StrUtil.utf8Bytes("见到你很高兴"));
|
||||
Assert.assertEquals(-1898490321, hv);
|
||||
Assert.assertEquals(1101306141, hv);
|
||||
hv = MurmurHash.hash32(StrUtil.utf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
|
||||
Assert.assertEquals(-1713131054, hv);
|
||||
Assert.assertEquals(-785444229, hv);
|
||||
}
|
||||
|
||||
@Test
|
@@ -1,8 +1,15 @@
|
||||
package cn.hutool.core.stream;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class StreamUtilTest {
|
||||
@@ -13,4 +20,36 @@ public class StreamUtilTest {
|
||||
final String result = stream.collect(CollectorUtil.joining(","));
|
||||
Assert.assertEquals("2,4,8,16", result);
|
||||
}
|
||||
|
||||
// === iterator ===
|
||||
@Test
|
||||
public void streamTestNullIterator() {
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> StreamUtil.ofIter((Iterator<Object>) null));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RedundantOperationOnEmptyContainer", "RedundantCollectionOperation"})
|
||||
@Test
|
||||
public void streamTestEmptyListToIterator() {
|
||||
assertStreamIsEmpty(StreamUtil.ofIter(new ArrayList<>().iterator()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamTestEmptyIterator() {
|
||||
assertStreamIsEmpty(StreamUtil.ofIter(Collections.emptyIterator()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamTestOrdinaryIterator() {
|
||||
final ArrayList<Integer> arrayList = ListUtil.of(1, 2, 3);
|
||||
Assert.assertArrayEquals(new Integer[]{1, 2, 3}, StreamUtil.ofIter(arrayList.iterator()).toArray());
|
||||
|
||||
final HashSet<Integer> hashSet = SetUtil.of(1, 2, 3);
|
||||
Assert.assertEquals(hashSet, StreamUtil.ofIter(hashSet.iterator()).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
void assertStreamIsEmpty(final Stream<?> stream) {
|
||||
Assert.assertNotNull(stream);
|
||||
Assert.assertEquals(0, stream.toArray().length);
|
||||
}
|
||||
// ================ stream test end ================
|
||||
}
|
||||
|
Reference in New Issue
Block a user