From 716acbfb9855b6cdba952963e2c16c8cec90a331 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Sat, 30 Sep 2017 22:27:08 -0400 Subject: [PATCH] test: fixed/improved some of the existing unit tests. --- .../ferma/DelegatingFrameGraphSanityTest.java | 52 +++++-------------- .../ferma/DelegatingTransactionTest.java | 14 ++++- .../AnnotationFrameFactoryTest.java | 15 ++++-- .../com/syncleus/ferma/tx/TxFactoryTest.java | 6 +-- 4 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/test/java/com/syncleus/ferma/DelegatingFrameGraphSanityTest.java b/src/test/java/com/syncleus/ferma/DelegatingFrameGraphSanityTest.java index 50e40d09..af00440e 100644 --- a/src/test/java/com/syncleus/ferma/DelegatingFrameGraphSanityTest.java +++ b/src/test/java/com/syncleus/ferma/DelegatingFrameGraphSanityTest.java @@ -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) { diff --git a/src/test/java/com/syncleus/ferma/DelegatingTransactionTest.java b/src/test/java/com/syncleus/ferma/DelegatingTransactionTest.java index df0ad43c..a7265aa4 100644 --- a/src/test/java/com/syncleus/ferma/DelegatingTransactionTest.java +++ b/src/test/java/com/syncleus/ferma/DelegatingTransactionTest.java @@ -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()); diff --git a/src/test/java/com/syncleus/ferma/framefactories/annotation/AnnotationFrameFactoryTest.java b/src/test/java/com/syncleus/ferma/framefactories/annotation/AnnotationFrameFactoryTest.java index 7dcb7150..736899f5 100644 --- a/src/test/java/com/syncleus/ferma/framefactories/annotation/AnnotationFrameFactoryTest.java +++ b/src/test/java/com/syncleus/ferma/framefactories/annotation/AnnotationFrameFactoryTest.java @@ -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); } - } diff --git a/src/test/java/com/syncleus/ferma/tx/TxFactoryTest.java b/src/test/java/com/syncleus/ferma/tx/TxFactoryTest.java index e9467a53..35d9e2d6 100644 --- a/src/test/java/com/syncleus/ferma/tx/TxFactoryTest.java +++ b/src/test/java/com/syncleus/ferma/tx/TxFactoryTest.java @@ -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); } } -- GitLab