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

File DocumentQueryFilterTest.java

 

Code metrics

0
18
6
1
106
67
6
0.33
3
6
1

Classes

Class Line # Actions
DocumentQueryFilterTest 48 18 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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.query.internal;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.List;
25   
26    import javax.inject.Named;
27   
28    import org.junit.jupiter.api.Test;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.DocumentReferenceResolver;
31    import org.xwiki.query.Query;
32    import org.xwiki.test.junit5.mockito.ComponentTest;
33    import org.xwiki.test.junit5.mockito.InjectMockComponents;
34    import org.xwiki.test.junit5.mockito.MockComponent;
35   
36    import static org.junit.jupiter.api.Assertions.assertArrayEquals;
37    import static org.junit.jupiter.api.Assertions.assertEquals;
38    import static org.junit.jupiter.api.Assertions.assertSame;
39    import static org.mockito.Mockito.when;
40   
41    /**
42    * Unit tests for {@link DocumentQueryFilter}.
43    *
44    * @version $Id: 547cb5c7b5e919b776d6f221cf14a576eb532159 $
45    * @since 9.8
46    */
47    @ComponentTest
 
48    public class DocumentQueryFilterTest
49    {
50    @InjectMockComponents
51    private DocumentQueryFilter filter;
52   
53    @MockComponent
54    @Named("current")
55    private DocumentReferenceResolver<String> resolver;
56   
 
57  1 toggle @Test
58    public void filterStatement()
59    {
60  1 String statement = "select doc.fullName from XWikiDocument doc";
61  1 assertSame(statement, this.filter.filterStatement(statement, Query.HQL));
62    }
63   
 
64  1 toggle @Test
65    public void filterResultsWithOneColumn()
66    {
67  1 DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page");
68  1 when(this.resolver.resolve("Path.To.Page")).thenReturn(documentReference);
69   
70  1 List<Object> results = Arrays.asList("Path.To.Page");
71  1 assertEquals(Arrays.asList(documentReference), this.filter.filterResults(results));
72    }
73   
 
74  1 toggle @Test
75    public void filterResultsWithTwoColumns()
76    {
77  1 DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page");
78  1 when(this.resolver.resolve("Path.To.Page")).thenReturn(documentReference);
79   
80  1 List<Object> results = Arrays.asList((Object) new Object[]{ "Path.To.Page", "red" });
81  1 List<Object> filteredResults = this.filter.filterResults(results);
82  1 assertEquals(1, filteredResults.size());
83  1 assertArrayEquals(new Object[]{ documentReference, "red" }, (Object[]) filteredResults.get(0));
84    }
85   
 
86  1 toggle @Test
87    public void filterResultsWithOneColumnButNotString()
88    {
89  1 List<Object> results = Collections.singletonList(23);
90  1 assertSame(results, this.filter.filterResults(results));
91    }
92   
 
93  1 toggle @Test
94    public void filterResultsWithTwoColumnsButNotString()
95    {
96  1 List<Object> results = Collections.singletonList(new Object[]{ 23, "Path.To.Page" });
97  1 assertSame(results, this.filter.filterResults(results));
98    }
99   
 
100  1 toggle @Test
101    public void filterResultsEmpty()
102    {
103  1 List<Object> results = Collections.emptyList();
104  1 assertSame(results, this.filter.filterResults(results));
105    }
106    }