diff --git a/common.gradle b/common.gradle old mode 100644 new mode 100755 diff --git a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java old mode 100644 new mode 100755 index 991ad25c0ae..28122b9ca47 --- a/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java +++ b/jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java @@ -57,6 +57,10 @@ import com.jme3.renderer.opengl.GLFbo; import com.jme3.renderer.opengl.GLRenderer; import com.jme3.system.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -278,6 +282,20 @@ public TouchInput getTouchInput() { return androidInput.getTouchInput(); } + @Override + public java.util.List getInput() { + List inputs = new ArrayList<>(); + + inputs.add(getKeyInput()); + inputs.add(getMouseInput()); + if(!settings.getBoolean("DisableJoysticks")) { + inputs.add(getJoyInput()); + } + inputs.add(getTouchInput()); + inputs.removeAll(Collections.singleton(null)); + + return inputs; + } @Override public Timer getTimer() { return timer; diff --git a/jme3-core/src/main/java/com/jme3/app/Application.java b/jme3-core/src/main/java/com/jme3/app/Application.java index 475193bfe52..b0802bd87af 100755 --- a/jme3-core/src/main/java/com/jme3/app/Application.java +++ b/jme3-core/src/main/java/com/jme3/app/Application.java @@ -48,6 +48,7 @@ import com.jme3.system.JmeContext.Type; import java.net.MalformedURLException; import java.net.URL; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Future; @@ -86,10 +87,8 @@ public class Application implements SystemListener { protected LostFocusBehavior lostFocusBehavior = LostFocusBehavior.ThrottleOnLostFocus; protected float speed = 1f; protected boolean paused = false; - protected MouseInput mouseInput; - protected KeyInput keyInput; - protected JoyInput joyInput; - protected TouchInput touchInput; + + protected List inputs; protected InputManager inputManager; protected AppStateManager stateManager; @@ -173,6 +172,10 @@ public void setAssetManager(AssetManager assetManager){ this.assetManager = assetManager; } + public void setInputManager(InputManager inputManager) { + this.inputManager = inputManager; + } + private void initAssetManager(){ URL assetCfgUrl = null; @@ -306,25 +309,8 @@ private void initCamera(){ * AppSettings. */ protected void initInput(){ - mouseInput = context.getMouseInput(); - if (mouseInput != null) - mouseInput.initialize(); - - keyInput = context.getKeyInput(); - if (keyInput != null) - keyInput.initialize(); - - touchInput = context.getTouchInput(); - if (touchInput != null) - touchInput.initialize(); - - if (!settings.getBoolean("DisableJoysticks")){ - joyInput = context.getJoyInput(); - if (joyInput != null) - joyInput.initialize(); - } - - inputManager = new InputManager(mouseInput, keyInput, joyInput, touchInput); + inputs = context.getInput(); + inputManager = new InputManager(inputs); } private void initStateManager(){ @@ -715,18 +701,7 @@ public void update(){ } protected void destroyInput(){ - if (mouseInput != null) - mouseInput.destroy(); - - if (keyInput != null) - keyInput.destroy(); - - if (joyInput != null) - joyInput.destroy(); - - if (touchInput != null) - touchInput.destroy(); - + inputManager.destroyInput(); inputManager = null; } diff --git a/jme3-core/src/main/java/com/jme3/input/InputManager.java b/jme3-core/src/main/java/com/jme3/input/InputManager.java old mode 100644 new mode 100755 index b21d225bbc2..79af9511b34 --- a/jme3-core/src/main/java/com/jme3/input/InputManager.java +++ b/jme3-core/src/main/java/com/jme3/input/InputManager.java @@ -42,6 +42,7 @@ import com.jme3.util.SafeArrayList; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -89,6 +90,7 @@ public class InputManager implements RawInputListener { private final MouseInput mouse; private final JoyInput joystick; private final TouchInput touch; + private final List inputs; private float frameTPF; private long lastLastUpdateTime = 0; private long lastUpdateTime = 0; @@ -123,32 +125,43 @@ public Mapping(String name) { * *
This should only be called internally in {@link Application}.
*
- * @param mouse
- * @param keys
- * @param joystick
- * @param touch
+ * @param inputs
* @throws IllegalArgumentException If either mouseInput or keyInput are null.
*/
- public InputManager(MouseInput mouse, KeyInput keys, JoyInput joystick, TouchInput touch) {
+ public InputManager(List inputs) {
+ KeyInput keys = null;
+ MouseInput mouse = null;
+ JoyInput joystick = null;
+ TouchInput touch = null;
+
+ for (Input input : inputs) {
+ input.initialize();
+ if(input instanceof MouseInput) {
+ mouse = (MouseInput) input;
+ mouse.setInputListener(this);
+ } else if (input instanceof KeyInput) {
+ keys = (KeyInput) input;
+ keys.setInputListener(this);
+ } else if (input instanceof JoyInput) {
+ joystick = (JoyInput) input;
+ joystick.setInputListener(this);
+ joysticks = joystick.loadJoysticks(this);
+ } else if (input instanceof TouchInput) {
+ touch = (TouchInput) input;
+ touch.setInputListener(this);
+ }
+ }
+
if (keys == null || mouse == null) {
throw new IllegalArgumentException("Mouse or keyboard cannot be null");
}
+ this.inputs = inputs;
this.keys = keys;
this.mouse = mouse;
this.joystick = joystick;
this.touch = touch;
- keys.setInputListener(this);
- mouse.setInputListener(this);
- if (joystick != null) {
- joystick.setInputListener(this);
- joysticks = joystick.loadJoysticks(this);
- }
- if (touch != null) {
- touch.setInputListener(this);
- }
-
firstTime = keys.getInputTimeNanos();
}
@@ -893,13 +906,8 @@ public void update(float tpf) {
eventsPermitted = true;
- keys.update();
- mouse.update();
- if (joystick != null) {
- joystick.update();
- }
- if (touch != null) {
- touch.update();
+ for(Input input : inputs){
+ input.update();
}
eventsPermitted = false;
@@ -946,4 +954,30 @@ public void onTouchEvent(TouchEvent evt) {
cursorPos.set(evt.getX(), evt.getY());
inputQueue.add(evt);
}
+
+ public void destroyInput() {
+ for(Input input : inputs){
+ input.destroy();
+ }
+ }
+
+ public List getInputs() {
+ return inputs;
+ }
+
+ public TouchInput getTouch() {
+ return touch;
+ }
+
+ public JoyInput getJoystick() {
+ return joystick;
+ }
+
+ public MouseInput getMouse() {
+ return mouse;
+ }
+
+ public KeyInput getKeys() {
+ return keys;
+ }
}
diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java
old mode 100644
new mode 100755
diff --git a/jme3-core/src/main/java/com/jme3/system/JmeContext.java b/jme3-core/src/main/java/com/jme3/system/JmeContext.java
old mode 100644
new mode 100755
index f4f47ae679d..cda9ac7211f
--- a/jme3-core/src/main/java/com/jme3/system/JmeContext.java
+++ b/jme3-core/src/main/java/com/jme3/system/JmeContext.java
@@ -31,17 +31,15 @@
*/
package com.jme3.system;
-import com.jme3.input.JoyInput;
-import com.jme3.input.KeyInput;
-import com.jme3.input.MouseInput;
-import com.jme3.input.TouchInput;
+import com.jme3.input.*;
import com.jme3.renderer.Renderer;
+import java.util.List;
+
/**
* Represents a rendering context within the engine.
*/
public interface JmeContext {
-
/**
* The type of context.
*/
@@ -110,6 +108,11 @@ public enum Type {
*/
public Renderer getRenderer();
+ /**
+ * @return All input implementations. May be empty if not available.
+ */
+ public List getInput();
+
/**
* @return Mouse input implementation. May be null if not available.
*/
diff --git a/jme3-core/src/main/java/com/jme3/system/NullContext.java b/jme3-core/src/main/java/com/jme3/system/NullContext.java
old mode 100644
new mode 100755
index 41204e6c98d..0b9c4ac1777
--- a/jme3-core/src/main/java/com/jme3/system/NullContext.java
+++ b/jme3-core/src/main/java/com/jme3/system/NullContext.java
@@ -31,13 +31,14 @@
*/
package com.jme3.system;
-import com.jme3.input.JoyInput;
-import com.jme3.input.KeyInput;
-import com.jme3.input.MouseInput;
-import com.jme3.input.TouchInput;
+import com.jme3.input.*;
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.renderer.Renderer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -58,6 +59,8 @@ public class NullContext implements JmeContext, Runnable {
protected SystemListener listener;
protected NullRenderer renderer;
+ protected List inputs;
+
public Type getType() {
return Type.Headless;
}
@@ -175,6 +178,20 @@ public JoyInput getJoyInput() {
return null;
}
+ public java.util.List getInput() {
+ if(inputs == null) {
+ inputs = new ArrayList<>();
+ inputs.add(getKeyInput());
+ inputs.add(getMouseInput());
+ if(!settings.getBoolean("DisableJoysticks")) {
+ inputs.add(getJoyInput());
+ }
+ inputs.add(getTouchInput());
+ inputs.removeAll(Collections.singleton(null));
+ }
+ return inputs;
+ }
+
public TouchInput getTouchInput() {
return null;
}
diff --git a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java
old mode 100644
new mode 100755
index 55f1c77ac74..cd824c0ee8e
--- a/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java
+++ b/jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java
@@ -34,18 +34,17 @@
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.texture.Image;
-import org.fest.util.VisibleForTesting;
import java.nio.ByteBuffer;
public class DefaultImageRaster extends ImageRaster {
- @VisibleForTesting
+
protected final int[] components = new int[4];
private ByteBuffer buffer;
- @VisibleForTesting
+
protected final Image image;
- @VisibleForTesting
+
protected final ImageCodec codec;
private final int width;
private final int height;
@@ -55,7 +54,7 @@ public class DefaultImageRaster extends ImageRaster {
private int slice;
- @VisibleForTesting
+
protected void rangeCheck(int x, int y) {
if (x < 0 || y < 0 || x >= width || y >= height) {
throw new IllegalArgumentException("x and y must be inside the image dimensions:"
@@ -133,19 +132,19 @@ public void setPixel(int x, int y, ColorRGBA color) {
* Input is linear, needs to be converted to sRGB before writing into image.
* @param color
*/
- @VisibleForTesting
+
protected void getSRGB(ColorRGBA color) {
if (convertToLinear) {
color = color.getAsSrgb();
}
}
- @VisibleForTesting
+
protected void writeComponents(int x, int y) {
codec.writeComponents(getBuffer(), x, y, width, offset, components, temp);
}
- @VisibleForTesting
+
protected void readComponents(int x, int y) {
codec.readComponents(getBuffer(), x, y, width, offset, components, temp);
}
@@ -171,7 +170,7 @@ public ColorRGBA getPixel(int x, int y, ColorRGBA store) {
return store;
}
- @VisibleForTesting
+
protected void setSRGB(ColorRGBA store) {
if (convertToLinear) {
// Input image is sRGB, need to convert to linear.
diff --git a/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java
old mode 100644
new mode 100755
index 121bab62ef6..e3f3e08f589
--- a/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java
+++ b/jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java
@@ -35,7 +35,6 @@
import com.jme3.math.FastMath;
import com.jme3.system.JmeSystem;
import com.jme3.texture.Image;
-import org.fest.util.VisibleForTesting;
/**
* Utility class for reading and writing from jME3 {@link Image images}.
@@ -210,7 +209,6 @@ public ColorRGBA getPixel(int x, int y) {
* Check flags for grayscale
* @param color
*/
- @VisibleForTesting
protected void grayscaleCheck(ColorRGBA color, ImageCodec codec) {
if (codec.isGray) {
float gray = color.r * 0.27f + color.g * 0.67f + color.b * 0.06f;
@@ -218,7 +216,6 @@ protected void grayscaleCheck(ColorRGBA color, ImageCodec codec) {
}
}
- @VisibleForTesting
protected void setComponents(ColorRGBA color, ImageCodec codec, int[] components) {
switch (codec.type) {
case ImageCodec.FLAG_F16:
@@ -247,7 +244,6 @@ protected void setImageUpdateNeeded(Image image) {
image.setUpdateNeeded();
}
- @VisibleForTesting
protected void setStoreComponents(ColorRGBA store, ImageCodec codec, int[] components) {
switch (codec.type) {
case ImageCodec.FLAG_F16:
@@ -272,7 +268,6 @@ protected void setStoreComponents(ColorRGBA store, ImageCodec codec, int[] compo
}
}
- @VisibleForTesting
protected void setStoreRGBA(ColorRGBA store, ImageCodec codec) {
if (codec.isGray) {
store.g = store.b = store.r;
diff --git a/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java b/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java
old mode 100644
new mode 100755
index eda9e02605c..bb2402f62a5
--- a/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java
+++ b/jme3-core/src/main/java/com/jme3/texture/image/MipMapImageRaster.java
@@ -34,18 +34,17 @@
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.texture.Image;
-import org.fest.util.VisibleForTesting;
import java.nio.ByteBuffer;
public class MipMapImageRaster extends ImageRaster {
- @VisibleForTesting
+
protected final int[] components = new int[4];
private ByteBuffer buffer;
- @VisibleForTesting
+
protected final Image image;
- @VisibleForTesting
+
protected final ImageCodec codec;
private int width[];
private int height[];
@@ -54,7 +53,7 @@ public class MipMapImageRaster extends ImageRaster {
private int mipLevel;
private int[] offsets;
- @VisibleForTesting
+
protected void rangeCheck(int x, int y) {
if (x < 0 || y < 0 || x >= width[mipLevel] || y >= height[mipLevel]) {
throw new IllegalArgumentException("x and y must be inside the image dimensions");
@@ -111,12 +110,12 @@ public void setPixel(int x, int y, ColorRGBA color) {
setImageUpdateNeeded(image);
}
- @VisibleForTesting
+
protected void writeComponents(int x, int y) {
codec.writeComponents(getBuffer(), x, y, width[mipLevel], offsets[mipLevel], components, temp);
}
- @VisibleForTesting
+
protected void readComponents(int x, int y) {
codec.readComponents(getBuffer(), x, y, width[mipLevel], offsets[mipLevel], components, temp);
}
diff --git a/jme3-core/src/main/resources/com/jme3/system/version.properties b/jme3-core/src/main/resources/com/jme3/system/version.properties
index 6a18aebb503..11ba02daf24 100644
--- a/jme3-core/src/main/resources/com/jme3/system/version.properties
+++ b/jme3-core/src/main/resources/com/jme3/system/version.properties
@@ -1,23 +1,12 @@
# THIS IS AN AUTO-GENERATED FILE..
# DO NOT MODIFY!
-<<<<<<< 9873a76327519d60380864617c1c74f58802b99c
-build.date=2016-03-21
-git.revision=5389
-git.branch=test-texture
-git.hash=b99b43942ed5cf2b922c2268161efb413cc721d6
-git.hash.short=b99b439
-git.tag=v3.1-alpha1-231-gb99b439
-name.full=jMonkeyEngine 3.1-test-texture-5389
-version.full=3.1-test-texture-5389
-=======
-build.date=2016-03-22
-git.revision=5475
-git.branch=master
-git.hash=10947e8b5096f6d7e2bf0e327faa43b275adeb34
-git.hash.short=10947e8
+build.date=2016-04-03
+git.revision=5496
+git.branch=application-input-DIP
+git.hash=85ccf353a95329daff30dc60304532fcc63a5f4b
+git.hash.short=85ccf35
git.tag=null
-name.full=jMonkeyEngine 3.1-5475
-version.full=3.1-5475
->>>>>>> Init input Application tests
+name.full=jMonkeyEngine 3.1-application-input-DIP-5496
+version.full=3.1-application-input-DIP-5496
version.number=3.1.0
version.tag=SNAPSHOT
\ No newline at end of file
diff --git a/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java b/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
index 43abdb4705b..4c8cfa7f870 100755
--- a/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
+++ b/jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
@@ -1,113 +1 @@
-package com.jme3.app;
-
-import com.jme3.input.JoyInput;
-import com.jme3.input.KeyInput;
-import com.jme3.input.MouseInput;
-import com.jme3.input.TouchInput;
-import com.jme3.input.dummy.DummyKeyInput;
-import com.jme3.input.dummy.DummyMouseInput;
-import com.jme3.system.AppSettings;
-import com.jme3.system.NullContext;
-import com.jme3.texture.Texture;
-import org.junit.Before;
-import org.junit.Test;
-import static org.mockito.Mockito.*;
-import java.io.IOException;
-import java.security.Key;
-
-import static org.junit.Assert.*;
-
-
-public class ApplicationTest {
-
- Application app;
-
- @Before
- public void setUp() {
- app = new TestApplication();
- }
-
- @Test
- public void testDestroyInput() throws Exception {
-
- }
-
- @Test
- public void testInitInputWithJoyStick() throws Exception {
- //setup settings
- AppSettings settings = new AppSettings(true);
- settings.setUseJoysticks(true);
- app.setSettings(settings);
-
- //setup app
- Application spyApp = spy(app);
- assertNull(spyApp.getInputManager());
-
- //setup context
- NullContext spyContext = spy(new NullContext());
- MouseInput spyMouseInput = spy(new DummyMouseInput());
- KeyInput spyKeyInput = spy(new DummyKeyInput());
- TouchInput spyTouchInput = spy(new TestTouchInput());
- JoyInput spyJoyInput = spy(new TestJoyInput());
- doReturn(spyMouseInput).when(spyContext).getMouseInput();
- doReturn(spyKeyInput).when(spyContext).getKeyInput();
- doReturn(spyTouchInput).when(spyContext).getTouchInput();
- doReturn(spyJoyInput).when(spyContext).getJoyInput();
- spyApp.context = spyContext;
-
- spyApp.initInput();
-
- verify(spyContext, times(1)).getMouseInput();
- verify(spyMouseInput, times(1)).initialize();
- verify(spyContext, times(1)).getKeyInput();
- verify(spyKeyInput, times(1)).initialize();
- verify(spyContext, times(1)).getTouchInput();
- verify(spyTouchInput, times(1)).initialize();
- verify(spyContext, times(1)).getJoyInput();
- verify(spyJoyInput, times(1)).initialize();
-
- //verify(spyContext, times(1)).getJoyInput();
-
- assertNotNull(spyApp.getInputManager());
- }
-
- @Test
- public void testInitInputNoJoyStick() throws Exception {
- //setup settings
- AppSettings settings = new AppSettings(true);
- settings.setUseJoysticks(false);
- app.setSettings(settings);
-
- //setup app
- Application spyApp = spy(app);
- assertNull(spyApp.getInputManager());
-
- //setup context
- NullContext spyContext = spy(new NullContext());
- MouseInput spyMouseInput = spy(new DummyMouseInput());
- KeyInput spyKeyInput = spy(new DummyKeyInput());
- TouchInput spyTouchInput = spy(new TestTouchInput());
- JoyInput spyJoyInput = spy(new TestJoyInput());
- doReturn(spyMouseInput).when(spyContext).getMouseInput();
- doReturn(spyKeyInput).when(spyContext).getKeyInput();
- doReturn(spyTouchInput).when(spyContext).getTouchInput();
- doReturn(spyJoyInput).when(spyContext).getJoyInput();
- spyApp.context = spyContext;
-
- spyApp.initInput();
-
- verify(spyContext, times(1)).getMouseInput();
- verify(spyMouseInput, times(1)).initialize();
- verify(spyContext, times(1)).getKeyInput();
- verify(spyKeyInput, times(1)).initialize();
- verify(spyContext, times(1)).getTouchInput();
- verify(spyTouchInput, times(1)).initialize();
- verify(spyContext, times(0)).getJoyInput();
- verify(spyJoyInput, times(0)).initialize();
-
- //verify(spyContext, times(1)).getJoyInput();
-
- assertNotNull(spyApp.getInputManager());
- }
-
-}
\ No newline at end of file
+package com.jme3.app;
import com.jme3.input.*;
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.system.AppSettings;
import com.jme3.system.NullContext;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
public class ApplicationTest {
Application app;
@Before
public void setUp() {
app = new TestApplication();
}
@Test
public void testInitInput() throws Exception {
//setup settings
AppSettings settings = new AppSettings(true);
app.setSettings(settings);
//setup app
Application spyApp = spy(app);
assertNull(spyApp.getInputManager());
//setup context
NullContext spyContext = spy(new NullContext());
spyApp.context = spyContext;
List expectedInputs = spyContext.getInput();
spyApp.initInput();
//verify
InputManager actualInputManager = spyApp.getInputManager();
List actualInputs = actualInputManager.getInputs();
assertNotNull(actualInputManager);
assertThat(actualInputs, is(expectedInputs));
}
/**
* Test from before the refactor. Should still pass
* @throws Exception
*/
@Test
public void testInitInputNoJoyStick() throws Exception {
//setup settings
AppSettings settings = new AppSettings(true);
settings.setUseJoysticks(false);
app.setSettings(settings);
//setup app
Application spyApp = spy(app);
assertNull(spyApp.getInputManager());
//setup context
NullContext spyContext = spy(new NullContext());
MouseInput spyMouseInput = spy(new DummyMouseInput());
KeyInput spyKeyInput = spy(new DummyKeyInput());
TouchInput spyTouchInput = spy(new TestTouchInput());
JoyInput spyJoyInput = spy(new TestJoyInput());
doReturn(spyMouseInput).when(spyContext).getMouseInput();
doReturn(spyKeyInput).when(spyContext).getKeyInput();
doReturn(spyTouchInput).when(spyContext).getTouchInput();
doReturn(spyJoyInput).when(spyContext).getJoyInput();
spyApp.context = spyContext;
spyApp.initInput();
verify(spyContext, times(1)).getMouseInput();
verify(spyMouseInput, times(1)).initialize();
verify(spyContext, times(1)).getKeyInput();
verify(spyKeyInput, times(1)).initialize();
verify(spyContext, times(1)).getTouchInput();
verify(spyTouchInput, times(1)).initialize();
verify(spyContext, times(0)).getJoyInput();
verify(spyJoyInput, times(0)).initialize();
assertNotNull(spyApp.getInputManager());
}
/**
* Test from before the refactor. Should still pass
* @throws Exception
*/
@Test
public void testInitInputWithJoyStick() throws Exception {
//setup settings
AppSettings settings = new AppSettings(true);
settings.setUseJoysticks(true);
app.setSettings(settings);
//setup app
Application spyApp = spy(app);
assertNull(spyApp.getInputManager());
//setup context
NullContext spyContext = spy(new NullContext());
MouseInput spyMouseInput = spy(new DummyMouseInput());
KeyInput spyKeyInput = spy(new DummyKeyInput());
TouchInput spyTouchInput = spy(new TestTouchInput());
JoyInput spyJoyInput = spy(new TestJoyInput());
doReturn(spyMouseInput).when(spyContext).getMouseInput();
doReturn(spyKeyInput).when(spyContext).getKeyInput();
doReturn(spyTouchInput).when(spyContext).getTouchInput();
doReturn(spyJoyInput).when(spyContext).getJoyInput();
spyApp.context = spyContext;
spyContext.setSettings(settings);
spyApp.initInput();
verify(spyContext, times(1)).getMouseInput();
verify(spyMouseInput, times(1)).initialize();
verify(spyContext, times(1)).getKeyInput();
verify(spyKeyInput, times(1)).initialize();
verify(spyContext, times(1)).getTouchInput();
verify(spyTouchInput, times(1)).initialize();
verify(spyContext, times(1)).getJoyInput();
verify(spyJoyInput, times(1)).initialize();
assertNotNull(spyApp.getInputManager());
}
@Test
public void testDestroyInput() throws Exception {
//setup settings
AppSettings settings = new AppSettings(true);
app.setSettings(settings);
//setup app
app.context = new NullContext();
InputManager spyInputManager = spy(new InputManager(app.getContext().getInput()));
app.setInputManager(spyInputManager);
assertNotNull(app.getInputManager());
app.destroyInput();
verify(spyInputManager, times(1)).destroyInput();
assertNull(app.getInputManager());
}
}
\ No newline at end of file
diff --git a/jme3-core/src/main/java/com/jme3/app/TestApplication.java b/jme3-core/src/test/java/com/jme3/app/TestApplication.java
similarity index 100%
rename from jme3-core/src/main/java/com/jme3/app/TestApplication.java
rename to jme3-core/src/test/java/com/jme3/app/TestApplication.java
diff --git a/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java b/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java
new file mode 100755
index 00000000000..4e89aaa6dae
--- /dev/null
+++ b/jme3-core/src/test/java/com/jme3/input/InputManagerTest.java
@@ -0,0 +1,94 @@
+package com.jme3.input;
+
+import com.jme3.app.TestJoyInput;
+import com.jme3.app.TestTouchInput;
+import com.jme3.input.dummy.DummyKeyInput;
+import com.jme3.input.dummy.DummyMouseInput;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class InputManagerTest {
+
+ private MouseInput mouseSpy;
+ private KeyInput keySpy;
+ private TouchInput touchSpy;
+ private JoyInput joySpy;
+ private ArrayList inputs;
+
+ @Before
+ public void setupInputs(){
+ mouseSpy = spy(new DummyMouseInput());
+ keySpy = spy(new DummyKeyInput());
+ touchSpy = spy(new TestTouchInput());
+ joySpy = spy(new TestJoyInput());
+
+ inputs = new ArrayList<>();
+ inputs.add(mouseSpy);
+ inputs.add(keySpy);
+ inputs.add(touchSpy);
+ inputs.add(joySpy);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitializationNoKey() {
+ inputs.remove(keySpy);
+
+ new InputManager(inputs);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitializationNoMouse() {
+ inputs.remove(mouseSpy);
+
+ new InputManager(inputs);
+ }
+
+ @Test
+ public void testInitializationListenersSet() {
+ InputManager inputManager = new InputManager(inputs);
+
+ verify(mouseSpy, times(1)).setInputListener(inputManager);
+ verify(keySpy, times(1)).setInputListener(inputManager);
+ verify(touchSpy, times(1)).setInputListener(inputManager);
+ verify(joySpy, times(1)).setInputListener(inputManager);
+ }
+
+ @Test
+ public void testInitializationInputInitialization() {
+ new InputManager(inputs);
+
+ verify(mouseSpy, times(1)).initialize();
+ verify(keySpy, times(1)).initialize();
+ verify(touchSpy, times(1)).initialize();
+ verify(joySpy, times(1)).initialize();
+ }
+
+ @Test
+ public void testInitializationInputAssignments() {
+ InputManager inputManager = new InputManager(inputs);
+
+ assertNotNull(inputManager.getJoystick());
+ assertNotNull(inputManager.getMouse());
+ assertNotNull(inputManager.getKeys());
+ assertNotNull(inputManager.getTouch());
+ }
+
+ @Test
+ public void testDestroyInput() throws Exception {
+ InputManager inputManager = new InputManager(inputs);
+
+ inputManager.destroyInput();
+
+ for(Input input : inputs) {
+ verify(input, times(1)).destroy();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/jme3-core/src/test/java/com/jme3/system/NullContextTest.java b/jme3-core/src/test/java/com/jme3/system/NullContextTest.java
new file mode 100755
index 00000000000..a2835a0e0cb
--- /dev/null
+++ b/jme3-core/src/test/java/com/jme3/system/NullContextTest.java
@@ -0,0 +1,61 @@
+package com.jme3.system;
+
+import com.jme3.input.Input;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+public class NullContextTest {
+
+ @Test
+ public void testGetInputNotNull() throws Exception {
+ JmeContext spy = spy(new NullContext());
+
+ List inputs = spy.getInput();
+
+ assertNotNull(inputs);
+ }
+
+ @Test
+ public void testGetInputWithoutJoystick() throws Exception {
+ AppSettings settings = new AppSettings(true);
+ settings.setUseJoysticks(false);
+ JmeContext spy = spy(new NullContext());
+ spy.setSettings(settings);
+
+ spy.getInput();
+
+ verify(spy, times(1)).getKeyInput();
+ verify(spy, times(1)).getMouseInput();
+ verify(spy, times(0)).getJoyInput();
+ verify(spy, times(1)).getTouchInput();
+ }
+
+ @Test
+ public void testGetInputNoNullWithoutJoystick() throws Exception {
+ AppSettings settings = new AppSettings(true);
+ settings.setUseJoysticks(false);
+ JmeContext spy = spy(new NullContext());
+ spy.setSettings(settings);
+
+ List inputs = spy.getInput();
+
+ assertFalse(inputs.contains(null));
+ }
+
+ @Test
+ public void testGetInputNoNullWithJoystick() throws Exception {
+ AppSettings settings = new AppSettings(true);
+ settings.setUseJoysticks(true);
+ JmeContext spy = spy(new NullContext());
+ spy.setSettings(settings);
+
+ List inputs = spy.getInput();
+
+ assertFalse(inputs.contains(null));
+ }
+
+}
\ No newline at end of file
diff --git a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java
old mode 100644
new mode 100755
index 897632a0091..86fc3104da2
--- a/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java
+++ b/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java
@@ -31,15 +31,14 @@
*/
package com.jme3.system.awt;
-import com.jme3.input.JoyInput;
-import com.jme3.input.KeyInput;
-import com.jme3.input.MouseInput;
-import com.jme3.input.TouchInput;
+import com.jme3.input.*;
import com.jme3.input.awt.AwtKeyInput;
import com.jme3.input.awt.AwtMouseInput;
import com.jme3.renderer.Renderer;
import com.jme3.system.*;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
public class AwtPanelsContext implements JmeContext {
@@ -49,6 +48,7 @@ public class AwtPanelsContext implements JmeContext {
protected ArrayList