📄 sequentialiteratortest.java
字号:
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is Jamon code, released February, 2003. * * The Initial Developer of the Original Code is Ian Robertson. Portions * created by Ian Robertson are Copyright (C) 2003 Ian Robertson. All Rights * Reserved. * * Contributor(s): */package org.jamon.codegen;import junit.framework.TestCase;import java.util.Arrays;import java.util.Iterator;import java.util.NoSuchElementException;public class SequentialIteratorTest extends TestCase{ public void testNoIters() { assertIterEquals(constructIterator(new String[0]), new SequentialIterator<Object>(new Iterator<?>[0])); } public void testOneEmptyIter() { Iterator<String> i1 = constructIterator(new String[0]); assertIterEquals(i1, new SequentialIterator<Object>(new Iterator<?>[] {i1})); } public void testOneIter() { Iterator<String> i1 = constructIterator(new String[] {"one", "two"}); assertIterEquals(i1, new SequentialIterator<Object> (new Iterator<?>[] {constructIterator(new String[] {"one", "two"})})); } public void testTwoIters() { Iterator<String> i1 = constructIterator(new String[] {"one", "two"}); Iterator<String> i2 = constructIterator(new String[] {"three", "four"}); Iterator<String> combined = constructIterator (new String[] {"one", "two", "three", "four"}); assertIterEquals(combined, new SequentialIterator<String>(i1, i2)); } public void testTwoItersFirstEmpty() { Iterator<String> i1 = constructIterator(new String[0]); Iterator<String> i2 = constructIterator(new String[] {"three", "four"}); Iterator<String> combined = constructIterator(new String[] {"three", "four"}); assertIterEquals(combined, new SequentialIterator<String>(i1, i2)); } public void testTwoItersSecondEmpty() { Iterator<String> i1 = constructIterator(new String[] {"one", "two"}); Iterator<String> i2 = constructIterator(new String[0]); Iterator<String> combined = constructIterator(new String[] {"one", "two"}); assertIterEquals(combined, new SequentialIterator<String>(i1, i2)); } public void testThreeItersSecondEmpty() { Iterator<String> i1 = constructIterator(new String[] {"one", "two"}); Iterator<String> i2 = constructIterator(new String[0]); Iterator<String> i3 = constructIterator(new String[] {"three", "four"}); Iterator<String> combined = constructIterator (new String[] {"one", "two", "three", "four"}); assertIterEquals(combined, new SequentialIterator<String>(i1, i2, i3)); } private static Iterator<String> constructIterator(String[] p_objs) { return Arrays.asList(p_objs).iterator(); } private void assertIterEquals(Iterator<? extends Object> p_expected, Iterator<? extends Object> p_actual) { while(p_expected.hasNext()) { assertTrue(p_actual.hasNext()); assertEquals(p_expected.next(), p_actual.next()); } assertTrue(! p_actual.hasNext()); try { p_actual.next(); fail("next should have thrown an exception"); } catch(NoSuchElementException e) {} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -