当我尝试测试 2 个 ArraysLists 时出现错误。似乎错误是在我的 removeEndWith_at 方法中说“toArray() 未定义”。你们能给我一个建议如何测试这两个 ArraysList 吗?
谢谢。
Java 版本:jdk-10.0.2
JUnit:5
[ArrayListIterator 类]
import java.util.Iterator;
import java.util.List;
public class ArrayListIterator {
/**
* @param wordsAl : list of words
*/
public List<String> removeEndWith_at(List<String> wordsAl) {
Iterator<String> iterator = wordsAl.iterator();
while (iterator.hasNext()) {
if (iterator.next().endsWith("at"))
iterator.remove();
}
return wordsAl;
}
}
[ArrayListIteratorTest 类]
import static org.junit.Assert.assertArrayEquals;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
class ArrayListIteratorTest {
ArrayListIterator alIterator = new ArrayListIterator();
List<String> actualWords = Arrays.asList("Apple", "Bat", "Orange", "Cat");
@Test
void testremoveEndWith_at() {
actualWords = alIterator.removeEndWith_at(actualWords);
List<String> expectedvalue = Arrays.asList("Apple", "Orange");
assertArrayEquals(expectedvalue.toArray(), actualWords.toArray());
}
}
拉丁的传说
梦里花落0921
相关分类