From f38fb7f02c9c93e73a6a3326b98074bc1624f9f0 Mon Sep 17 00:00:00 2001 From: reger Date: Mon, 14 Aug 2017 02:16:43 +0200 Subject: [PATCH] Add junit test for AbstractOperations.addOperand() --- .../solr/logic/AbstractOperationsTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/java/net/yacy/cora/federate/solr/logic/AbstractOperationsTest.java diff --git a/test/java/net/yacy/cora/federate/solr/logic/AbstractOperationsTest.java b/test/java/net/yacy/cora/federate/solr/logic/AbstractOperationsTest.java new file mode 100644 index 000000000..30eda250a --- /dev/null +++ b/test/java/net/yacy/cora/federate/solr/logic/AbstractOperationsTest.java @@ -0,0 +1,57 @@ +/** + * AbstractOperationsTest + * part of YaCy + * Copyright 2017 by reger24; https://github.com/reger24 + * + * This library 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 library 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 program in the file lgpl21.txt + * If not, see . + */ +package net.yacy.cora.federate.solr.logic; + +import net.yacy.search.schema.CollectionSchema; +import static org.junit.Assert.*; +import org.junit.Test; + +/** + * Unit tests for AbstractOperationsTest class. + * + */ +public class AbstractOperationsTest { + + /** + * Test of addOperand method, of class AbstractOperations. + */ + @Test + public void testAddOperand() { + + + // create a simple query + Conjunction con = new Conjunction(); + con.addOperand(new LongLiteral(CollectionSchema.httpstatus_i, 200)); // result: con="httpstatus_i:200" + + // create a 2nd empty query + Disjunction dnf = new Disjunction(); + // add the empty query + con.addOperand(dnf); // result (shall be unchanged): "httpstatus_i:200" + + // test for wrong result "(httpstatus_i:200 AND )" + String query = con.toString(); + String testStr = query.replace(")", ""); // remove all ')' for easier testing + testStr = testStr.replace("(", ""); // remove all '(' for easier testing + testStr = testStr.trim(); + assertFalse("query ending with operator =" + query, testStr.endsWith(con.operandName)); + assertFalse("query ending with operator =" + query, testStr.endsWith(dnf.operandName)); + } + +}