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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:25:01+00:00 2026-06-06T07:25:01+00:00

Form docs: Comparable c=mock(Comparable.class); when(c.compareTo(anyInt())).thenReturn(-1); I would like: File tempDir=new File(test); Comparable c=mock(Comparable.class); when(c.compareTo(anyInt())).thenReturn(tempDir.mkdir());

  • 0

Form docs:

   Comparable c=mock(Comparable.class);
    when(c.compareTo(anyInt())).thenReturn(-1);

I would like:

 File tempDir=new File("test");
   Comparable c=mock(Comparable.class);
    when(c.compareTo(anyInt())).thenReturn(tempDir.mkdir());

So will be created real folder (i will use it next private method of class).
Does it possible?
Thanks.

  • 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-06T07:25:03+00:00Added an answer on June 6, 2026 at 7:25 am

    It’s incredibly unclear what you’re trying to accomplish. I’m not at all certain why you want to do something like this in the first place.

    As I said in my comment, the reason your current example won’t compile is because File.mkdir() returns a boolean and Comparable.compareTo(Comparable) returns an int. You can, however, make this compile if you are mocking a method that returns a boolean, like so:

    public class Foo {
      public static void main(String[] args) {
        File file = new File("/tmp/111");
        Bar bar = mock(Bar.class);
        when(bar.isTrue()).thenReturn(file.mkdir());
      }
    
      public static interface Bar {
        public boolean isTrue();
      }
    }
    

    That said, I seriously doubt this will do what you want. The line when(bar.isTrue()).thenReturn(file.mkdir()); actually invokes file.mkdir(). So your directory will be created when you create your mock. In other words, the previous example can (and should) be equivalently written as:

    public class Foo {
      public static void main(String[] args) {
        File file = new File("/tmp/111");
        Bar bar = mock(Bar.class);
        boolean dirMade = file.mkdir();
        when(bar.isTrue()).thenReturn(dirMade);
      }
    
      public static interface Bar {
        public boolean isTrue();
      }
    }
    

    Writing it like this would avoid any confusion on when the directory was actually created.

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

Sidebar

Related Questions

I would like to create an event signup form using Google Docs. The user
Form validation plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ Test url: http://docs.jquery.com/Plugins/Validation How to reproduce: 1.) Click on the
All, I'm trying to use the jQuery Form Validator (http://docs.jquery.com/Plugins/Validation). However I'd like to
Say I have a form like: class GeneralForm(forms.Form): field1 = forms.IntegerField(required=False) field2 = forms.
My form class: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form { public function init(){
jQuery Mobile Docs says if we wrap form element in div containing data-role=fieldcontain proper
The docs say: you should implement methods of the form validate:error:, as defined by
From the docs: The as operator is like a cast except that it yields
I use the JQuery Validation plugin to validate a form ( http://docs.jquery.com/Plugins/Validation/ ) For
I have a form that uses google docs and when you submit it will

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.