Skip to content

Commit

Permalink
JUnit test for #344
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Apr 20, 2021
1 parent 9323229 commit 42dd3db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/tech/units/indriya/format/SimpleUnitFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* @author <a href="mailto:werner@units.tech">Werner Keil</a>
* @author Eric Russell
* @author Andi Huber
* @version 2.7, Apr. 19, 2021
* @version 2.8, Apr. 20, 2021
* @since 1.0
*/
public abstract class SimpleUnitFormat extends AbstractUnitFormat {
Expand Down Expand Up @@ -114,10 +114,10 @@ public static enum Flavor {


/**
* Returns the unit format for the default locale (format used by {@link AbstractUnit#parse(CharSequence) AbstractUnit.parse(CharSequence)} and
* {@link Unit#toString() Unit.toString()}).
* Returns the globally shared unit format instance (used by {@link AbstractUnit#parse(CharSequence) AbstractUnit.parse()} and
* {@link AbstractUnit#toString() AbstractUnit.toString()}).
*
* @return the default unit format (locale sensitive).
* @return the default unit format.
*/
public static SimpleUnitFormat getInstance() {
return getInstance(Flavor.Default);
Expand All @@ -138,10 +138,10 @@ public static SimpleUnitFormat getInstance(Flavor flavor) {
}

/**
* Similar to {@link #getInstance()}, but returns a new unit format instance for the default locale,
* Similar to {@link #getInstance()}, but returns a new, non-shared unit format instance,
* instead of a shared singleton instance.
*
* @return a new instance of the default unit format (locale sensitive).
* @return a new instance of the default unit format.
* @see #getInstance()
*/
public static SimpleUnitFormat getNewInstance() {
Expand Down Expand Up @@ -314,7 +314,7 @@ public Exponent(int pow, int root) {
}

/**
* This class represents the standard format.
* This class represents the default (Unicode) format.
* @deprecated internal class, that will be made private soon, please extend either SimpleUnitFormat or AbstractUnitFormat
*/
protected static class DefaultFormat extends SimpleUnitFormat {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/tech/units/indriya/format/SimpleUnitFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,20 @@ public void testParseMonth() {
logger.log(LOG_LEVEL, format.format(MONTH));
assertEquals(MONTH, format.parse("mo"));
}


@Test
public void testFormatNewInstance() {
logger.log(LOG_LEVEL, "Candela (shared format): " + format.format(CANDELA));
assertEquals("cd", format.format(CANDELA));

logger.log(LOG_LEVEL, "Now we retrieve a new format instance");
final UnitFormat newFormat = SimpleUnitFormat.getNewInstance();
newFormat.label(CANDELA, "kd");
// The shared format and toString() based on it are unaffected
assertEquals("cd", format.format(CANDELA));
assertEquals("cd", CANDELA.toString());
// Only the new format got the label
assertEquals("kd", newFormat.format(CANDELA));
}
}

0 comments on commit 42dd3db

Please sign in to comment.