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 800573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:18:34+00:00 2026-05-14T23:18:34+00:00

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want

  • 0

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want to test the behaviour of some servlets.

I know JUnit probably provides this functionality but I don’t know how to use it (I will learn soon) and need to do this reasonably quickly.

HTTPServletRequest and HTTPServletResponse are both interfaces so they can’t be instantiated. There is a HttpServletRequestWrapper which implements HttpServletRequest but it doesn’t seem to have any setParameter() type methods and HttpServletResponse doesn’t seem to have any implementing classes at all.

How can I test my code by passing a suitable HttpServletRequest object and then checking that the received HttpServletResponse object matches what I expect?

  • 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-14T23:18:35+00:00Added an answer on May 14, 2026 at 11:18 pm

    The fact that it’s an interface makes it easier to mimic: It’s mocking final classes that’s tricky.

    class MyHttpServletRequest implements HttpServletRequest
    {
      //whatever
    }
    
    class MyHttpServletResponse implements HttpServletResponse
    {
      //whatever
    }
    
    
    doGet(new MyHttpServletRequest(),
          new MyHttpServletResponse())
    

    Subclassing HttpServletRequestWrapper may be easier, but it’s not necessary. I would look at overriding getParameter and getParameterMap

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

Sidebar

Related Questions

I want to mimic behaviour with jQuery like you can see here: http://edo.webmaster.am/ Just
I want to mimic the Excel equivalent PERCENTILE function in C# (or in some
I am trying to mimic std::map<string, std::list<string> > in VBA (this case is very
I want to mimic a Python functionality in Java. In Python if I want
I want to mimic the trim behavior of Photoshop (crop the area that is
I need to mimic changes (property/list) changes on an object and then apply it
How can I mimic this PHP functionality in twig? I need to increment a
I'd like to mimic a .NET class signature (and possibly some major pieces of
I'm trying to mimic IP camera that use MJPEG. At this moment to receive
I'd like to mimic html form behaviour using jquery. When clicking on a button,

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.