From 762b10f5508a3f2b463472b86e9f48a21ff3b71e Mon Sep 17 00:00:00 2001 From: Mats Rydberg Date: Thu, 25 Feb 2016 13:25:02 +0100 Subject: [PATCH] Add unit tests for all matchers Make NullMatcher a static field on ValueMatcher. --- .../feature/parser/CypherMatchersCreator.java | 5 +- .../parser/matchers/BooleanMatcher.java | 6 +++ .../feature/parser/matchers/FloatMatcher.java | 6 +++ .../parser/matchers/IntegerMatcher.java | 6 +++ .../feature/parser/matchers/ListMatcher.java | 15 +++++- .../feature/parser/matchers/MapMatcher.java | 10 +--- .../parser/matchers/StringMatcher.java | 14 +++-- .../feature/parser/matchers/ValueMatcher.java | 15 ++++++ .../scala/cypher/feature/parser/accept.scala | 13 +++++ .../parser/expectedResultsParserTest.scala | 17 +----- .../parser/matchers/BooleanMatcherTest.scala | 46 ++++++++++++++++ .../parser/matchers/FloatMatcherTest.scala | 52 +++++++++++++++++++ .../parser/matchers/IntegerMatcherTest.scala | 49 +++++++++++++++++ .../parser/matchers/ListMatcherTest.scala | 49 +++++++++++++++++ .../parser/matchers/MapMatcherTest.scala | 45 ++++++++++++++++ .../parser/matchers/StringMatcherTest.scala | 45 ++++++++++++++++ .../parser/matchers/ValueMatcherTest.scala} | 26 +++++++--- 17 files changed, 378 insertions(+), 41 deletions(-) create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/accept.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/BooleanMatcherTest.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/FloatMatcherTest.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/IntegerMatcherTest.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ListMatcherTest.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/MapMatcherTest.scala create mode 100644 community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/StringMatcherTest.scala rename community/cypher/compatibility-suite/src/{main/java/cypher/feature/parser/matchers/NullMatcher.java => test/scala/cypher/feature/parser/matchers/ValueMatcherTest.scala} (61%) diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/CypherMatchersCreator.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/CypherMatchersCreator.java index 3423396e48e1..0316f03dd5f0 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/CypherMatchersCreator.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/CypherMatchersCreator.java @@ -27,11 +27,9 @@ import cypher.feature.parser.matchers.ListMatcher; import cypher.feature.parser.matchers.MapMatcher; import cypher.feature.parser.matchers.NodeMatcher; -import cypher.feature.parser.matchers.NullMatcher; import cypher.feature.parser.matchers.StringMatcher; import cypher.feature.parser.matchers.ValueMatcher; -import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; @@ -39,7 +37,6 @@ import java.util.Map; import java.util.Set; -import org.neo4j.graphdb.Label; import org.neo4j.graphdb.RelationshipType; class CypherMatchersCreator extends FeatureResultsBaseListener @@ -75,7 +72,7 @@ public void enterInteger( FeatureResultsParser.IntegerContext ctx ) @Override public void enterNullValue( FeatureResultsParser.NullValueContext ctx ) { - workload.push( new NullMatcher() ); + workload.push( ValueMatcher.NULL_MATCHER ); } @Override diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/BooleanMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/BooleanMatcher.java index e2d6b644c028..bc6f91e5a2d0 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/BooleanMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/BooleanMatcher.java @@ -33,4 +33,10 @@ public boolean matches( Object value ) { return value instanceof Boolean && (Boolean) value == this.value; } + + @Override + public String toString() + { + return "BooleanMatcher for " + value; + } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/FloatMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/FloatMatcher.java index aaa8ddec85fe..a642946e445d 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/FloatMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/FloatMatcher.java @@ -33,4 +33,10 @@ public boolean matches( Object value ) { return value instanceof Double && value.equals( this.value ); } + + @Override + public String toString() + { + return "FloatMatcher for " + value; + } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/IntegerMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/IntegerMatcher.java index 424f609aa594..e288a6a6664a 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/IntegerMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/IntegerMatcher.java @@ -33,4 +33,10 @@ public boolean matches( Object value ) { return value instanceof Long && (Long) value == this.value; } + + @Override + public String toString() + { + return "IntegerMatcher for " + value; + } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ListMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ListMatcher.java index fc0a39089d39..20be1b45e4c7 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ListMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ListMatcher.java @@ -37,12 +37,23 @@ public boolean matches( Object value ) { List realList = (List) value; boolean match = realList.size() == list.size(); - for ( int i = 0; i < list.size(); ++i ) + if ( match ) { - match &= list.get( i ).matches( realList.get( i ) ); + for ( int i = 0; i < list.size(); ++i ) + { + ValueMatcher valueMatcher = list.get( i ); + Object value1 = realList.get( i ); + match &= valueMatcher.matches( value1 ); + } } return match; } return false; } + + @Override + public String toString() + { + return "ListMatcher for " + list.toString(); + } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/MapMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/MapMatcher.java index 1aee9e3b74df..b6b55e7c8918 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/MapMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/MapMatcher.java @@ -25,13 +25,7 @@ public class MapMatcher implements ValueMatcher { - public static final MapMatcher EMPTY = new MapMatcher( Collections.emptyMap() ) { - @Override - public String toString() - { - return "{ MapMatcher matching the empty map }"; - } - }; + public static final MapMatcher EMPTY = new MapMatcher( Collections.emptyMap() ); private final Map map; @@ -65,6 +59,6 @@ public boolean matches( Object value ) @Override public String toString() { - return "{ MapMatcher matching a map with keys " + map.keySet().toString() + " and values " + map.values().toString() + " }"; + return "MapMatcher for " + map.toString(); } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/StringMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/StringMatcher.java index 50b47a2ddeab..7f27353768ee 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/StringMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/StringMatcher.java @@ -21,16 +21,22 @@ public class StringMatcher implements ValueMatcher { - private final String value; + private final String string; - public StringMatcher( String value ) + public StringMatcher( String string ) { - this.value = value; + this.string = string; } @Override public boolean matches( Object value ) { - return value instanceof String && value.toString().equals( value ); + return value instanceof String && value.toString().equals( string ); + } + + @Override + public String toString() + { + return "StringMatcher for " + string; } } diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ValueMatcher.java b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ValueMatcher.java index 3cd9ae206662..47091b52fb5c 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ValueMatcher.java +++ b/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/ValueMatcher.java @@ -22,4 +22,19 @@ public interface ValueMatcher { boolean matches( Object value ); + + ValueMatcher NULL_MATCHER = new ValueMatcher() + { + @Override + public boolean matches( Object value ) + { + return value == null; + } + + @Override + public String toString() + { + return "NullMatcher"; + } + }; } diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/accept.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/accept.scala new file mode 100644 index 000000000000..ff25d26fc0d7 --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/accept.scala @@ -0,0 +1,13 @@ +package cypher.feature.parser + +import cypher.feature.parser.matchers.ValueMatcher +import org.scalatest.matchers.{MatchResult, Matcher} + +case class accept(value: Any) extends Matcher[ValueMatcher] { + + override def apply(matcher: ValueMatcher): MatchResult = { + MatchResult(matches = matcher.matches(value), + s"$matcher did not match $value", + s"$matcher unexpectedly matched $value") + } +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/expectedResultsParserTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/expectedResultsParserTest.scala index f04751284302..8daa2b786069 100644 --- a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/expectedResultsParserTest.scala +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/expectedResultsParserTest.scala @@ -21,14 +21,11 @@ package cypher.feature.parser import java.lang.Boolean.{FALSE, TRUE} import java.lang.Long -import java.util.Arrays.asList -import java.util.Collections.{emptyList, emptyMap} +import java.util.Collections.emptyList import java.{lang, util} -import org.mockito.Mockito._ -import org.mockito.Mockito.{when, mock, _} - import cypher.feature.parser.matchers.ValueMatcher +import org.mockito.Mockito.{mock, when} import org.neo4j.graphdb._ import org.scalatest.matchers.{MatchResult, Matcher} import org.scalatest.{FunSuite, Matchers} @@ -208,14 +205,4 @@ class expectedResultsParserTest extends FunSuite with Matchers { map } - case class accept(expected: Any) - extends Matcher[ValueMatcher] { - - override def apply(actual: ValueMatcher): MatchResult = { - MatchResult(matches = actual.matches(expected), - s"Mismatch! Expected value $actual did not match $expected", - s"No mismatch found; $actual unexpectedly matched $expected") - } - } - } diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/BooleanMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/BooleanMatcherTest.scala new file mode 100644 index 000000000000..025d36cdcd2d --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/BooleanMatcherTest.scala @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class BooleanMatcherTest extends FunSuite { + + test("should match true") { + new BooleanMatcher(true) should accept(true) + } + + test("should match false") { + new BooleanMatcher(false) should accept(false) + } + + test("should not match other values") { + new BooleanMatcher(true) shouldNot accept(false) + new BooleanMatcher(true) shouldNot accept(null) + new BooleanMatcher(true) shouldNot accept("") + + new BooleanMatcher(false) shouldNot accept(true) + new BooleanMatcher(false) shouldNot accept(null) + new BooleanMatcher(false) shouldNot accept("") + } + +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/FloatMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/FloatMatcherTest.scala new file mode 100644 index 000000000000..28b2cd46b0e7 --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/FloatMatcherTest.scala @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class FloatMatcherTest extends FunSuite { + + test("should match simple float") { + new FloatMatcher(1.0) should accept(1.0) + new FloatMatcher(.1e1) should accept(1.0) + } + + test("should match infinities") { + new FloatMatcher(Double.PositiveInfinity) should accept(Double.PositiveInfinity) + new FloatMatcher(Double.NegativeInfinity) should accept(Double.NegativeInfinity) + } + + test("should match NaN") { + new FloatMatcher(Double.NaN) should accept(Double.NaN) + } + + test("should not match integers") { + new FloatMatcher(1.0) shouldNot accept(1) + new FloatMatcher(0.0) shouldNot accept(0) + } + + test("should not match strings") { + new FloatMatcher(0.0) shouldNot accept("0.0") + new FloatMatcher(0.0e1) shouldNot accept("0") + } + +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/IntegerMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/IntegerMatcherTest.scala new file mode 100644 index 000000000000..660c3b1847a0 --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/IntegerMatcherTest.scala @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class IntegerMatcherTest extends FunSuite { + + test("should match integers") { + new IntegerMatcher(0) should accept(0L) + new IntegerMatcher(-1) should accept(-1L) + new IntegerMatcher(2) should accept(2L) + } + + test("should only match longs") { + new IntegerMatcher(0) shouldNot accept(0) + new IntegerMatcher(0) shouldNot accept(0.asInstanceOf[Short]) + } + + test("should not accept other types") { + new IntegerMatcher(0) shouldNot accept(null) + new IntegerMatcher(0) shouldNot accept("0") + new IntegerMatcher(0) shouldNot accept(0.0) + } + + test("should match large ints") { + new IntegerMatcher(Long.MaxValue) should accept(Long.MaxValue) + } + +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ListMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ListMatcherTest.scala new file mode 100644 index 000000000000..6a4007d12fcd --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ListMatcherTest.scala @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import java.util.Arrays.asList +import java.util.Collections.emptyList + +import cypher.feature.parser.accept +import cypher.feature.parser.matchers.ValueMatcher.NULL_MATCHER +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class ListMatcherTest extends FunSuite { + + test("should match lists") { + new ListMatcher(asList(NULL_MATCHER)) should accept(asList(null)) + new ListMatcher(asList(new BooleanMatcher(true))) should accept(asList(true)) + new ListMatcher(emptyList()) should accept(emptyList()) + } + + test("should not match lists of different size") { + new ListMatcher(emptyList()) shouldNot accept(asList("")) + new ListMatcher(asList(new StringMatcher(""))) shouldNot accept(emptyList()) + new ListMatcher(asList(new StringMatcher(""), new ListMatcher(emptyList()))) shouldNot accept(asList("", emptyList(), 0)) + } + + test("should match nested lists") { + new ListMatcher(asList(new ListMatcher(asList(NULL_MATCHER)))) should accept(asList(asList(null))) + new ListMatcher(asList(new ListMatcher(asList(new IntegerMatcher(0), new BooleanMatcher(false))), new StringMatcher(""))) should accept(asList(asList(0L, false), "")) + } + +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/MapMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/MapMatcherTest.scala new file mode 100644 index 000000000000..7165712bbf2c --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/MapMatcherTest.scala @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import cypher.feature.parser.matchers.ValueMatcher.NULL_MATCHER +import org.scalatest.FunSuite +import org.scalatest.Matchers._ +import scala.collection.JavaConverters._ + +class MapMatcherTest extends FunSuite { + + test("should match maps") { + new MapMatcher(Map[String, ValueMatcher]("key" -> new StringMatcher("value")).asJava) should accept(Map("key" -> "value").asJava) + new MapMatcher(Map.empty[String, ValueMatcher].asJava) should accept(Map.empty.asJava) + } + + test("should match nested maps") { + new MapMatcher(Map[String, ValueMatcher]("key" -> new MapMatcher(Map[String, ValueMatcher]("key" -> new FloatMatcher(0.0)).asJava)).asJava) should accept(Map("key" -> Map("key" -> 0.0).asJava).asJava) + } + + test("should not match maps of different size") { + new MapMatcher(Map.empty[String, ValueMatcher].asJava) shouldNot accept(Map("k" -> "").asJava) + new MapMatcher(Map("k" -> NULL_MATCHER).asJava) shouldNot accept(Map.empty.asJava) + new MapMatcher(Map("k" -> NULL_MATCHER, "k2" -> new BooleanMatcher(true)).asJava) shouldNot accept(Map("k" -> NULL_MATCHER)) + } + +} diff --git a/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/StringMatcherTest.scala b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/StringMatcherTest.scala new file mode 100644 index 000000000000..74890f9019c1 --- /dev/null +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/StringMatcherTest.scala @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2002-2016 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class StringMatcherTest extends FunSuite { + + test("should match strings") { + new StringMatcher("test") should accept("test") + new StringMatcher("") should accept("") + } + + test("should not accept wrong strings") { + new StringMatcher("aaa") shouldNot accept("a") + new StringMatcher("a") shouldNot accept("aaa") + new StringMatcher("A") shouldNot accept("a") + } + + test("should not accept other types") { + new StringMatcher("0") shouldNot accept(0) + new StringMatcher("") shouldNot accept(null) + new StringMatcher("true") shouldNot accept(true) + } + +} diff --git a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/NullMatcher.java b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ValueMatcherTest.scala similarity index 61% rename from community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/NullMatcher.java rename to community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ValueMatcherTest.scala index d5bfbe94f5c0..c13f33eb4c13 100644 --- a/community/cypher/compatibility-suite/src/main/java/cypher/feature/parser/matchers/NullMatcher.java +++ b/community/cypher/compatibility-suite/src/test/scala/cypher/feature/parser/matchers/ValueMatcherTest.scala @@ -17,13 +17,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package cypher.feature.parser.matchers; +package cypher.feature.parser.matchers + +import cypher.feature.parser.accept +import cypher.feature.parser.matchers.ValueMatcher.NULL_MATCHER +import org.scalatest.FunSuite +import org.scalatest.Matchers._ + +class ValueMatcherTest extends FunSuite { + + test("null matcher should match null") { + NULL_MATCHER should accept(null) + } + + test("null matcher should not accept non-null") { + NULL_MATCHER shouldNot accept(0) + NULL_MATCHER shouldNot accept("") + NULL_MATCHER shouldNot accept(new Object()) + } -public class NullMatcher implements ValueMatcher -{ - @Override - public boolean matches( Object value ) - { - return value == null; - } }