andreachild commented on PR #3274:
URL: https://github.com/apache/tinkerpop/pull/3274#issuecomment-3503836042
It would be good to add a unit test for this. Here is a suggested one since
there are no existing (direct) unit tests for the `JavaTranslator`. Note that
if you execute the test below without the code fix it will randomly fail/pass
depending on the order of methods loaded into the
`JavaTranslator.GLOBAL_METHOD_CACHE`.
```
package org.apache.tinkerpop.gremlin.jsr223;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class JavaTranslatorTest {
private GraphTraversalSource g = EmptyGraph.instance().traversal();
private JavaTranslator<GraphTraversalSource, Traversal.Admin<?, ?>>
translator = JavaTranslator.of(EmptyGraph.instance().traversal());
@Test
public void shouldTranslateHasWithObjectArgValue() {
final Bytecode bytecode = new Bytecode();
bytecode.addStep("E");
bytecode.addStep("has", "knows", "weight", 1.0);
final Traversal.Admin<?, ?> translation =
translator.translate(bytecode);
assertEquals(g.E().has("knows", "weight", 1.0).asAdmin(),
translation);
}
@Test
public void shouldTranslateHasWithPredicateArgValue() {
final Bytecode bytecode = new Bytecode();
bytecode.addStep("E");
bytecode.addStep("has", "knows", "weight", P.eq(1.0));
final Traversal.Admin<?, ?> translation =
translator.translate(bytecode);
assertEquals(g.E().has("knows", "weight", P.eq(1.0)).asAdmin(),
translation);
}
@Test
public void shouldTranslateHasWithNullThirdArgValue() {
final Bytecode bytecode = new Bytecode();
bytecode.addStep("E");
bytecode.addStep("has", "knows", "weight", null);
final Traversal.Admin<?, ?> translation =
translator.translate(bytecode);
assertEquals(g.E().has("knows", "weight", (String) null).asAdmin(),
translation);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]