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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:25:49+00:00 2026-06-18T14:25:49+00:00

Having real hard time trying to fix this issue could anyone help me please?

  • 0

Having real hard time trying to fix this issue could anyone help me please?

I am clearly doing something fundamently wrong i have tried to verify each Mock object but it doesn’t seem to work.

 org.mockito.exceptions.misusing.UnfinishedVerificationException: 
 Missing method call for verify(mock) here:
 -> at     com.muuves.reservosity.service.TestProductServiceImpl.search_OneHourSlot_TwoBookingAvailable(TestProductServiceImpl.java:86)

 Example of correct verification:
verify(mock).doSomething()

Also, this error might show up because you verify either of: final/private/equals()  /hashCode() methods.
Those methods *cannot* be stubbed/verified.

at com.muuves.reservosity.service.TestProductServiceImpl.setUp(TestProductServiceImpl.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Here are my tests

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class TestProductServiceImpl {    
    ProductServiceImpl instance;
    @Mock
    EntityManager em;
    @Mock
    CriteriaBuilder builder;
    @Mock 
    CriteriaQuery<Product_Details> c;
    @Mock
    Root<Product_Details> productRoot;
    @Mock
    TypedQuery<Product_Details> typedQuery;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this); 
        instance = new  ProductServiceImpl();
        instance.setEm(em);
        instance.setCriteriaBuilder(builder);
        instance.setQuery(c);
        instance.setProductRoot(productRoot);
        instance.setTypedQuery(typedQuery);
    }

    @Test
    public void search_OneHourSlot_NoBookingAvailable() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("14:00-15:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(0, result.size());
    }
    @Test
    public void search_OneHourSlot_TwoBookingAvailable() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("14:00-17:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(1, result.size());
        Assert.assertEquals("2013-02-09 15:00", result.get(0).getTime());
        Assert.assertEquals("Google", result.get(0).getProductDetails().getProduct_Name());
    }

    @Test
    public void search_OneHourSlot_EndTimeAfterClosing() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("14:00-20:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(1, result.size());
        Assert.assertEquals("2013-02-09 15:00", result.get(0).getTime());
        Assert.assertEquals("Google", result.get(0).getProductDetails().getProduct_Name());
        verify(em);
    }

    @Test
    public void search__StartTimeBeforeOpening() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("08:00-13:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(3, result.size());
        Assert.assertEquals("2013-02-09 09:00", result.get(0).getTime());
        Assert.assertEquals("Google", result.get(0).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 10:00", result.get(1).getTime());
        Assert.assertEquals("Google", result.get(1).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 11:00", result.get(2).getTime());
        Assert.assertEquals("Google", result.get(2).getProductDetails().getProduct_Name());
    }
    @Test
    public void search__StartTimeAndEndTimeBeforeOpening() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("06:00-09:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(0, result.size());
    }
    @Test
    public void search__StartTimeAndEndTimeAfterClosing() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("17:00-21:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(0, result.size());
    }
    @Test
    public void search__StartTimeAndEndTimeExactlyOpeningClosing() {
        List<Product_Details> products = booking(60);
        when(em.getCriteriaBuilder()).thenReturn(builder);
        when(builder.createQuery(Product_Details.class)).thenReturn(c);
        when(c.from(Product_Details.class)).thenReturn(productRoot);
        when(em.createQuery(c)).thenReturn(typedQuery);
        when(typedQuery.getResultList()).thenReturn(products);
        Search search = new Search();
        search.setDate("2013-02-09");
        search.setLocation("Cork");
        search.setPrice("20");
        search.setTime("09:00-17:00");
        search.setType("Football");
        List<Search_Result> result = instance.search(search);
        Assert.assertEquals(5, result.size());
        Assert.assertEquals("2013-02-09 09:00", result.get(0).getTime());
        Assert.assertEquals("Google", result.get(0).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 10:00", result.get(1).getTime());
        Assert.assertEquals("Google", result.get(1).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 11:00", result.get(2).getTime());
        Assert.assertEquals("Google", result.get(2).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 13:00", result.get(3).getTime());
        Assert.assertEquals("Google", result.get(3).getProductDetails().getProduct_Name());
        Assert.assertEquals("2013-02-09 15:00", result.get(4).getTime());
        Assert.assertEquals("Google", result.get(4).getProductDetails().getProduct_Name());
    }
    private List<Product_Details> booking(int slot){
        List<Product_Details> products = new ArrayList<Product_Details>();
        Product_Details product = new Product_Details();
        product.setProduct_Name("Google");
        product.setSaturday_Open("09:00-17:00");
        product.setDates_Closed("2013-12-25");
        product.setTime_Per_Slot(slot);
        List<Booking_Details> bookings = new ArrayList<Booking_Details>();
        Booking_Details booking1 = new Booking_Details();
        booking1.setBooked_Date("2013-02-09 12:00");
        bookings.add(booking1);
        Booking_Details booking2 = new Booking_Details();
        booking2.setBooked_Date("2013-02-09 14:00");
        bookings.add(booking2);
        Booking_Details booking3 = new Booking_Details();
        booking3.setBooked_Date("2013-02-09 16:00");
        bookings.add(booking3);
        product.setBookings(bookings);
        products.add(product);
        return products;
    }
}

If somebody could help me that would be great.

  • 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-18T14:25:50+00:00Added an answer on June 18, 2026 at 2:25 pm

    You are trying to use verify method of Mockito framework in wrong way. It is used to verify that some behaviour happened once.
    In your tests you should specify what behaviour have happened (by behaviour meant method call).

    Here is an example of test that checks that checks method for sending mails:

    @RunWith(MockitoJUnitRunner.class)
    public class MailSenderTest {
    
        @Mock
        private JavaMailSender javaMailSender;
    
        @InjectMocks
        private MailSenderImpl mailSender;
    
        @Test
        public void testSendMail() {
    
            String from = "somemail@gmail.com";
            String to = "Danothermail@gmail.com";
            String title = "Test";
            String text = "Hello world!";
    
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(from);
            message.setTo(to);
            message.setSubject(title);
            message.setText(text);
    
            mailSender.sendMail(to, title, text);
    
            Mockito.verify(javaMailSender).send(message);
        }
    
    }
    

    As you can see from this example after verify(..) I specify method call that I want to check. In other words by last row
    of example I check that during execution of the sendMail(…) method of my service method send(..) of the JavaMailSender have been
    called with correct parameters.

    Look at the mockito official page. There are a lot of simple and usefull examples with good description. Here is a link to it.

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

Sidebar

Related Questions

I'm having a real hard time trying to figure out how to fix this
I think this should be simple, but im having a real hard time finding
Having a real hard time with this since I'm new to jQuery, but I'm
I am having a real hard time understanding something. In the project I've been
I'm having a real hard time showing a localized string during the installation of
I'm having a real hard time adding RadarColumnSeries to my Radar Chart using ActionScript.
I'm creating a Java swing app and I'm having a real hard time getting
I am having a real hard time finding a way to start, stop, and
I've been having a hard time trying to understand PyPy's translation. It looks like
I've just discovered this property in MVC projects, but I'm having a hard time

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.