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

8310923: Refactor Currency tests to use JUnit #14682

Closed

Conversation

justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Jun 27, 2023

Please review this PR which refactors Currency tests to use JUnit.

The most significant change occurs in ValidateISO4217.java. Other changes to this file excluding the JUnit refactoring include

  • Tests are no longer dependent on each other (order of execution does not matter)
  • Testing does not occur at the same time as data generation (The data is fully generated before any tests are executed)
  • Various cleanup (dead-code, clarifying comments, more descriptive method and var names)

Bug4512215.java now renamed to MinorUndefinedCodes was updated to remove redundant testing, and the file changed to focus on testing minor undefined currency codes instead.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8310923: Refactor Currency tests to use JUnit (Sub-task - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14682/head:pull/14682
$ git checkout pull/14682

Update a local copy of the PR:
$ git checkout pull/14682
$ git pull https://git.openjdk.org/jdk.git pull/14682/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14682

View PR using the GUI difftool:
$ git pr show -t 14682

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14682.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 27, 2023

👋 Welcome back jlu! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 27, 2023

@justin-curtis-lu The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Jun 27, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 27, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 27, 2023

Webrevs


import static org.junit.jupiter.api.Assertions.assertThrows;

public class CurrencyNameProviderTest {
Copy link
Member

Choose a reason for hiding this comment

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

Since this is not a generic CurrencyNameProvider test, but specific to the default impl of CNP.getDisplayName(), the class name could be more specific.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have renamed the file to be more descriptive, but if acronyms are not preferred in file names, I can rename it.

Currency currency1 = Currency.getInstance(currencyCode);
Currency currency2 = Currency.getInstance(currencyCode);
assertEquals(currency1, currency2, "Didn't get same instance for same currency code");
assertEquals(currency1.getCurrencyCode(), currencyCode, "Currency code changed");
Copy link
Member

Choose a reason for hiding this comment

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

Error message more like "wrong currency code", than "changed"

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the err msg

Arguments.of("BHD", 3), Arguments.of("IQD", 3),
Arguments.of("JOD", 3), Arguments.of("KWD", 3),
Arguments.of("LYD", 3), Arguments.of("OMR", 3),
Arguments.of("TND", 3), Arguments.of("TRL", 0), // Turkish Lira
Copy link
Member

Choose a reason for hiding this comment

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

The turkish lira comment should apply to both TRL and TRY

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good point, I have clarified the comment

if (!currency1.getCurrencyCode().equals(currencyCode)) {
throw new RuntimeException("Currency code changed");

// Calling getInstance() with an illegal name should throw an IAE
Copy link
Member

Choose a reason for hiding this comment

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

illegal name -> invalid currency code

/*
* @test
* @bug 4512215 4818420 4819436 8310923
* @summary Test some minor undefined currencies.
Copy link
Member

Choose a reason for hiding this comment

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

It'd be more readable something like "currencies without minor units." The class name can also be renamed to something like NoMinorUnitCurrenciesTest

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted the wording throughout the file according to your suggestions

// at the same time
setUpISO4217Codes();
setUpAdditionalCodes();
finishTestCurrencies();
Copy link
Member

@naotoj naotoj Jun 29, 2023

Choose a reason for hiding this comment

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

The method name finish is kind of confusing. I'd explicitly describe what the method does, i.e, setup other currencies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed it to your suggestion

Comment on lines 172 to 192
String[][] extraCodes = {
/* Defined in ISO 4217 list, but don't have code and minor unit info. */
{"AQ", "", "", "0"}, // Antarctica
/*
* Defined in ISO 4217 list, but don't have code and minor unit info in
* it. On the other hand, both code and minor unit are defined in
* .properties file. I don't know why, though.
*/
{"GS", "GBP", "826", "2"}, // South Georgia And The South Sandwich Islands
/* Not defined in ISO 4217 list, but defined in .properties file. */
{"AX", "EUR", "978", "2"}, // \u00c5LAND ISLANDS
{"PS", "ILS", "376", "2"}, // Palestinian Territory, Occupied
/* Not defined in ISO 4217 list, but added in ISO 3166 country code list */
{"JE", "GBP", "826", "2"}, // Jersey
{"GG", "GBP", "826", "2"}, // Guernsey
{"IM", "GBP", "826", "2"}, // Isle of Man
{"BL", "EUR", "978", "2"}, // Saint Barthelemy
{"MF", "EUR", "978", "2"}, // Saint Martin
/* Defined neither in ISO 4217 nor ISO 3166 list */
{"XK", "EUR", "978", "2"}, // Kosovo
};
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer this array to be placed as static in the class, not within the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, as well as for otherCodes

Comment on lines 209 to 214
final String otherCodes =
"ADP-AFA-ATS-AYM-AZM-BEF-BGL-BOV-BYB-BYR-CHE-CHW-CLF-COU-CUC-CYP-"
+ "DEM-EEK-ESP-FIM-FRF-GHC-GRD-GWP-IEP-ITL-LTL-LUF-LVL-MGF-MRO-MTL-MXV-MZM-NLG-"
+ "PTE-ROL-RUR-SDD-SIT-SLL-SKK-SRG-STD-TMM-TPE-TRL-VEF-UYI-USN-USS-VEB-VED-"
+ "XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XSU-XTS-XUA-XXX-"
+ "YUM-ZMK-ZWD-ZWN-ZWR";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto as extraCodes

private static final byte[] codes = new byte[ALPHA_NUM * ALPHA_NUM];
// Codes derived from ISO4217 golden-data file
private static final List<Arguments> ISO4217Codes = new ArrayList<Arguments>();
// Additional codes not from the ISO4217 golden-data file
Copy link
Member

Choose a reason for hiding this comment

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

Are these from the golden file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless I am misinterpreting the question, additionalCodes is built from the extraCodes array, which contains data that is not found in tablea1.txt(golden file)

Comment on lines 241 to 243
// Old and New Turkish Lira
Arguments.of("TRL", 0), Arguments.of("TRY", 2),
Arguments.of("TND", 3)
Copy link
Member

Choose a reason for hiding this comment

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

Probably TND moving upward before the comment would be clearer, like:

                Arguments.of("LYD", 3), Arguments.of("OMR", 3),
                Arguments.of("TND", 3),

                // Old and New Turkish Lira
                Arguments.of("TRL", 0), Arguments.of("TRY", 2)

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted TND upwards

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the refactoring

@openjdk
Copy link

openjdk bot commented Jun 30, 2023

@justin-curtis-lu This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8310923: Refactor Currency tests to use JUnit

Reviewed-by: naoto, lancea

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 77 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 30, 2023
@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 7, 2023

Going to push as commit e848d94.
Since your change was applied there have been 124 commits pushed to the master branch:

  • 0c86c31: 8302351: "assert(!JavaThread::current()->is_interp_only_mode() || !nm->method()->is_continuation_enter_intrinsic() || ContinuationEntry::is_interpreted_call(return_pc)) failed: interp_only_mode but not in enterSpecial interpreted entry" in fixup_callers_callsite
  • ec7da91: 8240567: MethodTooLargeException thrown while creating a jlink image
  • 97e99f0: 8311087: PhiNode::wait_for_region_igvn should break early
  • 7173c30: 8307766: Linux: Provide the option to override the timer slack
  • 356067d: 8311489: Remove unused dirent_md files
  • 3d813ae: 8311301: MethodExitTest may fail with stack buffer overrun
  • 0741cd3: 8311264: JavaDoc index comparator is not transitive
  • edb2be1: 8311279: TestStressIGVNAndCCP.java failed with different IGVN traces for the same seed
  • d072c40: 8311183: Remove unused mapping test files
  • 66d2736: 8307526: [JFR] Better handling of tampered JFR repository
  • ... and 114 more: https://git.openjdk.org/jdk/compare/7db2f08756b0aa1d79cdd2356ed42aa5ab8bc58b...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 7, 2023
@openjdk openjdk bot closed this Jul 7, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 7, 2023
@openjdk
Copy link

openjdk bot commented Jul 7, 2023

@justin-curtis-lu Pushed as commit e848d94.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
3 participants