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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:28:16+00:00 2026-06-03T16:28:16+00:00

I have a factory class to retrieve the configuration for my application: public class

  • 0

I have a factory class to retrieve the configuration for my application:

public class ConfigurationFactory {
private static ConfigurationFactory configurationFactory = new ConfigurationFactory();

private Configuration configuration = null;

public static ConfigurationFactory getConfigurationFactory() {
        return configurationFactory;
    }

And some getConfiguration methods depending on where I am getting the config from (file, database, default, etc…):

public Configuration getConfiguration(String path){...}
public Configuration getConfiguration(String database){...}

My problem is that when I do unit test for each method, I have to restart the singleton in order to load from a different source, so the only thing I had come up to is adding this:

public void resetConfiguration() {
 this.configuration = null;
}

And I feel I’ll burn in developer’s hell for doing it 🙂

My question: Is there any other way to do it without adding this method?

Note: I have seen this and I cannot use any DI framework like Spring or Guice, management thinks adding a framework would make the project heavyweight, as this program is intended to run as a daemon on servers.

  • 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-03T16:28:17+00:00Added an answer on June 3, 2026 at 4:28 pm

    Some of the things which i can think of are

    1. Use mocking frameworks like Easymock or Mockito to mock the ConfigurationFactory and use this mock objects in other calling areas.

    2. Have a setter defined in the ConfigurationFactory class and define an annotation like @TestPurpose and use this to override the singleton object from your unit tests. The annotation is to denote that this should not be used during the application flow and the function is meant only for junit purpose.

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

Sidebar

Related Questions

I have the following factory class: public class MessagePresenterCreator implements IPresenterFactory{ @Override public MessagePresenter
In my console application have an abstract Factory class Listener which contains code for
I have a factory class, DocumentLoaderFactory , which simply returns an instance that implements
So I have a factory class and I'm trying to work out what the
I have a class with a factory-pattern function in it: abstract class ParentObj {
I have a script with a factory method that I would like to return
im new in hibernate and JPA and i have some problems with annotations. My
Is it good practice to have a Factory method to retrieve injected objects or
I have a Factory class that creates a Widget object. The Factory object needs
in C# you have to declare everything in a class so an example factory

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.