This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit ced752b4a985dffaabc780459773e4ede97d2aab
Author: juanpablo <juanpa...@apache.org>
AuthorDate: Tue Mar 17 22:41:50 2020 +0100

    added new adapter to convert classes between o.a.w.search and 
o.a.w.api.search
---
 .../org/apache/wiki/providers/SearchAdapter.java   | 40 ++++++++++++++++++
 .../apache/wiki/providers/SearchAdapterTest.java   | 47 ++++++++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git 
a/jspwiki-210-adapters/src/main/java/org/apache/wiki/providers/SearchAdapter.java
 
b/jspwiki-210-adapters/src/main/java/org/apache/wiki/providers/SearchAdapter.java
new file mode 100644
index 0000000..8df1676
--- /dev/null
+++ 
b/jspwiki-210-adapters/src/main/java/org/apache/wiki/providers/SearchAdapter.java
@@ -0,0 +1,40 @@
+package org.apache.wiki.providers;
+
+import org.apache.wiki.api.core.Page;
+import org.apache.wiki.api.search.QueryItem;
+import org.apache.wiki.api.search.SearchResult;
+
+
+class SearchAdapter {
+
+    static org.apache.wiki.search.QueryItem oldQueryItemfrom( final QueryItem 
item ) {
+        final org.apache.wiki.search.QueryItem qi = new 
org.apache.wiki.search.QueryItem();
+        qi.type = item.type;
+        qi.word = item.word;
+        return qi;
+    }
+
+    static SearchResult newSearchResultFrom( final 
org.apache.wiki.search.SearchResult result ) {
+        return new SearchResult() {
+
+            /** {@inheritDoc} */
+            @Override
+            public Page getPage() {
+                return result.getPage();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public int getScore() {
+                return result.getScore();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public String[] getContexts() {
+                return result.getContexts();
+            }
+        };
+    }
+
+}
diff --git 
a/jspwiki-210-adapters/src/test/java/org/apache/wiki/providers/SearchAdapterTest.java
 
b/jspwiki-210-adapters/src/test/java/org/apache/wiki/providers/SearchAdapterTest.java
new file mode 100644
index 0000000..40a9a35
--- /dev/null
+++ 
b/jspwiki-210-adapters/src/test/java/org/apache/wiki/providers/SearchAdapterTest.java
@@ -0,0 +1,47 @@
+package org.apache.wiki.providers;
+
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.search.QueryItem;
+import org.apache.wiki.api.search.SearchResult;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+public class SearchAdapterTest {
+
+    @Test
+    public void testOldQueryItemfrom() {
+        final QueryItem qi = new QueryItem();
+        qi.type = 1;
+        qi.word = "word";
+        final org.apache.wiki.search.QueryItem old = 
SearchAdapter.oldQueryItemfrom( qi );
+        Assertions.assertEquals( qi.type, old.type );
+        Assertions.assertEquals( qi.word, old.word );
+    }
+
+    @Test
+    public void testNewSearchResultFrom() {
+        final org.apache.wiki.search.SearchResult old = new 
org.apache.wiki.search.SearchResult() {
+
+            @Override
+            public WikiPage getPage() {
+                return null;
+            }
+
+            @Override
+            public int getScore() {
+                return 0;
+            }
+
+            @Override
+            public String[] getContexts() {
+                return new String[ 0 ];
+            }
+        };
+        final SearchResult sr = SearchAdapter.newSearchResultFrom( old );
+        Assertions.assertEquals( old.getPage(), sr.getPage() );
+        Assertions.assertEquals( old.getScore(), sr.getScore() );
+        Assertions.assertArrayEquals( old.getContexts(), sr.getContexts() );
+    }
+
+}

Reply via email to