Skip to content

Commit

Permalink
Init input Application tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoopAue committed Mar 24, 2016
1 parent 9873a76 commit 85ccf35
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/app/Application.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private void initCamera(){
* initializes joystick input if joysticks are enabled in the
* AppSettings.
*/
private void initInput(){
protected void initInput(){
mouseInput = context.getMouseInput();
if (mouseInput != null)
mouseInput.initialize();
Expand Down
9 changes: 9 additions & 0 deletions jme3-core/src/main/java/com/jme3/app/TestApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jme3.app;


public class TestApplication extends SimpleApplication{
@Override
public void simpleInitApp() {

}
}
Empty file modified jme3-core/src/main/java/com/jme3/input/JoyInput.java
100644 → 100755
Empty file.
Empty file modified jme3-core/src/main/java/com/jme3/input/TouchInput.java
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions jme3-core/src/main/resources/com/jme3/system/version.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# THIS IS AN AUTO-GENERATED FILE..
# DO NOT MODIFY!
<<<<<<< 9873a76327519d60380864617c1c74f58802b99c
build.date=2016-03-21
git.revision=5389
git.branch=test-texture
Expand All @@ -8,5 +9,15 @@ 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
git.tag=null
name.full=jMonkeyEngine 3.1-5475
version.full=3.1-5475
>>>>>>> Init input Application tests
version.number=3.1.0
version.tag=SNAPSHOT
113 changes: 113 additions & 0 deletions jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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());
}

}
49 changes: 49 additions & 0 deletions jme3-core/src/test/java/com/jme3/app/TestJoyInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.jme3.app;


import com.jme3.input.InputManager;
import com.jme3.input.JoyInput;
import com.jme3.input.Joystick;
import com.jme3.input.RawInputListener;

public class TestJoyInput implements JoyInput{
@Override
public void setJoyRumble(int joyId, float amount) {

}

@Override
public Joystick[] loadJoysticks(InputManager inputManager) {
return new Joystick[0];
}

@Override
public void initialize() {

}

@Override
public void update() {

}

@Override
public void destroy() {

}

@Override
public boolean isInitialized() {
return false;
}

@Override
public void setInputListener(RawInputListener listener) {

}

@Override
public long getInputTimeNanos() {
return 0;
}
}
61 changes: 61 additions & 0 deletions jme3-core/src/test/java/com/jme3/app/TestTouchInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.jme3.app;

import com.jme3.input.RawInputListener;
import com.jme3.input.TouchInput;

public class TestTouchInput implements TouchInput{
@Override
public void setSimulateMouse(boolean simulate) {

}

@Override
public boolean isSimulateMouse() {
return false;
}

@Override
public void setSimulateKeyboard(boolean simulate) {

}

@Override
public boolean isSimulateKeyboard() {
return false;
}

@Override
public void setOmitHistoricEvents(boolean dontSendHistory) {

}

@Override
public void initialize() {

}

@Override
public void update() {

}

@Override
public void destroy() {

}

@Override
public boolean isInitialized() {
return false;
}

@Override
public void setInputListener(RawInputListener listener) {

}

@Override
public long getInputTimeNanos() {
return 0;
}
}

0 comments on commit 85ccf35

Please sign in to comment.