-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...rchus-core/src/test/java/org/hipparchus/exception/IntentionallyIncompleteLocalizable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Hipparchus project under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The Hipparchus project licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hipparchus.exception; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Intentionally incomplete localizable, for testing purposes | ||
* @author Luc Maisonobe | ||
*/ | ||
enum IntentionallyIncompleteLocalizable implements Localizable | ||
{ | ||
MESSAGE_WITHOUT_ARGUMENT("message without argument"), | ||
|
||
MESSAGE_WITH_ONE_ARGUMENT("message with one argument {0}"), | ||
|
||
MESSAGE_WITH_TWO_ARGUMENTS("message with two arguments {0}, {1}"); | ||
|
||
/** | ||
* Simple constructor. | ||
* @param sourceFormat source English format to use when no | ||
* localized version is available | ||
*/ | ||
IntentionallyIncompleteLocalizable(final String sourceFormat) | ||
{ | ||
this.sourceFormat = sourceFormat; | ||
} | ||
|
||
/** Source English format. */ | ||
private final String sourceFormat; | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public String getSourceString() | ||
{ | ||
return sourceFormat; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public String getLocalizedString(final Locale locale) | ||
{ | ||
return getLocalizedString("assets/" + IntentionallyIncompleteLocalizable.class.getName().replaceAll("\\.", "/"), | ||
name(), locale); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...s-core/src/test/java/org/hipparchus/exception/IntentionallyIncompleteLocalizableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Hipparchus project under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The Hipparchus project licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hipparchus.exception; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Intentionally incomplete localizable, for testing purposes | ||
* @author Luc Maisonobe | ||
*/ | ||
public class IntentionallyIncompleteLocalizableTest | ||
{ | ||
@Test | ||
public void testFixedLocale() { | ||
Assertions.assertEquals("message without argument", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITHOUT_ARGUMENT.getLocalizedString(Locale.ENGLISH)); | ||
Assertions.assertEquals("message with one argument {0}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_ONE_ARGUMENT.getLocalizedString(Locale.ENGLISH)); | ||
Assertions.assertEquals("message with two arguments {0}, {1}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_TWO_ARGUMENTS.getLocalizedString(Locale.ENGLISH)); | ||
} | ||
|
||
@Test | ||
public void testUnsupportedLocale() { | ||
Assertions.assertEquals("message without argument", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITHOUT_ARGUMENT.getLocalizedString(Locale.TRADITIONAL_CHINESE)); | ||
Assertions.assertEquals("message with one argument {0}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_ONE_ARGUMENT.getLocalizedString(Locale.TRADITIONAL_CHINESE)); | ||
Assertions.assertEquals("message with two arguments {0}, {1}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_TWO_ARGUMENTS.getLocalizedString(Locale.TRADITIONAL_CHINESE)); | ||
} | ||
|
||
@Test | ||
public void testIncompleteTranslations() { | ||
Assertions.assertEquals("message sans argument", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITHOUT_ARGUMENT.getLocalizedString(Locale.FRENCH)); | ||
Assertions.assertEquals("message with one argument {0}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_ONE_ARGUMENT.getLocalizedString(Locale.FRENCH)); | ||
Assertions.assertEquals("message with two arguments {0}, {1}", | ||
IntentionallyIncompleteLocalizable.MESSAGE_WITH_TWO_ARGUMENTS.getLocalizedString(Locale.FRENCH)); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...test/resources/assets/org/hipparchus/exception/IntentionallyIncompleteLocalizable_en.utf8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MESSAGE_WITHOUT_ARGUMENT = message without argument | ||
MESSAGE_WITH_ONE_ARGUMENT = message with one argument {0} | ||
MESSAGE_WITH_TWO_ARGUMENTS = message with two arguments {0}, {1} |
3 changes: 3 additions & 0 deletions
3
...test/resources/assets/org/hipparchus/exception/IntentionallyIncompleteLocalizable_fr.utf8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MESSAGE_WITHOUT_ARGUMENT = message sans argument | ||
MESSAGE_WITH_ONE_ARGUMENT = <MISSING TRANSLATION> | ||
MESSAGE_WITH_TWO_ARGUMENTS = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters