I am trying to test a spring bean which is as service. I am doing outside-in like approach by passing collaborators in.
In my case service depends on repository and other class that is parsing the data coming from the repository. Since parser is very specific and I am not sure whether I will need to have different parsers in the future I am reluctant to create an interface and I would like to make parser package private so I have more control in the future over how my service works.
My problem is writing a test where I want to mock the parser which I can do but I don't want to use package private setters, field setting or some other a little ugly approach.
Only option I think I have is to have two constructors:
- First one for spring to inject repository and within constructor my service will create an instance of a parser
- Second one is package private taking two arguments in - repository and parser.
Would like to hear from the community.
What other options are out there for me? Is there something I should do different with my design?
Aucun commentaire:
Enregistrer un commentaire