You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Manuel Doninger <ma...@googlemail.com> on 2011/01/03 09:35:09 UTC

Two classes with same name in src/main/java and src/test/java

Hi,
i have the following constellation: I have a class Feature.java and a
class MapData.java in my folder src/main/java. The Feature contains
some work to do, and the MapData is contains a HashMap which is
populated with data from a database and their methods are called in
Feature. Now i want to write unit tests for my class Feature, but i
don't want to start a database connection if the MapData is called. So
i thought about creating a class MapData in my folder src/test/java,
which contains all methods like my real MapData, but with test data in
it.
If i call "mvn test", i get some strange errors, like
NoSuchMethodErrors etc. If i exclude the src/main/java/MapData in my
Eclipse Build Path, then the tests run fine.

I have now 2 questions:
1. Why does Maven consider my Eclipse build path? I thought, if i run
maven from my command line, only the pom.xml applies.
2. How can i solve my problem? Is there a possibility to exclude my
src/main/java/MapData in my pom, with the surefire plugin?

Thank you for your suggestions,

Manuel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Two classes with same name in src/main/java and src/test/java

Posted by Samuli Saarinen <sa...@remion.com>.
Hello,

You could use jmockit [1] and replace the functionality in MapData.

Or you could change the Feature class to accept MapData as contructor 
arg or with setter and replace it in tests with another implementation 
of MapData...

br,
Samuli

[1] http://code.google.com/p/jmockit/


On 3.1.2011 10:35, Manuel Doninger wrote:
> Hi,
> i have the following constellation: I have a class Feature.java and a
> class MapData.java in my folder src/main/java. The Feature contains
> some work to do, and the MapData is contains a HashMap which is
> populated with data from a database and their methods are called in
> Feature. Now i want to write unit tests for my class Feature, but i
> don't want to start a database connection if the MapData is called. So
> i thought about creating a class MapData in my folder src/test/java,
> which contains all methods like my real MapData, but with test data in
> it.
> If i call "mvn test", i get some strange errors, like
> NoSuchMethodErrors etc. If i exclude the src/main/java/MapData in my
> Eclipse Build Path, then the tests run fine.
>
> I have now 2 questions:
> 1. Why does Maven consider my Eclipse build path? I thought, if i run
> maven from my command line, only the pom.xml applies.
> 2. How can i solve my problem? Is there a possibility to exclude my
> src/main/java/MapData in my pom, with the surefire plugin?
>
> Thank you for your suggestions,
>
> Manuel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



-- 
Remion Oy           Etävalvontajärjestelmät liiketoiminnan
Samuli Saarinen           tehostamiseen
gsm +358 (0)50 3560075
fax +358 (0)3 2125064       www.remion.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org