Unverified Commit 716acbfb authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

test: fixed/improved some of the existing unit tests.

parent e885dba9
......@@ -46,67 +46,39 @@ public class DelegatingFrameGraphSanityTest {
g.close();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullDelegate() {
try {
assertSanity(new DelegatingFramedGraph(null, resolver));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
new DelegatingFramedGraph(null, resolver);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullResolver() {
try {
assertSanity(new DelegatingFramedGraph(g, (TypeResolver) null));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
new DelegatingFramedGraph(g, (TypeResolver) null);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullBuilder() {
try {
assertSanity(new DelegatingFramedGraph(g, null, resolver));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
new DelegatingFramedGraph(g, null, resolver);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullReflectionsCache() {
try {
assertSanity(new DelegatingFramedGraph(g, null, true, true));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
new DelegatingFramedGraph(g, null, true, true);
}
@Test
public void testNoTypeResolutionNoAnnotations() {
try {
assertSanity(new DelegatingFramedGraph(g, new ReflectionCache(), false, false));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
assertSanity(new DelegatingFramedGraph(g, new ReflectionCache(), false, false));
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullTypes() {
try {
assertSanity(new DelegatingFramedGraph(g, true, null));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
new DelegatingFramedGraph(g, true, null);
}
@Test
public void testEmptyTypesSet() {
try {
assertSanity(new DelegatingFramedGraph(g, false, new HashSet<>()));
} catch (IllegalArgumentException e) {
// Illegal args is ok
}
assertSanity(new DelegatingFramedGraph(g, false, new HashSet<>()));
}
private void assertSanity(DelegatingFramedGraph framed) {
......
......@@ -16,6 +16,8 @@
package com.syncleus.ferma;
import java.util.function.Consumer;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph;
import org.junit.Assert;
......@@ -23,6 +25,8 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.when;
/**
*
* @author rqpa
......@@ -30,13 +34,19 @@ import org.mockito.Mockito;
public class DelegatingTransactionTest {
private Transaction gremlinTx;
private WrappedFramedGraph<?> framedGraph;
private WrappedFramedGraph<Graph> framedGraph;
private Graph baseGraph;
private DelegatingTransaction delegatingTx;
@Before
public void setUp() {
gremlinTx = Mockito.mock(Transaction.class);
framedGraph = Mockito.mock(WrappedFramedGraph.class, Mockito.RETURNS_MOCKS);
baseGraph = Mockito.mock(Graph.class, Mockito.RETURNS_MOCKS);
when(gremlinTx.createThreadedTx()).thenReturn(baseGraph);
when(framedGraph.getBaseGraph()).thenReturn(baseGraph);
delegatingTx = new DelegatingTransaction(gremlinTx, framedGraph);
}
......@@ -120,7 +130,7 @@ public class DelegatingTransactionTest {
private void assertDelegatingIsOpenUsage(boolean expectedValue) {
Transaction tx = Mockito.mock(Transaction.class);
WrappedFramedGraph<?> graph = Mockito.mock(WrappedFramedGraph.class);
Mockito.when(tx.isOpen()).thenReturn(expectedValue);
when(tx.isOpen()).thenReturn(expectedValue);
DelegatingTransaction delTx = new DelegatingTransaction(tx, graph);
Assert.assertEquals(expectedValue, delTx.isOpen());
......
......@@ -29,7 +29,9 @@ import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Collections;
import net.bytebuddy.dynamic.DynamicType;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.junit.After;
import org.junit.Before;
......@@ -103,9 +105,14 @@ public class AnnotationFrameFactoryTest {
}
@Test (expected = IllegalStateException.class)
public void testBadElementBadFrame() {
Element badElement = Mockito.mock(Element.class);
frameFactory.create(badElement, InvalidFrame.class);
public void testVertexBadFrame() {
Vertex okElement = Mockito.mock(Vertex.class);
frameFactory.create(okElement, InvalidFrame.class);
}
@Test (expected = IllegalStateException.class)
public void testEdgeBadFrame() {
Edge okElement = Mockito.mock(Edge.class);
frameFactory.create(okElement, InvalidFrame.class);
}
}
......@@ -141,11 +141,7 @@ public class TxFactoryTest implements TxFactory {
@Override
public <T> T tx(TxAction<T> txHandler) {
try (Tx tx = tx()) {
try {
return txHandler.handle(mock);
} catch (Exception e) {
throw new RuntimeException(e);
}
return txHandler.handle(mock);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment