mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Add localization option for template engines
This commit is contained in:
@@ -97,6 +97,11 @@ public class MustacheTemplateEngineTest extends TemplateEngineTestBase
|
||||
return "sonia/scm/template/001.mustache";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateResourceWithGermanTranslation() {
|
||||
return "sonia/scm/template/loc.mustache";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -37,6 +37,7 @@ package sonia.scm.template;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -52,6 +53,7 @@ import java.io.StringWriter;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -92,6 +94,8 @@ public abstract class TemplateEngineTestBase
|
||||
*/
|
||||
public abstract String getTemplateResource();
|
||||
|
||||
public abstract String getTemplateResourceWithGermanTranslation();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -126,7 +130,7 @@ public abstract class TemplateEngineTestBase
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void testGetTemlateNotFound() throws IOException
|
||||
public void testGetTemplateNotFound() throws IOException
|
||||
{
|
||||
ServletContext context = mock(ServletContext.class);
|
||||
TemplateEngine engine = createEngine(context);
|
||||
@@ -151,6 +155,32 @@ public abstract class TemplateEngineTestBase
|
||||
assertNotNull(engine.getTemplate(getTemplateResource()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTemplateFromClasspathWithExistingLocale() throws IOException
|
||||
{
|
||||
ServletContext context = mock(ServletContext.class);
|
||||
|
||||
TemplateEngine engine = createEngine(context);
|
||||
|
||||
Template template = engine.getTemplate(getTemplateResourceWithGermanTranslation(), Locale.GERMAN);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.execute(writer, new Object());
|
||||
Assertions.assertThat(writer.toString()).contains("German");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTemplateFromClasspathWithNotExistingLocale() throws IOException
|
||||
{
|
||||
ServletContext context = mock(ServletContext.class);
|
||||
|
||||
TemplateEngine engine = createEngine(context);
|
||||
|
||||
Template template = engine.getTemplate(getTemplateResourceWithGermanTranslation(), Locale.CHINESE);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.execute(writer, new Object());
|
||||
Assertions.assertThat(writer.toString()).contains("English");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user