diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-30 13:10:53 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-01-30 13:11:10 +0100 |
commit | 74d021d80d07c1e768a7ed4552e2483b9bf10c97 (patch) | |
tree | ff0c9eaedfcae430d9718665bf3bc2c8d7618435 /sonar-core | |
parent | 9963f42534c2ed037a0c38bb72a3815313e4fb35 (diff) | |
download | sonarqube-74d021d80d07c1e768a7ed4552e2483b9bf10c97.tar.gz sonarqube-74d021d80d07c1e768a7ed4552e2483b9bf10c97.zip |
SONAR-2501 add unit tests
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java | 9 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java | 87 |
2 files changed, 87 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java index feea6d2ac80..d0a701064d2 100644 --- a/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java +++ b/sonar-core/src/main/java/org/sonar/core/graph/GraphUtil.java @@ -63,13 +63,4 @@ public class GraphUtil { } return result; } - - public static void setNullableProperty(Element elt, String key, @Nullable Object value) { - if (value == null) { - elt.removeProperty(key); - } else { - elt.setProperty(key, value); - } - } - } diff --git a/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java b/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java new file mode 100644 index 00000000000..23bf7d657a7 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/graph/BeanGraphTest.java @@ -0,0 +1,87 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.graph; + +import com.tinkerpop.blueprints.Direction; +import com.tinkerpop.blueprints.Vertex; +import com.tinkerpop.blueprints.impls.tg.TinkerGraph; +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class BeanGraphTest { + + @Test + public void should_get_underlying_graph() { + TinkerGraph graph = new TinkerGraph(); + BeanGraph beanGraph = new BeanGraph(graph); + + assertThat(beanGraph.getUnderlyingGraph()).isSameAs(graph); + } + + @Test + public void should_create_bean_vertex() { + TinkerGraph graph = new TinkerGraph(); + BeanGraph beanGraph = new BeanGraph(graph); + Person person = beanGraph.createVertex(Person.class); + + assertThat(person).isNotNull(); + assertThat(person.element()).isNotNull(); + assertThat(person.element().getId()).isNotNull(); + assertThat(person.beanGraph()).isSameAs(beanGraph); + assertThat(person.age()).isNull(); + } + + @Test + public void should_wrap_existing_element() { + TinkerGraph graph = new TinkerGraph(); + BeanGraph beanGraph = new BeanGraph(graph); + Vertex vertex = graph.addVertex(null); + vertex.setProperty("age", 42); + + Person person = beanGraph.wrap(vertex, Person.class); + assertThat(person).isNotNull(); + assertThat(person.element()).isSameAs(vertex); + assertThat(person.age()).isEqualTo(42); + } + + @Test + public void should_create_adjacent_bean_vertex() { + TinkerGraph graph = new TinkerGraph(); + BeanGraph beanGraph = new BeanGraph(graph); + Person person = beanGraph.createVertex(Person.class); + + Person adjacent = beanGraph.createAdjacentVertex(person, Person.class, "knows", "type", "family"); + assertThat(adjacent).isNotNull(); + assertThat(person.knows()).hasSize(1); + assertThat(person.knows().iterator().next()).isSameAs(adjacent); + assertThat(adjacent.knows()).isEmpty(); + } + + static class Person extends BeanVertex { + Integer age() { + return (Integer) getProperty("age"); + } + + Iterable<Person> knows() { + return getVertices(Person.class, Direction.OUT, "knows"); + } + } +} |