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

ELY-2641 : Simplify assersions in MaskCommandTest#testMissingSaltAnd iteration method #1961

Merged

Conversation

nidhiazad
Copy link

https://issues.redhat.com/browse/ELY-2641

Simplify assersions in MaskCommandTest#testMissingSaltAndIteration method

@PrarthonaPaul
Copy link
Contributor

Thank you @nidhiazad for the PR!
@Skyllarr just wondering, does this line also need to be turned to assertEquals?
assertTrue("output has to be the as pre-generated one", ("MASK-" + pbGenerated + ";" + "ASDF1234" + ";" + 123).equals(retValNoNewLine));
If not, then it looks good to me

@SoniaZaldana
Copy link
Contributor

Thank you @nidhiazad for the PR! @Skyllarr just wondering, does this line also need to be turned to assertEquals? assertTrue("output has to be the as pre-generated one", ("MASK-" + pbGenerated + ";" + "ASDF1234" + ";" + 123).equals(retValNoNewLine)); If not, then it looks good to me

@PrarthonaPaul I think the issue only involves changing statements in testMissingSaltAndIteration. The line you quoted is within another test, so most likely not :)

@PrarthonaPaul
Copy link
Contributor

Thank you @nidhiazad for the PR! @Skyllarr just wondering, does this line also need to be turned to assertEquals? assertTrue("output has to be the as pre-generated one", ("MASK-" + pbGenerated + ";" + "ASDF1234" + ";" + 123).equals(retValNoNewLine)); If not, then it looks good to me

@PrarthonaPaul I think the issue only involves changing statements in testMissingSaltAndIteration. The line you quoted is within another test, so most likely not :)

Awesome, thank you @SoniaZaldana
In that case, this PR looks good! Thank you @nidhiazad

Copy link
Contributor

@SoniaZaldana SoniaZaldana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Contributor

@ashley-abdelsayed98 ashley-abdelsayed98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution @nidhiazad

assertTrue("Message about invalid iteration parameter must be present", ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Message about invalid salt parameter must be present", true, retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
assertEquals("Message about invalid iteration parameter must be present", true, ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this statement is passing true as the expected value and then passes this line:("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]) as the actual value to the assertEquals function to confirm that they are equal. we can simplify this by just passing ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.") as the expected value and retValLines[1] as the actual value to the assertEquals function and the function will compare to check if the 2 strings are equal.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thanks. Fixing this.

assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Message about invalid salt parameter must be present", true, retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
assertEquals("Message about invalid iteration parameter must be present", true, ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertEquals("Message about invalid salt parameter must be present",true, retValLines[2].contains("MASK-"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, i think we can keep the original statement that asserts retValLines[2].contains("MASK-") is true, rather than asserting that statement is equal to true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nidhiazad. rather than using assertEquals for all 3 statements, i think the first and last statement can be kept with assertTrue, instead of asserting that retValLines[2].contains("MASK-") is true

Suggested change
assertEquals("Message about invalid salt parameter must be present",true, retValLines[2].contains("MASK-"));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));

assertTrue("Message about invalid salt parameter must be present", retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
assertTrue("Message about invalid iteration parameter must be present", ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Message about invalid salt parameter must be present", true, retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can keep the original statement that asserts retValLines[0].contains("Invalid \"salt\" parameter. Generated value") is true, rather than asserting that statement is equal to true

@nidhiazad
Copy link
Author

updated the code. Please review and let me know if anything needs to be done.

assertTrue("Message about invalid salt parameter must be present", retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
assertTrue("Message about invalid iteration parameter must be present", ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Invalid \"salt\" parameter. Generated value", retValLines[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this case, we want to keep the original statement that retValLines[0] contains the string "Invalid \"salt\" parameter. Generated value" but it is not equal to it

assertTrue("Message about invalid iteration parameter must be present", ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Invalid \"salt\" parameter. Generated value", retValLines[0]);
assertEquals("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.",retValLines[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all 3 statements, we can keep the original messages that indicaet why this assertion should pass:

Suggested change
assertEquals("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.",retValLines[1]);
assertEquals("Message about invalid salt parameter must be present", "Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.",retValLines[1]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashley-abdelsayed98 I am passing message,expected,actual in the assertEquals method for all the three statements now. This is how it needs to be done. Sorry about the previous commits. Hope so this one is correct. Please let me know if any alteration is required.

@Skyllarr
Copy link
Contributor

Thank you @nidhiazad for the PR! @Skyllarr just wondering, does this line also need to be turned to assertEquals? assertTrue("output has to be the as pre-generated one", ("MASK-" + pbGenerated + ";" + "ASDF1234" + ";" + 123).equals(retValNoNewLine)); If not, then it looks good to me

@PrarthonaPaul I think the issue only involves changing statements in testMissingSaltAndIteration. The line you quoted is within another test, so most likely not :)

That's right! This

Thank you @nidhiazad for the PR! @Skyllarr just wondering, does this line also need to be turned to assertEquals? assertTrue("output has to be the as pre-generated one", ("MASK-" + pbGenerated + ";" + "ASDF1234" + ";" + 123).equals(retValNoNewLine)); If not, then it looks good to me

@PrarthonaPaul I think the issue only involves changing statements in testMissingSaltAndIteration. The line you quoted is within another test, so most likely not :)

Yes this test is specifically for the method testMissingSaltAndIteration. IIRC we have other jira issues that address this in other methods

Copy link
Contributor

@ashley-abdelsayed98 ashley-abdelsayed98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the changes @nidhiazad !

assertTrue("Message about invalid salt parameter must be present", retValLines[0].contains("Invalid \"salt\" parameter. Generated value"));
assertTrue("Message about invalid iteration parameter must be present", ("Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.").equals(retValLines[1]));
assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Message about invalid salt parameter must be present","Invalid \"salt\" parameter. Generated value", retValLines[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this test will still fail because retValLines[0] does not equal "Invalid \"salt\" parameter. Generated value", but rather it just contains it as a substring

assertTrue("Message about invalid salt parameter must be present", retValLines[2].contains("MASK-"));
assertEquals("Message about invalid salt parameter must be present","Invalid \"salt\" parameter. Generated value", retValLines[0]);
assertEquals("Message about invalid iteration parameter must be present","Invalid \"iteration\" parameter. Default value \"" + defaultIteration + "\" will be used.",retValLines[1]);
assertEquals("Message about invalid salt parameter must be present","MASK-",retValLines[2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, i think this test will fail because retValLines[2] does not equal "MASK-", but rather it just contains it as a substring

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have submitted the new changes and verified by running mvn clean install -Dtest=MaskCommandTest. The test is passing now.

@Skyllarr
Copy link
Contributor

Skyllarr commented Sep 22, 2023

@nidhiazad Just a minor, in the testMissingSaltAndIteration is a single assertTrue that can be updated to use assertEquals easily.
The methods that use assertTrue(object1.equals(object2)) can be updated to use assertEquals(object1, object2). The other 2 assertions use the contains() method. The values in the contains methods are not written in full, so the assertEquals cannot be used there as @ashley-abdelsayed98 explained above.

You can try to run the project with mvn clean install and you will see that this test will not pass. Alternatively, you can change to the tool subdirectory of the project and run mvn clean install -Dtest=MaskCommandTest#testMissingSaltAndIteration which will run only this single test .

Copy link
Contributor

@SoniaZaldana SoniaZaldana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nidhiazad, thanks for the changes. They look good!

Could you please squash your commits? Let me know if you need any help with that.

@Skyllarr
Copy link
Contributor

@nidhiazad The changes look great now! It just need squashing of the commits into a single commit. If you need any help, please let us know

@nidhiazad nidhiazad force-pushed the feature/ELY-2641_OSD_Nidhi_Azad branch from 3d0d312 to b9bf6dc Compare September 22, 2023 21:59
Copy link
Contributor

@ashley-abdelsayed98 ashley-abdelsayed98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @nidhiazad!

@Skyllarr Skyllarr merged commit 174424c into wildfly-security:2.x Sep 22, 2023
3 checks passed
@Skyllarr
Copy link
Contributor

@nidhiazad Thank you!

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.

5 participants