use of org.xwiki.localization.LocalizationManager in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
Mockery mockery = new JUnit4Mockery();
final LocalizationManager localizationManager = componentManager.registerMockComponent(mockery, LocalizationManager.class);
final LocalizationContext localizationContext = componentManager.registerMockComponent(mockery, LocalizationContext.class);
mockery.checking(new Expectations() {
{
allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH);
will(returnValue(new Translation() {
@Override
public Block render(Locale locale, Object... parameters) {
return parameters.length > 0 ? new WordBlock("entranslationmessage" + Arrays.toString(parameters)) : new WordBlock("entranslationmessage");
}
@Override
public Block render(Object... parameters) {
return render(null, parameters);
}
@Override
public String getRawSource() {
return "entranslationmessagesource";
}
@Override
public Locale getLocale() {
return Locale.ENGLISH;
}
@Override
public String getKey() {
return "some.translation";
}
@Override
public TranslationBundle getBundle() {
return null;
}
}));
allowing(localizationManager).getTranslation("some.translation", Locale.FRENCH);
will(returnValue(new Translation() {
@Override
public Block render(Locale locale, Object... parameters) {
return parameters.length > 0 ? new WordBlock("frtranslationmessage" + Arrays.toString(parameters)) : new WordBlock("frtranslationmessage");
}
@Override
public Block render(Object... parameters) {
return render(null, parameters);
}
@Override
public String getRawSource() {
return "frtranslationmessagesource";
}
@Override
public Locale getLocale() {
return Locale.FRENCH;
}
@Override
public String getKey() {
return "some.translation";
}
@Override
public TranslationBundle getBundle() {
return null;
}
}));
allowing(localizationManager).getTranslation("unexisting.translation", Locale.ENGLISH);
will(returnValue(null));
allowing(localizationContext).getCurrentLocale();
will(returnValue(Locale.ENGLISH));
}
});
}
use of org.xwiki.localization.LocalizationManager in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
Aggregations