Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:36:43+00:00 2026-05-31T13:36:43+00:00

I am trying to do tests on a class that implements Iterable. When I

  • 0

I am trying to do tests on a class that implements Iterable. When I go to test any method,in the itorator class, like hasNext(), next(). So when I call list.itorator().Next(); nothing happens, the node is the current node in the list not the next. but when I do ListIterator itrList = new ListIterator(list); the code inside it works. I am calling public Iterator iterator() {return new ListIterator (this);
So what am I not doing correctly/ grasping?
Thanks for any help.

public void test6() {
    List<String> list = new List<String>();

    list.addAfterCurrent("1");
    list.addAfterCurrent("2");
    list.addAfterCurrent("3");
    ListIterator itrList = new ListIterator(list);


    TextIO.putln(list.iterator().next()); // output is 1
    TextIO.putln(list.iterator().next()); // output is 1 
    TextIO.putln(itrList.next());         // output is 1
    TextIO.putln(itrList.next());         // now output is 2           
    assertEquals("1", list.getCurrent());
    assertEquals(3, list.size());

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:36:44+00:00Added an answer on May 31, 2026 at 1:36 pm

    You’re creating a fresh iterator each time you call list.iterator(). You want to keep the same iterator and call its next method multiple times, e.g.

    Iterator itr = list.iterator();
    assertEquals(1, itr.next());
    assertEquals(2, itr.next());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to test a class that manages data access in the database
I'm trying to test a class that takes a factory ( Func<T> ) and
I'm trying to Unit Test a class that has many internal functions. These obviously
I am trying to write a Unit test for a class that has several
I'm trying to call Error(My Test) in normal cpp class (Not a COM object,
I'm trying to compile a class Tmp that implements an interface TmpInter . /*
I've been trying to create a simple class that implements the ViewSwitcher.ViewFactory interface basing
I have a class that I am trying to do unit tests on. The
I'm trying to set up integration tests using the AbstractTransactionalJUnit4SpringContextTests base class. My goal
Trying to add tests to the gobject-introspection test suite to cover more of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.