2

I started using dependency injection with roboguice and created an interface like DataProvider. I have an implementation which retrieves the data from some WebServer located in the WebServerDataProvider class. In Order to eliminate the waiting for the webserver i added a DummyDataProvider.

Where would i put such class? I don't like that it is in /src/main/java/my/package/providers/ since it is not real part of the application, but still i need it for development.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
Absurd-Mind
  • 7,884
  • 5
  • 35
  • 47
  • Perhaps better to put it along with unit-tests and write some test case (for instance, an Android test project), instead of using it directly in the app code. – yorkw Dec 19 '12 at 03:50

2 Answers2

1

Typically you would use such a class in your unit tests. Roboguice works well with Robolectric , which allows you to mock things like http access. If you do that you would put your code in src/test/java/...

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • hmpf, i missed it that src/test/java is in classpath even for simple application start when starting from the IDE. In this case it's obvious that these classes should go there. – Absurd-Mind Dec 19 '12 at 11:20
0

You could put it into the main project if you want to use it for fiddling around with the application without bothering the server each time and deactivate it with some constant for deployment, e.g.

if (DEBUG) {
    setDataProvider(new MockDataProvider());
}

Proguard should be smart enough to remove this unused class if you remember to reset your variable (you might have to fiddle around with the settings there).

koljaTM
  • 10,064
  • 2
  • 40
  • 42