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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:20:50+00:00 2026-06-06T14:20:50+00:00

I have a static methods class, Utils, that is basically for utility methods, its

  • 0

I have a static methods class, Utils, that is basically for utility methods, its used by almost every class. It does things like get files and other basic stuff. My tester went and changed this class to a singleton so that every class using Utils now has to call getInstance(). The reason was that he couldn’t test certain things unless this was the case. It seems to me that this is wrong in some ways and that this could lead to issues.

public class Utils {

/**
 * Singleton method to allow for easier testing.
 * @return an instance of
 */
public synchronized static Utils getInstance() {
    if (instance == null) {
        instance = new Utils();
    }
    return instance;
}

public synchronized static void setInstance(Utils instance) {
    Utils.instance = instance;
}

/** Singleton to make testing easier **/
private static Utils instance = null;

public static boolean checkOSTen() {
    return getInstance()._checkOSTen();
}

private boolean _checkOSTen() {
    boolean autoPair = false;
    if (android.os.Build.VERSION.SDK_INT >= 10){   
        autoPair = true;
    }
    return autoPair;
}

}

By the way I have a very complex system of internal messaging that uses at least 7 threads to send messages and wanted to see if there is an impact of static method calls vs Singleton static method calls.

Is there another way to do testing other than this? Seems some Java reflection would get what you need.

  • 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-06T14:20:51+00:00Added an answer on June 6, 2026 at 2:20 pm

    Your tester probably finds this code difficult to test as they can’t easily change the return value of android.os.Build.VERSION.SDK_INT, and therefore they can’t easily test the different code paths that are used depending on this return value. By using an instance method they can use a mocking framework to fake the _checkOSTen method to return either true or false, depending on what they are trying to test.

    Another way to do testing is to not use static methods such as these at all, and instead use class (perhaps called DeviceCapabilities) which will be injected via a setter or a constructor into every other class that requires knowledge of the version of the OS.

    Then, your tester could easily pass instances of DeviceCapabilities to whichever class needed access to this information.

    That said, at this stage in your build it may be too late to make a change like this so the change your tester has made is a reasonable compromise.

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

Sidebar

Related Questions

Assume, that I have class with static methods only. Will class loader load every
If I have a class called myclass does having static methods within the class
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
I have a class that looks like this: utils/Result.php <?php class Result { public
In Java, the java.util.Arrays class have several static toString(...) methods that take an array
I have a static method that takes a parameter and returns a class. the
How often should I use static methods generally? If I have like: Class1 _class34
I have a Django model with some static methods. I'd like to call the
When I've used common-collections I've done custom extensions to those utils like: class MyCollectionUtils
I have a util class (C#) where I have a static method that takes

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.