-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added unit tests for SampleEnvSetter. #228
Conversation
harshitsharma2801
commented
Apr 8, 2024
- Added Junit5 to POM.XML
- Added maven-surefire-plugin to run tests on every build
- POM.XML was formatted by a XML Formatter
- Added a setter to set mqEndpoints to mock and test the endpoints from SampleEnvSetterTest.
@@ -233,4 +233,8 @@ public int getCount() { | |||
// need to come from a CCDT and environment settings | |||
return (null == mqEndPoints) ? 1 : mqEndPoints.length(); | |||
} | |||
|
|||
public void setMqEndpoints(JSONArray mqEndPoints){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a function just to test it!
Remove this function, we should be testing the functions that already exist, and are being used.
|
static SampleEnvSetter envSetter; | ||
|
||
@BeforeAll | ||
public static void setUp() throws NoSuchFieldException, IllegalAccessException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be mocking the endpoints. The point of the test is to verify:
- That the env setter is able to read the file, whose name and location are specified by an environment variable.
- That it allows overrides via environment variables.
- How it behaves when there are missing values in the env file.
- How it behaves when the file can't be found.
int value = envSetter.getPortEnvValue("PORT", 0); | ||
assertEquals(1415 , value); | ||
assertNotNull(value); | ||
|
||
//Test for default port given invalid port key | ||
value = envSetter.getPortEnvValue("INVALID_PORT", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is INVALID_PORT
returning 1414 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function returns the default port if the key is not found.
@@ -22,13 +22,13 @@ | |||
|
|||
public class SampleEnvSetterTest { | |||
|
|||
static SampleEnvSetter envSetter; | |||
private static SampleEnvSetter envSetter; | |||
private static final String ENV_FILE = "EnvFile"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are no longer use, they can be removed.