Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/test/java/org/takes/misc/VerboseIterableTest.java
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 {

Copy link

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

Copy link
Author

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.

Copy link

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

@Rule
public ExpectedException expectedEx = ExpectedException.none();

@Test
public void testIterator() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
}
}
53 changes: 53 additions & 0 deletions src/test/java/org/takes/misc/VerboseIteratorTest.java
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{

Copy link

Choose a reason for hiding this comment

The 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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
}
}