| 1 |
|
package org.europa.together.domain; |
| 2 |
|
|
| 3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
| 4 |
|
import org.europa.together.JUnit5Preperator; |
| 5 |
|
import org.europa.together.application.LogbackLogger; |
| 6 |
|
import org.europa.together.business.Logger; |
| 7 |
|
import org.europa.together.utils.StringUtils; |
| 8 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 9 |
|
import static org.junit.jupiter.api.Assertions.*; |
| 10 |
|
import org.junit.jupiter.api.Test; |
| 11 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
| 12 |
|
|
| 13 |
|
@SuppressWarnings("unchecked") |
| 14 |
|
@ExtendWith({JUnit5Preperator.class}) |
| |
|
| 100% |
Uncovered Elements: 0 (76) |
Complexity: 10 |
Complexity Density: 0.15 |
|
| 15 |
|
public class TreeNodeTest { |
| 16 |
|
|
| 17 |
|
private static final Logger LOGGER = new LogbackLogger(TreeNodeTest.class); |
| 18 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 19 |
1 |
@Test... |
| 20 |
|
void createDomainObject() { |
| 21 |
1 |
LOGGER.log("TEST CASE: createDomainObject", LogLevel.DEBUG); |
| 22 |
|
|
| 23 |
1 |
assertThat(TreeNode.class, hasValidBeanConstructor()); |
| 24 |
1 |
assertThat(TreeNode.class, hasValidBeanHashCodeFor("nodeName")); |
| 25 |
1 |
assertThat(TreeNode.class, hasValidBeanEqualsFor("nodeName")); |
| 26 |
|
} |
| 27 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 28 |
1 |
@Test... |
| 29 |
|
void correctBeanConstruction() { |
| 30 |
1 |
LOGGER.log("TEST CASE: correctBeanConstruction", LogLevel.DEBUG); |
| 31 |
|
|
| 32 |
1 |
TreeNode<String> node_00 = new TreeNode<>(); |
| 33 |
1 |
assertNotNull(node_00.getUuid()); |
| 34 |
|
|
| 35 |
1 |
TreeNode<String> node_01 = new TreeNode<>("Node"); |
| 36 |
1 |
assertNotNull(node_01.getUuid()); |
| 37 |
1 |
assertEquals("Node", node_01.getNodeName()); |
| 38 |
|
} |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 40 |
1 |
@Test... |
| 41 |
|
void createDomainObjectBySetter() { |
| 42 |
1 |
LOGGER.log("TEST CASE: createDomainObjectBySetter", LogLevel.DEBUG); |
| 43 |
|
|
| 44 |
1 |
TreeNode<Integer> parent = new TreeNode<>(); |
| 45 |
1 |
TreeNode<Integer> node = new TreeNode<>(); |
| 46 |
1 |
node.setNodeName("name"); |
| 47 |
1 |
node.setValue(100); |
| 48 |
1 |
node.setParent(parent.getUuid()); |
| 49 |
|
|
| 50 |
1 |
assertEquals("name", node.getNodeName()); |
| 51 |
1 |
assertEquals(100, node.getValue()); |
| 52 |
1 |
assertEquals(parent.getUuid(), node.getParent()); |
| 53 |
|
} |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 55 |
1 |
@Test... |
| 56 |
|
void createDomainObjectWithDifferentValueObjects() { |
| 57 |
1 |
LOGGER.log("TEST CASE: createDomainObjectWithDifferentValueObjects", LogLevel.DEBUG); |
| 58 |
|
|
| 59 |
1 |
TreeNode<Integer> parent = new TreeNode<>(); |
| 60 |
1 |
parent.setValue(404); |
| 61 |
|
|
| 62 |
1 |
TreeNode<String> node = new TreeNode<>(); |
| 63 |
1 |
node.setNodeName("name"); |
| 64 |
1 |
node.setValue("String Object instead of the parent Integer"); |
| 65 |
1 |
node.setParent(parent.getUuid()); |
| 66 |
|
|
| 67 |
1 |
assertTrue(parent.getValue() instanceof Integer); |
| 68 |
1 |
assertTrue(node.getValue() instanceof String); |
| 69 |
|
} |
| 70 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 71 |
1 |
@Test... |
| 72 |
|
void generateToString() { |
| 73 |
1 |
LOGGER.log("TEST CASE: generateToString", LogLevel.DEBUG); |
| 74 |
|
|
| 75 |
1 |
TreeNode<String> node = new TreeNode<>("NODE"); |
| 76 |
1 |
node.setValue("string value."); |
| 77 |
1 |
String out = node.toString(); |
| 78 |
1 |
LOGGER.log("toString() " + out, LogLevel.DEBUG); |
| 79 |
1 |
assertEquals(out, node.toString()); |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 82 |
1 |
@Test... |
| 83 |
|
void equalByCopy() { |
| 84 |
1 |
LOGGER.log("TEST CASE: equalByCopy", LogLevel.DEBUG); |
| 85 |
|
|
| 86 |
1 |
TreeNode<String> node_01 = new TreeNode<>("cloend"); |
| 87 |
1 |
node_01.setParent(StringUtils.generateUUID()); |
| 88 |
1 |
node_01.setValue("string value"); |
| 89 |
|
|
| 90 |
1 |
TreeNode<String> node_02 = node_01.copy(node_01); |
| 91 |
|
|
| 92 |
1 |
assertEquals(node_01, node_02); |
| 93 |
1 |
assertEquals(node_01.getValue(), node_02.getValue()); |
| 94 |
|
} |
| 95 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 96 |
1 |
@Test... |
| 97 |
|
void notEqualByCopyAndManipulate() { |
| 98 |
1 |
LOGGER.log("TEST CASE: notEqualByCopyAndManipulate", LogLevel.DEBUG); |
| 99 |
|
|
| 100 |
1 |
TreeNode<String> node_01 = new TreeNode<>("node x"); |
| 101 |
1 |
node_01.setNodeName("node 1"); |
| 102 |
1 |
node_01.setParent(StringUtils.generateUUID()); |
| 103 |
|
|
| 104 |
1 |
TreeNode<String> node_02 = node_01.copy(node_01); |
| 105 |
1 |
node_02.setNodeName("node 2"); |
| 106 |
|
|
| 107 |
1 |
LOGGER.log("Node: " + node_02.toString(), LogLevel.DEBUG); |
| 108 |
1 |
LOGGER.log("Node: " + node_01.toString(), LogLevel.DEBUG); |
| 109 |
|
|
| 110 |
1 |
assertNotEquals(node_01, node_02); |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 113 |
1 |
@Test... |
| 114 |
|
void equalByDiffrentUuid() { |
| 115 |
1 |
LOGGER.log("TEST CASE: equalByDiffrentUuid", LogLevel.DEBUG); |
| 116 |
|
|
| 117 |
1 |
TreeNode<Boolean> a = new TreeNode<>(""); |
| 118 |
1 |
TreeNode<Boolean> b = new TreeNode<>(""); |
| 119 |
|
|
| 120 |
1 |
assertTrue(a.equals(b)); |
| 121 |
1 |
assertEquals(a, b); |
| 122 |
|
} |
| 123 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 124 |
1 |
@Test... |
| 125 |
|
void notEqualBySameRootAndDiffrentName() { |
| 126 |
1 |
LOGGER.log("TEST CASE: notEqualDefaultCompare", LogLevel.DEBUG); |
| 127 |
|
|
| 128 |
1 |
TreeNode<Boolean> root = new TreeNode<>("root"); |
| 129 |
1 |
TreeNode<Boolean> node_01 = new TreeNode<>("node A"); |
| 130 |
1 |
node_01.setParent(root.getUuid()); |
| 131 |
1 |
TreeNode<Boolean> node_02 = new TreeNode<>("node B"); |
| 132 |
1 |
node_02.setParent(root.getUuid()); |
| 133 |
|
|
| 134 |
1 |
assertNotEquals(node_01, node_02); |
| 135 |
1 |
assertFalse(node_01.equals(node_02)); |
| 136 |
|
} |
| 137 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 138 |
1 |
@Test... |
| 139 |
|
void notEqualByNull() { |
| 140 |
1 |
LOGGER.log("TEST CASE: notEqualByNull", LogLevel.DEBUG); |
| 141 |
|
|
| 142 |
1 |
TreeNode<?> node_01 = new TreeNode<>("node A"); |
| 143 |
1 |
assertFalse(node_01.equals(null)); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
} |