Skip to content

Commit d465d0c

Browse files
committed
Complete LocalizationManagerTests, fixed resource files, extracted ILocalizationModule
1 parent 57e3a7b commit d465d0c

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/main/java/aquality/selenium/core/localization/ILocalizationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public interface ILocalizationManager {
77
/**
8-
* Get localized message from resources by its key.
8+
* Gets localized message from resources by its key.
99
* @param messageKey Key in resource file.
1010
* @param args Arguments, which will be provided to template of localized message.
1111
* @return Localized message.

src/main/java/aquality/selenium/core/localization/ILocalizationModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package aquality.selenium.core.localization;
22

3+
/**
4+
* Describes implementations of localization services to be registered in DI container.
5+
*/
36
public interface ILocalizationModule {
7+
/**
8+
* @return class which implements ILocalizationManager
9+
*/
410
default Class<? extends ILocalizationManager> getLocalizationManagerImplementation() {
511
return LocalizationManager.class;
612
}
713

14+
/**
15+
* @return class which implements ILocalizedLogger
16+
*/
817
default Class<? extends ILocalizedLogger> getLocalizedLoggerImplementation() {
918
return LocalizedLogger.class;
1019
}

src/main/java/aquality/selenium/core/localization/LocalizationManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ public class LocalizationManager implements ILocalizationManager {
1010
private static final String LANG_RESOURCE_TEMPLATE = "localization/%1$s.json";
1111
private final ISettingsFile localizationFile;
1212
private final Logger logger;
13+
private final String locResourceName;
1314

1415
@Inject
1516
public LocalizationManager(ILoggerConfiguration loggerConfiguration, Logger logger) {
1617
this.logger = logger;
1718
String language = loggerConfiguration.getLanguage();
18-
String locResourceName = String.format(LANG_RESOURCE_TEMPLATE, language.toLowerCase());
19+
locResourceName = String.format(LANG_RESOURCE_TEMPLATE, language.toLowerCase());
1920
localizationFile = new JsonSettingsFile(locResourceName);
2021
}
2122

@@ -26,7 +27,8 @@ public String getLocalizedMessage(String messageKey, Object... args) {
2627
return String.format(localizationFile.getValue(jsonKeyPath).toString(), args);
2728
}
2829

29-
logger.warn(String.format("Cannot find localized message by key '%1$s'", jsonKeyPath));
30+
logger.warn(String.format("Cannot find localized message by key '%1$s' in resource file %2$s",
31+
jsonKeyPath, locResourceName));
3032
return messageKey;
3133
}
3234
}

src/main/java/aquality/selenium/core/localization/LocalizedLogger.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class LocalizedLogger implements ILocalizedLogger {
1010

1111
@Inject
1212
public LocalizedLogger(ILocalizationManager localizationManager, Logger logger) {
13-
1413
this.localizationManager = localizationManager;
1514
this.logger = logger;
1615
}

src/test/java/tests/localization/LocalizationManagerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.testng.annotations.DataProvider;
99
import org.testng.annotations.Test;
1010
import tests.application.CustomAqualityServices;
11+
import tests.application.browser.AqualityServices;
1112

1213
import java.util.MissingFormatArgumentException;
1314

@@ -39,7 +40,7 @@ private Object[] keysWithoutParams() {
3940

4041
private LocalizationManager getLocalizationManager() {
4142
return new LocalizationManager(
42-
CustomAqualityServices.getServiceProvider().getInstance(ILoggerConfiguration.class),
43+
AqualityServices.getServiceProvider().getInstance(ILoggerConfiguration.class),
4344
Logger.getInstance());
4445
}
4546

@@ -110,5 +111,4 @@ public void testShouldThrowWhenInvalidLanguageSupplied() {
110111
Assert.assertThrows(IllegalArgumentException.class, () ->
111112
getLocalizationManager("invalid").getLocalizedMessage(CLICKING_MESSAGE_KEY));
112113
}
113-
114114
}

0 commit comments

Comments
 (0)