Skip to content
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

Merged
merged 8 commits into from
Apr 23, 2024

Conversation

harshitsharma2801
Copy link
Contributor

  1. Added Junit5 to POM.XML
  2. Added maven-surefire-plugin to run tests on every build
  3. POM.XML was formatted by a XML Formatter
  4. Added a setter to set mqEndpoints to mock and test the endpoints from SampleEnvSetterTest.

@chughts chughts self-requested a review April 9, 2024 08:55
@@ -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){
Copy link
Collaborator

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.

@harshitsharma2801
Copy link
Contributor Author

  1. Removed the setter function
  2. Updated Readme
  3. Added test for Env file

static SampleEnvSetter envSetter;

@BeforeAll
public static void setUp() throws NoSuchFieldException, IllegalAccessException{
Copy link
Collaborator

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:

  1. That the env setter is able to read the file, whose name and location are specified by an environment variable.
  2. That it allows overrides via environment variables.
  3. How it behaves when there are missing values in the env file.
  4. 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);
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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";
Copy link
Collaborator

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.

@rcoppen rcoppen merged commit bffc927 into ibm-messaging:master Apr 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants