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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:00:41+00:00 2026-06-14T23:00:41+00:00

Following is the test code: package a.b.c.concurrent.locks; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import

  • 0

Following is the test code:

package a.b.c.concurrent.locks;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.when;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

import mockit.Mocked;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestLockConcludesProperly {

    private static LockProxy lockProxy;

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout()));
    }

    @Test
    public void testAquireLockInFirstIteration(@Mocked Lock mockLock) throws Exception {

        when(mockLock.tryLock(anyLong(), any(TimeUnit.class))).thenReturn(true);

        lockProxy = new LockProxy(mockLock, 2, TimeUnit.MILLISECONDS);

        lockProxy.lock();

    }
}

The error I get and just can’t figure out, though it is probably some misconfiguration on my part, is:

Tests in error: 
  testAquireLockInFirstIteration(a.b.c.concurrent.locks.TestLockConcludesProperly): 
Misplaced argument matcher detected here:

-> at a.b.c.concurrent.locks.TestLockConcludesProperly.testAquireLockInFirstIteration(TestLockConcludesProperly.java:34)
-> at a.b.c.concurrent.locks.TestLockConcludesProperly.testAquireLockInFirstIteration(TestLockConcludesProperly.java:34)

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().

What am I doing wrong?

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

    My bad…

    It would seem as if I had mixed up JMockit API and Mockito’s API.

    All I needed to do in order to mock the Lock interface was:

        @Test
        public void testAquireLockInFirstIteration() throws Exception {
    
            Lock mockLock = Mockito.mock(Lock.class);
            when(mockLock.tryLock(anyLong(), any(TimeUnit.class))).thenReturn(true);
    
            lockProxy = new LockProxy(mockLock, 2, TimeUnit.MILLISECONDS);
    
            lockProxy.lock();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code: package test; import java.util.logging.Level; import java.util.logging.Logger; class Data{ int ar[]=new
create file test1.scala with following code: package test import java.io.FileInputStream object Foo create another
Please have a look at the following code package test; import java.awt.*; import java.awt.event.*;
I have the following simple code: package test; import javax.swing.*; class KeyEventDemo { static
Given the following not-very-useful code: package com.something; import java.util.ArrayList; import java.util.Collection; //Not a generic
So i have the following code: package animation; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage;
The following code returns null for me. package test; import com.google.gson.Gson; class test {
Code: package com.parse; import org.w3c.dom.*; import javax.xml.xpath.*; import javax.xml.parsers.*; import java.io.IOException; import org.xml.sax.SAXException; public
With the following source code: package util.abc; public class Test{ public String out(){ return
I have the following code: class Test { public static void main(String[] args) {

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.