From a25b1d54e33f5db6b522a100be856dbe5f18459a Mon Sep 17 00:00:00 2001 From: ioannispan Date: Tue, 30 Jul 2024 15:56:26 +0200 Subject: [PATCH] Remove `BaseProcTest` usage --- .../org/neo4j/gds/paths/PathFactoryTest.java | 78 ++++++++----------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/algo/src/test/java/org/neo4j/gds/paths/PathFactoryTest.java b/algo/src/test/java/org/neo4j/gds/paths/PathFactoryTest.java index 65d38faafd..17e72ca4ca 100644 --- a/algo/src/test/java/org/neo4j/gds/paths/PathFactoryTest.java +++ b/algo/src/test/java/org/neo4j/gds/paths/PathFactoryTest.java @@ -20,17 +20,17 @@ package org.neo4j.gds.paths; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.neo4j.gds.BaseProcTest; -import org.neo4j.gds.compat.GraphDatabaseApiProxy; +import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -class PathFactoryTest extends BaseProcTest { +class PathFactoryTest { @AfterEach void resetIds() { @@ -39,68 +39,54 @@ void resetIds() { @Nested class SingleNode { - static final String DB_CYPHER = "CREATE ()"; - - @BeforeEach - void setup() { - runQuery(DB_CYPHER); - } @Test void emptyPath() { var nodeIds = new long[]{0L}; var costs = new double[]{0.0D}; - GraphDatabaseApiProxy.runInFullAccessTransaction(db, tx -> { - var path = PathFactory.create( - tx::getNodeById, - nodeIds, - costs, - RelationshipType.withName("REL"), - "prop" - ); - assertEquals(0, path.length()); - }); + var path = PathFactory.create( + v-> mock(Node.class), + nodeIds, + costs, + RelationshipType.withName("REL"), + "prop" + ); + assertEquals(0, path.length()); } } @Nested class MultipleNodes { - static final String DB_CYPHER = - "CREATE" + - " (a)" + - ", (b)" + - ", (c)" + - ", (a)-[:R]->(b)" + - ", (b)-[:R]->(c)"; - - @BeforeEach - void setup() { - runQuery(DB_CYPHER); - } @Test void pathWithCosts() { var nodeIds = new long[]{0L, 1L, 2L}; var costs = new double[]{0.0D, 1.0D, 4.0D}; - GraphDatabaseApiProxy.runInFullAccessTransaction(db, tx -> { - var path = PathFactory.create( - tx::getNodeById, - nodeIds, - costs, - RelationshipType.withName("REL"), - "prop" - ); + var mockNode0 = mock(Node.class); + var mockNode1 = mock(Node.class); + var mockNode2 = mock(Node.class); + + when(mockNode0.getId()).thenReturn(nodeIds[0]); + when(mockNode1.getId()).thenReturn(nodeIds[1]); + when(mockNode2.getId()).thenReturn(nodeIds[2]); + + var path = PathFactory.create( + v -> new Node[]{mockNode0,mockNode1,mockNode2}[(int)v], + nodeIds, + costs, + RelationshipType.withName("REL"), + "prop" + ); - assertEquals(2, path.length()); + assertEquals(2, path.length()); - path.relationships().forEach(relationship -> { - var actualCost = (double) relationship.getProperty("prop"); - var expectedCost = costs[(int) relationship.getEndNodeId()] - costs[(int) relationship.getStartNodeId()]; + path.relationships().forEach(relationship -> { + var actualCost = (double) relationship.getProperty("prop"); + var expectedCost = costs[(int) relationship.getEndNodeId()] - costs[(int) relationship.getStartNodeId()]; - assertEquals(expectedCost, actualCost, 1E-4); - }); + assertEquals(expectedCost, actualCost, 1E-4); }); } }