-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added tests for VerboseIterable and VerboseIterator #125
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.takes.misc; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Test case for {@link VerboseIterable} | ||
* @author Zarko Celebic | ||
*/ | ||
public class VerboseIterableTest { | ||
|
||
@Rule | ||
public ExpectedException expectedEx = ExpectedException.none(); | ||
|
||
@Test | ||
public void testIterator() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @celezar see http://www.yegor256.com/2014/04/27/typical-mistakes-in-java-code.html#test-method-names for test name and test description. |
||
List<String> testList = Arrays.asList("1", "2", "3", "4", "5"); | ||
VerboseIterable<String> vIterable = new VerboseIterable<String>(testList, "Error Message"); | ||
Iterator<String> iter = vIterable.iterator(); | ||
|
||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(true)); | ||
MatcherAssert.assertThat(iter.next(), Matchers.equalTo("1")); | ||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(true)); | ||
MatcherAssert.assertThat(iter.next(), Matchers.equalTo("2")); | ||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(true)); | ||
MatcherAssert.assertThat(iter.next(), Matchers.equalTo("3")); | ||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(true)); | ||
MatcherAssert.assertThat(iter.next(), Matchers.equalTo("4")); | ||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(true)); | ||
MatcherAssert.assertThat(iter.next(), Matchers.equalTo("5")); | ||
MatcherAssert.assertThat(iter.hasNext(), Matchers.equalTo(false)); | ||
|
||
expectedEx.expect(NoSuchElementException.class); | ||
expectedEx.expectMessage("Error Message"); | ||
iter.next(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.takes.misc; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Test case for {@link VerboseIterator} | ||
* @author Zarko Celebic | ||
*/ | ||
public final class VerboseIteratorTest{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @celezar let's avoid coupling tests together, maybe it's better to inline? |
||
@Rule | ||
public ExpectedException expectedEx = ExpectedException.none(); | ||
|
||
@Test | ||
public void testHasNext() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @celezar see http://www.yegor256.com/2014/04/27/typical-mistakes-in-java-code.html#test-method-names for test name and test description. |
||
List<String> testList = Arrays.asList("1", "2", "3", "4", "5"); | ||
VerboseIterator<String> vi = new VerboseIterator<String>(testList.iterator(), "Error message"); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(true)); | ||
vi.next(); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(true)); | ||
vi.next(); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(true)); | ||
vi.next(); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(true)); | ||
vi.next(); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(true)); | ||
vi.next(); | ||
MatcherAssert.assertThat(vi.hasNext(), Matchers.equalTo(false)); | ||
|
||
} | ||
|
||
@Test | ||
public void testNext() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @celezar see http://www.yegor256.com/2014/04/27/typical-mistakes-in-java-code.html#test-method-names for test name and test description. |
||
List<String> testList = Arrays.asList("1", "2", "3", "4", "5"); | ||
VerboseIterator<String> vi = new VerboseIterator<String>(testList.iterator(), "Error message"); | ||
MatcherAssert.assertThat(vi.next(), Matchers.equalTo("1")); | ||
MatcherAssert.assertThat(vi.next(), Matchers.equalTo("2")); | ||
MatcherAssert.assertThat(vi.next(), Matchers.equalTo("3")); | ||
MatcherAssert.assertThat(vi.next(), Matchers.equalTo("4")); | ||
MatcherAssert.assertThat(vi.next(), Matchers.equalTo("5")); | ||
expectedEx.expect(NoSuchElementException.class); | ||
expectedEx.expectMessage("Error message"); | ||
vi.next(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@celezar let's avoid extracting fields when used only once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are used at least two times. i extracted them because qulice was complaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@celezar you can try to use different string, let's not couple tests together