1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.query

File CurrentLanguageQueryFilterTest.java

 

Code metrics

0
10
1
1
67
35
1
0.1
10
1
1

Classes

Class Line # Actions
CurrentLanguageQueryFilterTest 44 10 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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 com.xpn.xwiki.internal.query;
21   
22    import java.util.Locale;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.context.Execution;
27    import org.xwiki.context.ExecutionContext;
28    import org.xwiki.query.Query;
29    import org.xwiki.test.mockito.MockitoComponentMockingRule;
30   
31    import com.xpn.xwiki.XWikiContext;
32   
33    import static org.junit.Assert.assertEquals;
34    import static org.mockito.Mockito.any;
35    import static org.mockito.Mockito.mock;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * Unit tests for {@link CurrentLanguageQueryFilter}.
40    *
41    * @version $Id: 51e3b1aca200b4f47aed39a3f026fb66898c4178 $
42    * @since 5.1M2
43    */
 
44    public class CurrentLanguageQueryFilterTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<CurrentLanguageQueryFilter> mocker =
48    new MockitoComponentMockingRule<CurrentLanguageQueryFilter>(CurrentLanguageQueryFilter.class);
49   
 
50  1 toggle @Test
51    public void filterStatement() throws Exception
52    {
53  1 Execution execution = this.mocker.getInstance(Execution.class);
54  1 ExecutionContext executionContext = mock(ExecutionContext.class);
55  1 when(execution.getContext()).thenReturn(executionContext);
56  1 XWikiContext xwikiContext = mock(XWikiContext.class);
57  1 when(executionContext.getProperty("xwikicontext")).thenReturn(xwikiContext);
58  1 com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
59  1 when(xwikiContext.getWiki()).thenReturn(xwiki);
60  1 when(xwiki.getDefaultLocale(any(XWikiContext.class))).thenReturn(Locale.FRANCE);
61   
62  1 String result = this.mocker.getComponentUnderTest().filterStatement(
63    "select doc.fullName from XWikiDocument doc where 1=1", Query.HQL);
64  1 assertEquals("select doc.fullName from XWikiDocument doc where (doc.language is null or doc.language = '' or "
65    + "doc.language = 'fr_FR') and (1=1)", result);
66    }
67    }