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

  • Home
  • SEARCH
  • 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 7853401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:40:42+00:00 2026-06-02T19:40:42+00:00

new to Java programming, I am just trying to understand how I can make

  • 0

new to Java programming, I am just trying to understand how I can make this class be tested. I have made a Queue class:

public class Queue<E> {

private ArrayList<E> items;

public Queue(){
    items = new ArrayList<E>();
}

public void join(E e) {
    items.add(e);
}

public E leave() throws EmptyQueueError {
    if (items.isEmpty()) {
        throw new EmptyQueueError();
    }
    return items.remove(0);

}

}

I want to make a JUnit called QueueTest that is automatically reset to empty before each test that is commenced? Then I want it check that removing an item from an empty queue throws an EmptyQueueError? Finally, I want it to check that when several items join an (initially) empty queue, it is the first item that joined which is the first to leave?

It’s a tutorial I am following but it fails to make me understand. I have made the class above and I have attempted the JTest class:

package queue;

public class QueueTest<e> {

private Queue q;

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void test() {
    q = new Queue<e>();
    assertEquals("Empty Queue", 0, q);

}

}

Am I close to what I am trying to achieve? I am trying to do the first one.

Thank you for your help and ample time.

  • 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-06-02T19:40:44+00:00Added an answer on June 2, 2026 at 7:40 pm

    You’re doing well.

    @Test
    public void test() {
        q = new Queue<e>();
        assertEquals("Empty Queue", 0, q);
    
    }
    

    The problem with this is that you make a new Queue instance, but you don’t do anything with it.

    Then your test’s innards could be

    @Test
    public void test() {
        Queue<Integer> q = new Queue<Integer>();      // A
        try {
            Integer ignore = q.leave();     // B
            fail("exception expected");               // C
        } catch (EmptyQueueError ex) {
            // implicit success                       // D
        }
    }
    

    What this means is that you’d make a Queue (‘A’), then immediately try to get an item (‘B’). This should cause an exception. If it does not, your test fails with “exception expected” (‘C’). If the expected exception is thrown, you code works (‘D’)

    I’ll post more once you get this working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I am new to Android and Java programming. I have a class which implements
I am new to thread programming in Java. To understand threading I'm trying to
sry about my english :) Im new to Java programming and i have a
I have been working on Eclipse recently. I am fairly new to java programming,
I am new to Android/java programming. I really have no clue what I am
Before I start know this: I am extremely new to Java and programming. How
I'm new to Android & Java programming but have been programming in .NET for
I'm trying out several exercises from a Java programming book. I have the code
I'm quite new to Java Programming and am writing my first desktop app, this

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.