first set of tests for the Geometry. There's 18 tests in total, covering roughly 40% of the total number of methods in the geometry class.

To get all the tests to run, I needed to add EasyMock and some related jar files. This enables me to mock classes other the the one actually being tested to get a better test isolation.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10646 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rac..om 12 years ago
parent 96006f1383
commit 9b8060bac2
  1. BIN
      engine/lib/EasyMock/cglib-docs-2.2.3.jar
  2. BIN
      engine/lib/EasyMock/cglib-nodep-2.2.3.jar
  3. BIN
      engine/lib/EasyMock/cglib-src-2.2.3.jar
  4. BIN
      engine/lib/EasyMock/easymock-3.1-javadoc.jar
  5. BIN
      engine/lib/EasyMock/easymock-3.1-sources.jar
  6. BIN
      engine/lib/EasyMock/easymock-3.1.jar
  7. BIN
      engine/lib/EasyMock/objenesis-1.3-javadoc.jar
  8. BIN
      engine/lib/EasyMock/objenesis-1.3-sources.jar
  9. BIN
      engine/lib/EasyMock/objenesis-1.3.jar
  10. 12
      engine/lib/nblibraries.properties
  11. 5
      engine/nbproject/project.properties
  12. 178
      engine/test/com/jme3/scene/GeometryTest.java

@ -6,6 +6,18 @@ libs.CopyLibs.classpath=\
${base}/CopyLibs-2/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=1.0
libs.EasyMock.classpath=\
${base}/EasyMock/easymock-3.1.jar:\
${base}/EasyMock/objenesis-1.3.jar:\
${base}/EasyMock/cglib-nodep-2.2.3.jar
libs.EasyMock.displayName=EasyMock
libs.EasyMock.javadoc=\
${base}/EasyMock/easymock-3.1-javadoc.jar!//:\
${base}/EasyMock/objenesis-1.3-javadoc.jar!//
libs.EasyMock.src=\
${base}/EasyMock/easymock-3.1-sources.jar!//:\
${base}/EasyMock/objenesis-1.3-sources.jar!//:\
${base}/EasyMock/cglib-src-2.2.3.jar!/src/test/
libs.jbullet.classpath=\
${base}/jbullet/jbullet.jar:\
${base}/jbullet/stack-alloc.jar:\

@ -69,8 +69,8 @@ javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${libs.junit_4.classpath}:\
${libs.EasyMock.classpath}:\
${javac.classpath}:\
${build.classes.dir}:\
${file.reference.build-android}:\
${file.reference.build-blender}:\
${file.reference.build-bullet}:\
@ -87,7 +87,8 @@ javac.test.classpath=\
${file.reference.build-networking}:\
${file.reference.build-niftygui}:\
${file.reference.build-plugins}:\
${file.reference.build-terrain}
${file.reference.build-terrain}:\
${build.classes.dir}
javadoc.additionalparam=-protected
javadoc.author=false
javadoc.encoding=${source.encoding}

@ -0,0 +1,178 @@
package com.jme3.scene;
import com.jme3.bounding.BoundingVolume;
import com.jme3.material.Material;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import org.junit.Test;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
public class GeometryTest {
@Test
public void testConstructorNameNull() {
Geometry geom = new Geometry(null);
assertNull(geom.getName());
}
@Test
public void testConstructorName() {
Geometry geom = new Geometry("TestGeometry");
assertEquals("TestGeometry", geom.getName());
}
@Test(expected = NullPointerException.class)
public void testConstructorNameMeshNullMesh() {
Geometry geom = new Geometry("TestGeometry", null);
}
@Test
public void testConstructorNameMesh() {
Mesh m = new Mesh();
Geometry geom = new Geometry("TestGeometry", m);
assertEquals("TestGeometry", geom.getName());
assertEquals(m, geom.getMesh());
}
@Test(expected = IllegalStateException.class)
public void testSetLodLevelMeshLodZero() {
Mesh m = new Mesh();
Geometry geom = new Geometry("TestGeometry", m);
geom.setLodLevel(0);
}
@Test(expected = IllegalArgumentException.class)
public void testSetLodLevelLodLessZero() {
Mesh m = new Mesh();
VertexBuffer lodLevels = new VertexBuffer(VertexBuffer.Type.Size);
m.setLodLevels(new VertexBuffer[]{lodLevels});
Geometry geom = new Geometry("TestGeometry", m);
geom.setLodLevel(-1);
}
@Test(expected = IllegalArgumentException.class)
public void testSetLodLevelLodGreaterMeshLod() {
Mesh m = new Mesh();
VertexBuffer lodLevel = new VertexBuffer(VertexBuffer.Type.Size);
m.setLodLevels(new VertexBuffer[]{lodLevel});
Geometry geom = new Geometry("TestGeometry", m);
geom.setLodLevel(5);
}
@Test
public void testSetLodLevel() {
Mesh m = new Mesh();
VertexBuffer lodLevel = new VertexBuffer(VertexBuffer.Type.Size);
m.setLodLevels(new VertexBuffer[]{lodLevel, lodLevel, lodLevel});
Geometry geom = new Geometry("TestGeometry", m);
geom.setLodLevel(2);
assertEquals(2, geom.getLodLevel());
}
@Test(expected = IllegalArgumentException.class)
public void testSetMeshNull() {
Geometry geom = new Geometry();
geom.setMesh(null);
}
@Test(expected = UnsupportedOperationException.class)
public void testSetMeshBatched() {
Mesh m = new Mesh();
Geometry geom = new Geometry();
BatchNode bn = new BatchNode();
geom.batch(bn, 1);
geom.setMesh(m);
}
@Test
public void testSetMesh() {
Mesh m = new Mesh();
Geometry geom = new Geometry();
geom.setMesh(m);
assertEquals(m, geom.getMesh());
}
@Test(expected = UnsupportedOperationException.class)
public void testSetMaterialBatched() {
Material m = new Material();
Geometry geom = new Geometry();
BatchNode bn = new BatchNode();
geom.batch(bn, 1);
geom.setMaterial(m);
}
@Test
public void testSetMaterial() {
Material m = new Material();
Geometry geom = new Geometry();
geom.setMaterial(m);
assertEquals(m, geom.getMaterial());
}
@Test
public void testUpdateModelBound() {
Mesh mockedMesh = createMock(Mesh.class);
mockedMesh.updateBound();
expectLastCall();
replay(mockedMesh);
Geometry geom = new Geometry();
geom.setMesh(mockedMesh);
geom.updateModelBound();
verify(mockedMesh);
}
@Test(expected = NullPointerException.class)
public void testUpdateWorldBoundNoMesh() {
Geometry geom = new Geometry();
geom.updateWorldBound();
}
@Test
public void testUpdateWorlBoundNoBoundingVolume() {
Mesh mockedMesh = createMock(Mesh.class);
expect(mockedMesh.getBound()).andReturn(null);
replay(mockedMesh);
Geometry geom = new Geometry();
geom.setMesh(mockedMesh);
geom.updateWorldBound();
verify(mockedMesh);
}
@Test
public void testUpdateWorlBoundIgnoreTransform() {
Mesh mockedMesh = createMock(Mesh.class);
BoundingVolume mockedBoundingVolume = createMock(BoundingVolume.class);
expect(mockedMesh.getBound()).andReturn(mockedBoundingVolume).times(2);
expect(mockedBoundingVolume.clone(null)).andReturn(null);
replay(mockedMesh, mockedBoundingVolume);
Geometry geom = new Geometry();
geom.setMesh(mockedMesh);
geom.setIgnoreTransform(true);
geom.updateWorldBound();
verify(mockedMesh, mockedBoundingVolume);
}
@Test
public void testUpdateWorlBoundTransform() {
Mesh mockedMesh = createMock(Mesh.class);
BoundingVolume mockedBoundingVolume = createMock(BoundingVolume.class);
expect(mockedMesh.getBound()).andReturn(mockedBoundingVolume).times(2);
expect(mockedBoundingVolume.transform(anyObject(Transform.class), same((BoundingVolume) null))).andReturn(null);
replay(mockedMesh, mockedBoundingVolume);
Geometry geom = new Geometry();
geom.setMesh(mockedMesh);
geom.setIgnoreTransform(false);
geom.updateWorldBound();
verify(mockedMesh, mockedBoundingVolume);
}
}
Loading…
Cancel
Save