Skip to content
Snippets Groups Projects
Commit 07a6d6b0 authored by Pierre Jeanjean's avatar Pierre Jeanjean Committed by Thomas Mortagne
Browse files

XWIKI-21473: Improve search suggest evaluation

* Fix coverage in xwiki-platform-search-api

(cherry picked from commit 8f37e1c5)
parent 49c1820d
No related branches found
No related tags found
No related merge requests found
...@@ -40,5 +40,12 @@ ...@@ -40,5 +40,12 @@
<artifactId>xwiki-commons-component-api</artifactId> <artifactId>xwiki-commons-component-api</artifactId>
<version>${commons.version}</version> <version>${commons.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-tool-test-component</artifactId>
<version>${commons.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.search.internal;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Named;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.xwiki.evaluation.ObjectEvaluatorException;
import org.xwiki.evaluation.ObjectPropertyEvaluator;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectMockComponents;
import org.xwiki.test.junit5.mockito.MockComponent;
import com.xpn.xwiki.objects.BaseObject;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Validate {@link SearchSuggestSourceObjectEvaluator}.
*
* @version $Id$
*/
@ComponentTest
public class SearchSuggestSourceObjectEvaluatorTest
{
@InjectMockComponents
private SearchSuggestSourceObjectEvaluator searchSuggestSourceObjectEvaluator;
@MockComponent
@Named("velocity")
private ObjectPropertyEvaluator velocityObjectPropertyEvaluator;
@Mock
private BaseObject baseObject;
@BeforeEach
void setUp() throws ObjectEvaluatorException
{
when(this.baseObject.getStringValue("icon")).thenReturn("unevaluated icon");
when(this.baseObject.getStringValue("name")).thenReturn("unevaluated name");
Map<String, String> evaluatedVelocityProperties = new HashMap<>();
evaluatedVelocityProperties.put("icon", "evaluated icon");
evaluatedVelocityProperties.put("name", "evaluated name");
when(this.velocityObjectPropertyEvaluator.evaluateProperties(this.baseObject, "name", "icon"))
.thenReturn(evaluatedVelocityProperties);
}
@Test
void checkEvaluationThroughPropertyEvaluator() throws ObjectEvaluatorException
{
Map<String, String> evaluationResults = this.searchSuggestSourceObjectEvaluator.evaluate(this.baseObject);
verify(this.velocityObjectPropertyEvaluator).evaluateProperties(this.baseObject, "name", "icon");
assertEquals("evaluated icon", evaluationResults.get("icon"));
assertEquals("evaluated name", evaluationResults.get("name"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment