| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.localization.script; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
import java.util.Locale; |
| 24 |
|
|
| 25 |
|
import javax.inject.Provider; |
| 26 |
|
|
| 27 |
|
import org.apache.commons.lang3.ArrayUtils; |
| 28 |
|
import org.jmock.Expectations; |
| 29 |
|
import org.jmock.api.Invocation; |
| 30 |
|
import org.jmock.lib.action.CustomAction; |
| 31 |
|
import org.junit.Assert; |
| 32 |
|
import org.junit.Test; |
| 33 |
|
import org.xwiki.component.internal.ContextComponentManagerProvider; |
| 34 |
|
import org.xwiki.localization.LocalizationContext; |
| 35 |
|
import org.xwiki.localization.LocalizationManager; |
| 36 |
|
import org.xwiki.localization.Translation; |
| 37 |
|
import org.xwiki.rendering.block.WordBlock; |
| 38 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
| 39 |
|
import org.xwiki.rendering.renderer.printer.WikiPrinter; |
| 40 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 41 |
|
import org.xwiki.test.annotation.ComponentList; |
| 42 |
|
import org.xwiki.test.jmock.AbstractMockingComponentTestCase; |
| 43 |
|
import org.xwiki.test.jmock.annotation.MockingRequirement; |
| 44 |
|
|
| 45 |
|
@MockingRequirement(value = LocalizationScriptService.class, exceptions = {Provider.class}) |
| 46 |
|
@ComponentList({ContextComponentManagerProvider.class}) |
| |
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 9 |
Complexity Density: 0.31 |
|
| 47 |
|
public class LocalizationScriptServiceTest extends AbstractMockingComponentTestCase<LocalizationScriptService> |
| 48 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 49 |
4 |
public void prepareRenderTest() throws Exception... |
| 50 |
|
{ |
| 51 |
4 |
final BlockRenderer renderer = registerMockComponent(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString()); |
| 52 |
|
|
| 53 |
4 |
final LocalizationManager localizationManager = getComponentManager().getInstance(LocalizationManager.class); |
| 54 |
4 |
final LocalizationContext localizationContext = getComponentManager().getInstance(LocalizationContext.class); |
| 55 |
4 |
final Translation translation = getMockery().mock(Translation.class); |
| 56 |
4 |
getMockery().checking(new Expectations() |
| 57 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 58 |
4 |
{... |
| 59 |
4 |
oneOf(renderer).render(with(equal(new WordBlock("message"))), with(any(WikiPrinter.class))); |
| 60 |
4 |
will(new CustomAction("render") |
| 61 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 62 |
4 |
@Override... |
| 63 |
|
public Object invoke(Invocation invocation) throws Throwable |
| 64 |
|
{ |
| 65 |
4 |
WikiPrinter printer = (WikiPrinter) invocation.getParameter(1); |
| 66 |
4 |
printer.print("print result"); |
| 67 |
|
|
| 68 |
4 |
return null; |
| 69 |
|
} |
| 70 |
|
}); |
| 71 |
|
|
| 72 |
4 |
oneOf(translation).render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY); |
| 73 |
4 |
will(returnValue(new WordBlock("message"))); |
| 74 |
|
|
| 75 |
4 |
oneOf(localizationManager).getTranslation("key", Locale.ROOT); |
| 76 |
4 |
will(returnValue(translation)); |
| 77 |
|
|
| 78 |
4 |
oneOf(localizationContext).getCurrentLocale(); |
| 79 |
4 |
will(returnValue(Locale.ROOT)); |
| 80 |
|
} |
| 81 |
|
}); |
| 82 |
|
} |
| 83 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 84 |
1 |
@Test... |
| 85 |
|
public void render() throws Exception |
| 86 |
|
{ |
| 87 |
1 |
prepareRenderTest(); |
| 88 |
|
|
| 89 |
1 |
Assert.assertEquals("print result", getMockedComponent().render("key")); |
| 90 |
|
} |
| 91 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 92 |
1 |
@Test... |
| 93 |
|
public void renderWithSyntax() throws Exception |
| 94 |
|
{ |
| 95 |
1 |
prepareRenderTest(); |
| 96 |
|
|
| 97 |
1 |
Assert.assertEquals("print result", getMockedComponent().render("key", Syntax.PLAIN_1_0)); |
| 98 |
|
} |
| 99 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 100 |
1 |
@Test... |
| 101 |
|
public void renderWithSyntaxAndParameters() throws Exception |
| 102 |
|
{ |
| 103 |
1 |
prepareRenderTest(); |
| 104 |
|
|
| 105 |
1 |
Assert.assertEquals("print result", getMockedComponent().render("key", Syntax.PLAIN_1_0, Arrays.asList())); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 108 |
1 |
@Test... |
| 109 |
|
public void renderWithParameters() throws Exception |
| 110 |
|
{ |
| 111 |
1 |
prepareRenderTest(); |
| 112 |
|
|
| 113 |
1 |
Assert.assertEquals("print result", getMockedComponent().render("key", Arrays.asList())); |
| 114 |
|
} |
| 115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 116 |
1 |
@Test... |
| 117 |
|
public void getCurrentLocale() throws Exception |
| 118 |
|
{ |
| 119 |
1 |
final LocalizationContext localizationContext = getComponentManager().getInstance(LocalizationContext.class); |
| 120 |
1 |
getMockery().checking(new Expectations() |
| 121 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 122 |
1 |
{... |
| 123 |
1 |
oneOf(localizationContext).getCurrentLocale(); |
| 124 |
1 |
will(returnValue(Locale.ENGLISH)); |
| 125 |
|
} |
| 126 |
|
}); |
| 127 |
|
|
| 128 |
1 |
Assert.assertEquals(Locale.ENGLISH, getMockedComponent().getCurrentLocale()); |
| 129 |
|
} |
| 130 |
|
} |