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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:04:32+00:00 2026-05-11T01:04:32+00:00

I have a class that after it does some stuff, sends a JMS message.

  • 0

I have a class that after it does some stuff, sends a JMS message. I’d like to unit test the ‘stuff’, but not necessarily the sending of the message.

When I run my test, the ‘stuff’ green bars, but then fails when sending the message (it should, the app server is not running). What is the best way to do this, is it to mock the message queue, if so, how is that done.

I am using Spring, and ‘jmsTemplate’ is injected, along with ‘queue’.

  • 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. 2026-05-11T01:04:33+00:00Added an answer on May 11, 2026 at 1:04 am

    The simplest answer I would use is to stub out the message sending functionality. For example, if you have this:

    public class SomeClass {     public void doit() {         //do some stuff         sendMessage( /*some parameters*/);     }      public void sendMessage( /*some parameters*/ ) {          //jms stuff     } } 

    Then I would write a test that obscures the sendMessage behavior. For example:

    @Test public void testRealWorkWithoutSendingMessage() {     SomeClass thing = new SomeClass() {         @Override         public void sendMessage( /*some parameters*/ ) { /*do nothing*/ }     }      thing.doit();     assertThat( 'Good stuff happened', x, is( y ) ); } 

    If the amount of code that is stubbed out or obscured is substantial, I would not use an anonymous inner class but just a ‘normal’ inner class.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Read up on Technical Debt. This is a simple cost-benefit… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer Use Reader.read(). A return value of -1 means end of… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer having done this before.. First thing you need to do… May 11, 2026 at 5:41 pm

Related Questions

I take care of critical app in my project. It does stuff related to
I'm trying to pass an instance of a class between two separate classes, like
I'm a Java rookie and I was wondering, if I have the following typical
In win32, how do I setup a callback mechanism for RichEdit I have not

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.