Instantiating a class without constructor and with @Value annotation for Junit

Hi,
I want to make a Bean in context of my Junit code of a spring web application. Here is the class in the project that i want to instantiate.
This has no constructor and also uses @Value annotation. How to do it.

@Service
public class AppEnvironment {

    @Value("${app.appId}")
    private String appId;
    @Value("${app.appSecret}")
    private String appSecret;
    @Value("${app.isProd}")
    private boolean isProd;
    @Value("${app.baseUrl}")
    private String baseUrl;
    @Value("${app.botId}")
    private String botGUID;
    @Value("${app.botToken}")
    private String botToken;
    @Value("${app.iconUrl}")
    private String appIconUrl;
    private String fontColor;
    @Value("${app.notificationHostname}")
    private String reminderBotHost;

Open in new window


Thanks
Rohit BajajAsked:
Who is Participating?
 
girionisConnect With a Mentor Commented:
There are several approaches:

1) Mock the class (using Mockito/JMock/any other mocking framework)
2) Run it with SpringJUnit4ClassRunner and use a @TestPropertySource
3) Change the access to package and set the values manually.
0
 
girionisCommented:
This is a perfectly valid answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.