Files
Gruppe-01-fin/Projekte/jme-common/src/test/java/pp/view/ModelViewSynchronizerTest.java
Timo Brennförder 8c45784246 Code cleanup
added JavaDocs
removed unnecessary lines
2024-10-13 01:59:46 +02:00

82 lines
2.1 KiB
Java

package pp.view;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ModelViewSynchronizerTest {
private Node rootNode;
private Node itemNode;
private ModelViewSynchronizer<String> synchronizer;
@Before
public void setUp() {
rootNode = new Node("root"); //NON-NLS
synchronizer = new ModelViewSynchronizer<>(rootNode) {
@Override
protected Spatial translate(String item) {
return new Node(item);
}
};
itemNode = (Node) rootNode.getChild(0);
}
@Test
public void testConstructor() {
assertNotNull(itemNode);
assertEquals(1, rootNode.getQuantity());
}
@Test
public void testAdd() {
String item = "item1"; //NON-NLS
synchronizer.add(item);
Spatial spatial = synchronizer.getSpatial(item);
assertNotNull(spatial);
assertEquals(item, spatial.getName());
assertTrue(itemNode.hasChild(spatial));
}
@Test
public void testDelete() {
String item = "item1"; //NON-NLS
synchronizer.add(item);
synchronizer.delete(item);
Spatial spatial = synchronizer.getSpatial(item);
assertNull(spatial);
assertFalse(itemNode.hasChild(spatial));
}
@Test
public void testClear() {
synchronizer.add("item1"); //NON-NLS
synchronizer.add("item2"); //NON-NLS
synchronizer.clear();
assertNull(synchronizer.getSpatial("item1")); //NON-NLS
assertNull(synchronizer.getSpatial("item2")); //NON-NLS
assertEquals(0, itemNode.getQuantity());
}
@Test
public void testAddDuplicate() {
String item = "item1"; //NON-NLS
synchronizer.add(item);
synchronizer.add(item);
assertEquals(1, itemNode.getQuantity());
}
}