attachutils npe bugfix
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
0f6e46159f
commit
d4f8cbf9df
@ -678,7 +678,8 @@ Include jenkins dockerfile in repo
|
||||
Better model for gameobjects
|
||||
Server synchronization of sprint tree
|
||||
Fix potential bad path for item state lookup
|
||||
Fix ItemUtils NPE bug + unit test
|
||||
Fix ItemUtils NPE bug
|
||||
Fix AttachUtils NPE bug
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
@ -125,4 +125,12 @@ public class EntityCreationUtils {
|
||||
Globals.clientScene.registerEntityToTag(entity, EntityTags.DRAWABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an entity for testing
|
||||
* @return The entity
|
||||
*/
|
||||
public static Entity TEST_createEntity(){
|
||||
return new Entity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -633,7 +633,13 @@ public class AttachUtils {
|
||||
* @return true if attached, false otherwise
|
||||
*/
|
||||
public static boolean isAttached(Entity e){
|
||||
return e.containsKey(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
|
||||
if(e == null){
|
||||
return false;
|
||||
}
|
||||
if(!e.containsKey(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED)){
|
||||
return false;
|
||||
}
|
||||
return (boolean)e.getData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package electrosphere.entity.types.attach;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import annotations.FastTest;
|
||||
import annotations.UnitTest;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityCreationUtils;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
|
||||
/**
|
||||
* Unit tests for attach utils
|
||||
*/
|
||||
public class AttachUtilsUnitTests {
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void isAttached_NullEntity_False(){
|
||||
boolean result = AttachUtils.isAttached(null);
|
||||
Assertions.assertEquals(false, result);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void isAttached_FalseValue_False(){
|
||||
Entity testEnt = EntityCreationUtils.TEST_createEntity();
|
||||
testEnt.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, false);
|
||||
boolean result = AttachUtils.isAttached(testEnt);
|
||||
Assertions.assertEquals(false, result);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void isAttached_NullValue_False(){
|
||||
Entity testEnt = EntityCreationUtils.TEST_createEntity();
|
||||
boolean result = AttachUtils.isAttached(testEnt);
|
||||
Assertions.assertEquals(false, result);
|
||||
}
|
||||
|
||||
@UnitTest
|
||||
@FastTest
|
||||
public void isAttached_TrueValue_True(){
|
||||
Entity testEnt = EntityCreationUtils.TEST_createEntity();
|
||||
testEnt.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true);
|
||||
boolean result = AttachUtils.isAttached(testEnt);
|
||||
Assertions.assertEquals(true, result);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user