|
|
|
|
@ -10,7 +10,6 @@ import static org.mockito.Mockito.never; |
|
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.Reader; |
|
|
|
|
import java.io.StringReader; |
|
|
|
|
@ -27,9 +26,6 @@ import java.util.stream.Collectors; |
|
|
|
|
import org.hamcrest.Matchers; |
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
|
|
import de.kreth.property2java.processor.Format; |
|
|
|
|
|
|
|
|
|
class GeneratorTests { |
|
|
|
|
|
|
|
|
|
@ -44,9 +40,7 @@ class GeneratorTests { |
|
|
|
|
Map<String, Reader> input = new HashMap<>(); |
|
|
|
|
input.put(path, testProperties()); |
|
|
|
|
|
|
|
|
|
config = Mockito.spy(TestImplConfig.class); |
|
|
|
|
when(config.getRootPath()).thenReturn(new File(".").toPath()); |
|
|
|
|
when(config.getFormat()).thenReturn(Format.WithInitializer); |
|
|
|
|
config = mock(Configuration.class); |
|
|
|
|
when(config.getInput()).thenReturn(input); |
|
|
|
|
when(config.mapFilenameToClassName(anyString())).thenCallRealMethod(); |
|
|
|
|
when(config.outputCharset()).thenCallRealMethod(); |
|
|
|
|
@ -119,19 +113,23 @@ class GeneratorTests { |
|
|
|
|
when(config.outWriter(anyString())).thenReturn(out); |
|
|
|
|
generator.start(); |
|
|
|
|
|
|
|
|
|
List<String> lines = out.toString().lines().filter(line -> line.contains(" (\"")).collect(Collectors.toList()); |
|
|
|
|
List<String> lines = out.toString().lines().filter(line -> line.contains(" (\"")) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
assertEquals(21, lines.size()); |
|
|
|
|
assertLineMatch(lines, "label", "label"); |
|
|
|
|
assertLineMatch(lines, "label_addarticle", "label.addarticle"); |
|
|
|
|
assertLineMatch(lines, "label_user_register", "label.user.register"); |
|
|
|
|
assertLineMatch(lines, "message_article_priceerror", "message.article.priceerror"); |
|
|
|
|
assertLineMatch(lines, "message_invoiceitem_startbeforeend", "message.invoiceitem.startbeforeend"); |
|
|
|
|
assertLineMatch(lines, "message_invoiceitem_allfieldsmustbeset", "message.invoiceitem.allfieldsmustbeset"); |
|
|
|
|
assertLineMatch(lines, "message_invoiceitem_startbeforeend", |
|
|
|
|
"message.invoiceitem.startbeforeend"); |
|
|
|
|
assertLineMatch(lines, "message_invoiceitem_allfieldsmustbeset", |
|
|
|
|
"message.invoiceitem.allfieldsmustbeset"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertLineMatch(List<String> lines, String key, String expected) { |
|
|
|
|
Optional<String> found = lines.stream().filter(line -> keyMatches(line, key)).findFirst(); |
|
|
|
|
Optional<String> found = lines.stream().filter(line -> keyMatches(line, key)) |
|
|
|
|
.findFirst(); |
|
|
|
|
|
|
|
|
|
assertTrue(found.isPresent(), "No line found with key = " + key); |
|
|
|
|
final String line = found.get().trim(); |
|
|
|
|
@ -149,21 +147,31 @@ class GeneratorTests { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private StringReader testProperties() { |
|
|
|
|
return new StringReader("\r\n" + "label = \r\n" + "\r\n" + "label.addarticle = Add Article\r\n" |
|
|
|
|
+ "label.cancel = Cancel\r\n" + "label.close = Close\r\n" |
|
|
|
|
+ "label.delete = Delete\r\n" + "label.discart = Discart\r\n" |
|
|
|
|
+ "label.loggedin = Logged in:\r\n" + "label.logout = Logout\r\n" |
|
|
|
|
+ "label.ok = OK\r\n" + "label.store = Store\r\n" |
|
|
|
|
+ "label.preview = Preview\r\n" + "label.open = Open\r\n" |
|
|
|
|
+ "label.user.register = Register\r\n" + "\r\n" |
|
|
|
|
+ "message.article.priceerror = Please set the price.\r\n" |
|
|
|
|
+ "message.delete.text = Delete {0}?\r\n" |
|
|
|
|
+ "message.delete.title = Really delete?\r\n" |
|
|
|
|
+ "message.invoiceitem.allfieldsmustbeset = Start, end and article must not be \\r\\n" |
|
|
|
|
+ " empty!\r\n" |
|
|
|
|
+ "message.invoiceitem.startbeforeend = End must be later than start.\r\n" |
|
|
|
|
+ "message.user.create.success = Thanks {0} created!\r\n" |
|
|
|
|
+ "message.user.loginfailure = Login Error! Wrong user or password?\r\n" |
|
|
|
|
+ "message.user.passwordmissmatch = Passwords don't match.\r\n" + ""); |
|
|
|
|
return new StringReader("\r\n" + |
|
|
|
|
"label = \r\n" + |
|
|
|
|
"\r\n" + |
|
|
|
|
"label.addarticle = Add Article\r\n" + |
|
|
|
|
"label.cancel = Cancel\r\n" + |
|
|
|
|
"label.close = Close\r\n" + |
|
|
|
|
"label.delete = Delete\r\n" + |
|
|
|
|
"label.discart = Discart\r\n" + |
|
|
|
|
"label.loggedin = Logged in:\r\n" + |
|
|
|
|
"label.logout = Logout\r\n" + |
|
|
|
|
"label.ok = OK\r\n" + |
|
|
|
|
"label.store = Store\r\n" + |
|
|
|
|
"label.preview = Preview\r\n" + |
|
|
|
|
"label.open = Open\r\n" + |
|
|
|
|
"label.user.register = Register\r\n" + |
|
|
|
|
"\r\n" + |
|
|
|
|
"message.article.priceerror = Please set the price.\r\n" + |
|
|
|
|
"message.delete.text = Delete {0}?\r\n" + |
|
|
|
|
"message.delete.title = Really delete?\r\n" + |
|
|
|
|
"message.invoiceitem.allfieldsmustbeset = Start, end and article must not be \\r\\n" + |
|
|
|
|
" empty!\r\n" + |
|
|
|
|
"message.invoiceitem.startbeforeend = End must be later than start.\r\n" + |
|
|
|
|
"message.user.create.success = Thanks {0} created!\r\n" + |
|
|
|
|
"message.user.loginfailure = Login Error! Wrong user or password?\r\n" + |
|
|
|
|
"message.user.passwordmissmatch = Passwords don't match.\r\n" + |
|
|
|
|
""); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|