Skip to content

Commit

Permalink
Sonar: Parameterized test.
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagolvlsantos committed Jun 30, 2021
1 parent 7125b9b commit cfb1bc7
Showing 1 changed file with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import io.github.thiagolvlsantos.json.predicate.impl.PredicateFactoryJson;

@RunWith(Parameterized.class)
public class JsonPredicateTests {

private IPredicateFactory factory = new PredicateFactoryJson();
private static Map<String, Object> map;

@Parameter
public String expression;

@BeforeClass
public static void map() {
map = new HashMap<>();
Expand All @@ -24,51 +32,23 @@ public static void map() {
map.put("c", "any");
}

@Test
public void testEquals() {
Predicate<Object> pred = factory.read("{\"a\":{\"$eq\":1}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testNotEquals() {
Predicate<Object> pred = factory.read("{\"a\":{\"$ne\":2}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testTrue() {
Predicate<Object> pred = factory.read("{\"b\":{\"$eq\":true}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testFalse() {
Predicate<Object> pred = factory.read("{\"b\":{\"$ne\":false}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testContains() {
Predicate<Object> pred = factory.read("{\"c\":{\"$contains\":\"any\"}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testNotContains() {
Predicate<Object> pred = factory.read("{\"c\":{\"$ncontains\":\"other\"}}".getBytes());
assertTrue(pred.test(map));
}

@Test
public void testMatch() {
Predicate<Object> pred = factory.read("{\"c\":{\"$match\":\"any\"}}".getBytes());
assertTrue(pred.test(map));
@Parameters(name = "Expression: {0}")
public static String[] expressions() {
return new String[] { //
"{\"a\":{\"$eq\":1}}", //
"{\"a\":{\"$ne\":2}}", //
"{\"b\":{\"$eq\":true}}", //
"{\"b\":{\"$ne\":false}}", //
"{\"c\":{\"$contains\":\"any\"}}", //
"{\"c\":{\"$ncontains\":\"other\"}}", //
"{\"c\":{\"$match\":\"any\"}}", //
"{\"c\":{\"$nmatch\":\"her\"}}" //
};
}

@Test
public void testNotMatch() {
Predicate<Object> pred = factory.read("{\"c\":{\"$nmatch\":\"her\"}}".getBytes());
public void test() {
Predicate<Object> pred = factory.read(expression.getBytes());
assertTrue(pred.test(map));
}
}

0 comments on commit cfb1bc7

Please sign in to comment.