1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.localization.messagetool.internal

File MessageToolTranslationMessageParserTest.java

 

Code metrics

0
22
7
1
112
76
7
0.32
3.14
7
1

Classes

Class Line # Actions
MessageToolTranslationMessageParserTest 42 22 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.localization.messagetool.internal;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.xwiki.component.manager.ComponentLookupException;
27    import org.xwiki.localization.message.TranslationMessage;
28    import org.xwiki.localization.message.TranslationMessageParser;
29    import org.xwiki.rendering.block.Block;
30    import org.xwiki.rendering.block.CompositeBlock;
31    import org.xwiki.rendering.block.SpecialSymbolBlock;
32    import org.xwiki.rendering.block.WordBlock;
33    import org.xwiki.rendering.internal.parser.plain.PlainTextBlockParser;
34    import org.xwiki.rendering.internal.parser.plain.PlainTextStreamParser;
35    import org.xwiki.rendering.parser.Parser;
36    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
37    import org.xwiki.test.annotation.ComponentList;
38    import org.xwiki.test.jmock.annotation.MockingRequirement;
39   
40    @MockingRequirement(value = MessageToolTranslationMessageParser.class, exceptions = Parser.class)
41    @ComponentList({PlainTextBlockParser.class, PlainTextStreamParser.class})
 
42    public class MessageToolTranslationMessageParserTest extends AbstractMockingComponentTestCase<TranslationMessageParser>
43    {
 
44  1 toggle @Test
45    public void messageEmpty() throws ComponentLookupException
46    {
47  1 TranslationMessage translationMessage = getMockedComponent().parse("");
48   
49  1 Assert.assertEquals("", translationMessage.getRawSource());
50  1 Assert.assertEquals(new CompositeBlock(), translationMessage.render(null, null));
51    }
52   
 
53  1 toggle @Test
54    public void messageSimple() throws ComponentLookupException
55    {
56  1 TranslationMessage translationMessage = getMockedComponent().parse("word");
57   
58  1 Assert.assertEquals("word", translationMessage.getRawSource());
59  1 Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null));
60    }
61   
 
62  1 toggle @Test
63    public void messageWithOneParameter() throws ComponentLookupException
64    {
65  1 TranslationMessage translationMessage = getMockedComponent().parse("{0}");
66   
67  1 Assert.assertEquals("{0}", translationMessage.getRawSource());
68  1 Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null, "word"));
69    }
70   
 
71  1 toggle @Test
72    public void messageWithExpectedParameter() throws ComponentLookupException
73    {
74  1 TranslationMessage translationMessage = getMockedComponent().parse("{0}");
75   
76  1 Assert.assertEquals("{0}", translationMessage.getRawSource());
77  1 Assert.assertEquals(
78    new CompositeBlock(Arrays.<Block> asList(new SpecialSymbolBlock('{'), new WordBlock("0"),
79    new SpecialSymbolBlock('}'))), translationMessage.render(null, null));
80    }
81   
 
82  1 toggle @Test
83    public void messageWithApostrophe() throws ComponentLookupException
84    {
85  1 TranslationMessage translationMessage = getMockedComponent().parse("'");
86   
87  1 Assert.assertEquals("'", translationMessage.getRawSource());
88  1 Assert.assertEquals(new SpecialSymbolBlock('\''), translationMessage.render(null, null));
89    }
90   
 
91  1 toggle @Test
92    public void messageWithEscapedParameter() throws ComponentLookupException
93    {
94  1 TranslationMessage translationMessage = getMockedComponent().parse("'{0}");
95   
96  1 Assert.assertEquals("'{0}", translationMessage.getRawSource());
97  1 Assert.assertEquals(
98    new CompositeBlock(Arrays.<Block> asList(new SpecialSymbolBlock('{'), new WordBlock("0"),
99    new SpecialSymbolBlock('}'))), translationMessage.render(null, null, "word"));
100    }
101   
 
102  1 toggle @Test
103    public void messageWithChoiceSyntax() throws ComponentLookupException
104    {
105  1 TranslationMessage translationMessage = getMockedComponent().parse("{0,choice,0#choice1|0<choice2}");
106   
107  1 Assert.assertEquals("{0,choice,0#choice1|0<choice2}", translationMessage.getRawSource());
108  1 Assert.assertEquals(new WordBlock("choice1"), translationMessage.render(null, null, 0));
109  1 Assert.assertEquals(new WordBlock("choice2"), translationMessage.render(null, null, 42));
110    }
111   
112    }