Skip to content

Commit 438f970

Browse files
author
dave
committed
#436 test coverage
1 parent 7655463 commit 438f970

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

.idea/runConfigurations/TcMenuDesigner_Tests.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/ejava/EmbeddedJavaGenerator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.nio.file.Files;
2121
import java.nio.file.Path;
22+
import java.nio.file.StandardCopyOption;
2223
import java.util.Collection;
2324
import java.util.Comparator;
2425
import java.util.List;
@@ -93,7 +94,7 @@ public boolean startConversion(Path directory, List<CodePluginItem> plugins, Men
9394
options.getSaveLocation(), previousPluginFiles);
9495

9596
if(handler.isLocalSupportEnabled()) {
96-
copyLocaleDataIntoProject();
97+
copyLocaleDataIntoProject(javaProject);
9798
}
9899

99100
logLine(INFO, "Checking if all dependencies are in the maven POM");
@@ -110,8 +111,10 @@ public boolean startConversion(Path directory, List<CodePluginItem> plugins, Men
110111
return false;
111112
}
112113

113-
private void copyLocaleDataIntoProject() {
114-
114+
private void copyLocaleDataIntoProject(EmbeddedJavaProject javaProject) throws IOException {
115+
loggerDelegate.accept(INFO, "Copying resource bundles to data/i18n directory");
116+
Files.copy(javaProject.getProjectRoot().resolve("i18n"), javaProject.getProjectRoot().resolve("data"),
117+
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
115118
}
116119

117120
private void createJavaModuleFile(CodeGeneratorOptions options, EmbeddedJavaProject javaProject) throws IOException {
@@ -238,7 +241,7 @@ private void generateMenuAppContext(EmbeddedJavaProject javaProject, String claz
238241
if(handler.isLocalSupportEnabled()) {
239242
builder.addStatement(new GeneratedJavaMethod(METHOD_IF_MISSING, "LocaleMappingHandler", "localeHandler")
240243
.withTcComponent()
241-
.withStatement("return new ResourceBundleMappingHandler(ResourceBundle.getBundle(\"i18n." + MENU_PROJECT_LANG_FILENAME+ "\"));"));
244+
.withStatement("return new PropertiesLocaleEnabledHandler(new SafeBundleLoader(\"./data/i18n/" + MENU_PROJECT_LANG_FILENAME+ "\"));"));
242245
} else {
243246
builder.addStatement(new GeneratedJavaMethod(METHOD_IF_MISSING, "LocaleMappingHandler", "localeHandler")
244247
.withTcComponent().withStatement("return LocaleMappingHandler.NOOP_IMPLEMENTATION;"));

tcMenuGenerator/src/test/java/com/thecoderscorner/menu/editorui/generator/mbed/MbedGeneratorTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.IOException;
3737
import java.nio.file.Files;
3838
import java.nio.file.Path;
39-
import java.nio.file.Paths;
4039
import java.util.Comparator;
4140
import java.util.List;
4241
import java.util.Objects;
@@ -140,6 +139,9 @@ public void testMbedConversion() throws IOException {
140139
var pluginGeneratedH = new String(Files.readAllBytes(generatedDir.resolve("source.h")));
141140
var pluginGeneratedCPP = new String(Files.readAllBytes(generatedDir.resolve("source.cpp")));
142141
var pluginGeneratedTransport = new String(Files.readAllBytes(generatedDir.resolve("MySpecialTransport.h")));
142+
var langSelectHeader = Files.readString(generatedDir.resolve("project_langSelect.h"));
143+
var langCoreHeader = Files.readString(generatedDir.resolve("project_lang.h"));
144+
var langFrHeader = Files.readString(generatedDir.resolve("project_lang_fr.h"));
143145

144146
var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.cpp")).readAllBytes());
145147
var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.h")).readAllBytes());
@@ -157,6 +159,37 @@ public void testMbedConversion() throws IOException {
157159
My Transport file
158160
#define THE_SERIAL Serial
159161
""", pluginGeneratedTransport);
162+
assertEqualsIgnoringCRLF("""
163+
// TcMenu Generated Locale File, do not edit this file.
164+
// This is the header to include. Set TC_LOCAL_?? to a locale
165+
// or omit for the default language
166+
167+
#if defined(TC_LOCALE_FR)
168+
# include "project_lang_fr.h"
169+
#else
170+
#include "project_lang.h"
171+
#endif
172+
""", langSelectHeader);
173+
assertEqualsIgnoringCRLF("""
174+
// TcMenu Generated Locale File, do not edit this file. Locale\s
175+
// Never include directly, always include the langSelect header
176+
177+
#define TC_I18N_MENU_10003_NAME "Analog Ram Def"
178+
#define TC_I18N_MENU_10002_NAME "IoT Def Text"
179+
#define TC_I18N_MENU_10003_UNIT "De"
180+
#define TC_I18N_MENU_10004_NAME "Text Edit Def"
181+
#define TC_I18N_MENU_10001_NAME "Auth Def Text"
182+
""", langCoreHeader);
183+
assertEqualsIgnoringCRLF("""
184+
// TcMenu Generated Locale File, do not edit this file. Locale fr
185+
// Never include directly, always include the langSelect header
186+
187+
#define TC_I18N_MENU_10003_NAME "Analog Ram Fr"
188+
#define TC_I18N_MENU_10002_NAME "IoT Fr Text"
189+
#define TC_I18N_MENU_10003_UNIT "Fr"
190+
#define TC_I18N_MENU_10004_NAME "Text Edit"
191+
#define TC_I18N_MENU_10001_NAME "Auth Fr Text"
192+
""", langFrHeader);
160193
}
161194

162195
private void putLocaleFilesInPlace(Path i18n) throws IOException {

0 commit comments

Comments
 (0)