jeudi 14 juin 2018

Intercepting method calls in Java with mockito or proxies

I'd like to know if there is a way to intercept class method call that contacts the server and returns configuration settings for my application and then return required value for my test. My application looks like this

package application;

class Application { 
  private static synchronized void getServerConfiguration() {
      ConfigurationAccessor accessor = new ConfigurationAccessor();
      optionOne = accessor.getOption("option-one"); // <- intercept this method call and return different value
      ...
  }
}

In my tests I need to use a running instance of the application to run GUI tests :

package tests;

class SomeTest {

@BeforeClass public static void startApplication() {
  createUsers();
  Application.start(); <- this will start application and load config from server
}

Unfortunately it's not possible to run connection via proxy server to mock responses.

Aucun commentaire:

Enregistrer un commentaire