Java Code Examples for com.badlogic.gdx.Gdx#app()

The following examples show how to use com.badlogic.gdx.Gdx#app() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void readValue() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryReadValue.class);
        QueryReadValue query = spy(new QueryReadValue(database, testReference));
        PowerMockito.whenNew(QueryReadValue.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        Class dataType = String.class;


        // When
        ((FuturePromise) database.inReference(testReference).readValue(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(ReadValueQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryReadValue.class);
        QueryReadValue.once(Mockito.any(DatabaseReference.class), Mockito.any(ConverterPromise.class));
    }
 
Example 2
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        Gdx.app = Mockito.mock(Application.class);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        Class dataType = String.class;

        // When
        ((FuturePromise) database.inReference(testReference).onDataChange(dataType).subscribe()).doComplete(testReference);

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.onValue(eq(testReference), Mockito.any(DatabaseReference.class));
    }
 
Example 3
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void onChildChange() throws Exception {
    // Given
    String testReference = "test_reference";
    Database database = new Database();
    mockStatic(QueryOnChildChange.class);
    QueryOnChildChange query = spy(new QueryOnChildChange(database, testReference));
    PowerMockito.whenNew(QueryOnChildChange.class).withAnyArguments().thenReturn(query);
    Gdx.app = Mockito.mock(Application.class);
    PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference + "child_added");
    Class dataType = String.class;

    // When
    ((FuturePromise) database.inReference(testReference)
            .onChildChange(dataType, ChildEventType.ADDED).subscribe()).doComplete(testReference);

    // Then
    PowerMockito.verifyStatic(QueryOnChildChange.class);
    QueryOnChildChange.onEvent(eq(testReference), eq("child_added"), Mockito.any(DatabaseReference.class));
}
 
Example 4
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
    public void onDataChange_detach() throws Exception {
        // Given
        String testReference = "test_reference";
        Database database = new Database();
        mockStatic(QueryOnDataChange.class);
        QueryOnDataChange query = spy(new QueryOnDataChange(database, testReference));
        PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query);
        PowerMockito.doReturn(false).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        GwtDataPromisesManager.removeDataPromise(testReference);
        Gdx.app = Mockito.mock(Application.class);

        // When
        FutureListenerPromise promise = ((FutureListenerPromise) database.inReference(testReference).onDataChange(String.class).subscribe());
        promise.doComplete(testReference);
        PowerMockito.doReturn(true).when(GwtDataPromisesManager.class, "hasPromise", testReference);
        promise.cancel();

        // Then
//        PowerMockito.verifyNew(OnDataChangeQuery.class).withArguments(Mockito.any());
        PowerMockito.verifyStatic(QueryOnDataChange.class);
        QueryOnDataChange.offValue(eq(testReference));
    }
 
Example 5
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnHTMLGDXFacebookWhenOnWebGL() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.WebGL);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(HTMLGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML)).thenReturn(HTMLGDXFacebook.class);
        when(ClassReflection.getConstructor(HTMLGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof HTMLGDXFacebook);
}
 
Example 6
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnDesktopGDXFacebookWhenOnDesktop() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.Desktop);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(DesktopGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP)).thenReturn(DesktopGDXFacebook.class);
        when(ClassReflection.getConstructor(DesktopGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof DesktopGDXFacebook);
}
 
Example 7
Source File: AndroidContextTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    PowerMockito.mockStatic(GdxNativesLoader.class);
    AndroidApplication application = PowerMockito.mock(AndroidApplication.class);
    Mockito.when(application.getType()).thenReturn(Application.ApplicationType.Android);
    Gdx.app = application;
    PowerMockito.mockStatic(Timer.class);
    PowerMockito.when(Timer.post(any(Timer.Task.class))).then(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((Timer.Task) invocation.getArgument(0)).run();
            return null;
        }
    });
    GdxFIRApp.setThrowFailureByDefault(false);
}
 
Example 8
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnIOSGDXFacebookWhenOnIOS() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(IOSGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS)).thenReturn(IOSGDXFacebook.class);
        when(ClassReflection.getConstructor(IOSGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof IOSGDXFacebook);
}
 
Example 9
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 6 votes vote down vote up
protected void onResume() {
    Gdx.app = this;
    Gdx.input = this.getInput();
    Gdx.audio = this.getAudio();
    Gdx.files = this.getFiles();
    Gdx.graphics = this.getGraphics();
    Gdx.net = this.getNet();
    this.input.onResume();
    if (this.graphics != null) {
        this.graphics.onResumeGLSurfaceView();
    }

    if (!this.firstResume) {
        this.graphics.resume();
    } else {
        this.firstResume = false;
    }

    this.isWaitingForAudio = true;
    if (this.wasFocusChanged == 1 || this.wasFocusChanged == -1) {
        this.audio.resume();
        this.isWaitingForAudio = false;
    }

    super.onResume();
}
 
Example 10
Source File: ControllerMappingsTest.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    // Note that we don't need to implement any of the listener's methods
    Gdx.app = new HeadlessApplication(new ApplicationListener() {
        @Override
        public void create() {
        }

        @Override
        public void resize(int width, int height) {
        }

        @Override
        public void render() {
        }

        @Override
        public void pause() {
        }

        @Override
        public void resume() {
        }

        @Override
        public void dispose() {
        }
    });

    // Use Mockito to mock the OpenGL methods since we are running headlessly
    Gdx.gl20 = Mockito.mock(GL20.class);
    Gdx.gl = Gdx.gl20;
}
 
Example 11
Source File: SeventhGame.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Hide the Mouse cursor
 * 
 * @param visible
 */
private void setHWCursorVisible(boolean visible) {
    if (Gdx.app.getType() != ApplicationType.Desktop && Gdx.app instanceof LwjglApplication) {
        return;
    }

    try {
        /* make sure the mouse doesn't move off the screen */
        seventh.client.gfx.Cursor cursor = this.uiManager.getCursor();
        cursor.setClampEnabled(config.getVideo().isFullscreen());
        Gdx.input.setCursorCatched(config.getVideo().isFullscreen());
        
        //Gdx.input.setCursorCatched(true);
        //Gdx.input.setCursorPosition(getScreenWidth()/2, getScreenHeight()/2);
        
        Cursor emptyCursor = null;
        if (Mouse.isCreated()) {
            int min = org.lwjgl.input.Cursor.getMinCursorSize();
            IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
            emptyCursor = new org.lwjgl.input.Cursor(min, min, min / 2, min / 2, 1, tmp, null);
        } else {
            Cons.println("Could not create empty cursor before Mouse object is created");
        }
    
        if (/*Mouse.isInsideWindow() &&*/ emptyCursor != null) {
            Mouse.setNativeCursor(visible ? null : emptyCursor);
        }
    }
    catch(LWJGLException e) {
        Cons.println("*** Unable to hide cursor: " + e);
    }
}
 
Example 12
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
private void androidPremocking() {

        Application mockApplication = mock(Application.class);
        when(mockApplication.getType()).thenReturn(Application.ApplicationType.Android);
        Gdx.app = mockApplication;

        try {
            mockConstructor = PowerMockito.mock(Constructor.class);
            mockFacebook = mock(AndroidGDXFacebook.class);
            mockField = mock(Field.class);
            mockObject = mock(Object.class);
            mockMethod = mock(Method.class);

            when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_ANDROID)).thenReturn(AndroidGDXFacebook.class);
            when(ClassReflection.getConstructor(AndroidGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
            when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);


            when(ClassReflection.forName("com.badlogic.gdx.Gdx")).thenReturn(Gdx.class);
            when(ClassReflection.getField(Gdx.class, "app")).thenReturn(mockField);
            when(mockField.get(null)).thenReturn(mockObject);


            when(ClassReflection.forName("com.badlogic.gdx.backends.android.AndroidEventListener")).thenReturn(AndroidEventListener.class);
            when(ClassReflection.forName("android.app.Activity")).thenReturn(Activity.class);

        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    }
 
Example 13
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
@Test
public void ifNoPlatformGDXFacebookCanBeFoundReturnFallbackGDXFacebook() {

    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(null);
    Gdx.app = mockApplication;

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof FallbackGDXFacebookIF);
}
 
Example 14
Source File: GdxIOSAppTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    PowerMockito.mockStatic(NatJ.class);
    IOSApplication application = Mockito.mock(IOSApplication.class);
    Mockito.when(application.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = application;
    GdxFIRApp.setThrowFailureByDefault(false);
}
 
Example 15
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void keepSynced() {
    // Given
    Database database = new Database();
    Application application = Mockito.mock(Application.class);
    Gdx.app = application;

    // When
    database.keepSynced(true);

    // Then
    Mockito.verify(application).log(Mockito.anyString(), Mockito.anyString());
}
 
Example 16
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void setPersistenceEnabled() {
    // Given
    Database database = new Database();
    Application application = Mockito.mock(Application.class);
    Gdx.app = application;

    // When
    database.setPersistenceEnabled(true);

    // Then
    Mockito.verify(application).log(Mockito.anyString(), Mockito.anyString());
}
 
Example 17
Source File: DesktopLauncher.java    From Norii with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] arg) {
	final LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	config.title = "Norii a turn based strategy game by Jelte";
	config.width = 580;
	config.height = 580;
	config.fullscreen = false;
	config.initialBackgroundColor = Color.BLACK;

	final Application app = new LwjglApplication(new Norii(), config);
	Gdx.app = app;
	Gdx.app.setLogLevel(Application.LOG_DEBUG);
}
 
Example 18
Source File: GdxDemoActivity.java    From thunderboard-android with Apache License 2.0 4 votes vote down vote up
private void init(ApplicationListener listener, AndroidApplicationConfiguration config, boolean isForView) {
    if (this.getVersion() < 8) {
        throw new GdxRuntimeException("LibGDX requires Android API Level 8 or later.");
    } else {
        this.setApplicationLogger(new AndroidApplicationLogger());
        this.graphics = new AndroidGraphics(this, config, (ResolutionStrategy) (config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy));
        this.input = AndroidInputFactory.newAndroidInput(this, this, this.graphics.view, config);
        this.audio = new AndroidAudio(this, config);
        this.getFilesDir();
        this.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
        this.net = new AndroidNet(this);
        this.listener = listener;
        this.handler = new Handler();
        this.useImmersiveMode = config.useImmersiveMode;
        this.hideStatusBar = config.hideStatusBar;
        this.clipboard = new AndroidClipboard(this);
        this.addLifecycleListener(new LifecycleListener() {
            public void resume() {
            }

            public void pause() {
                audio.pause();
            }

            public void dispose() {
                audio.dispose();
            }
        });
        Gdx.app = this;
        Gdx.input = this.getInput();
        Gdx.audio = this.getAudio();
        Gdx.files = this.getFiles();
        Gdx.graphics = this.getGraphics();
        Gdx.net = this.getNet();
        if (!isForView) {
            try {
                this.requestWindowFeature(1);
            } catch (Exception var8) {
                this.log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", var8);
            }

            this.getWindow().setFlags(1024, 1024);
            this.getWindow().clearFlags(2048);
            this.setContentView(this.graphics.getView(), this.createLayoutParams());
        }

        this.createWakeLock(config.useWakelock);
        this.hideStatusBar(this.hideStatusBar);
        this.useImmersiveMode(this.useImmersiveMode);
        if (this.useImmersiveMode && this.getVersion() >= 19) {
            try {
                Class<?> vlistener = Class.forName("com.badlogic.gdx.backends.android.AndroidVisibilityListener");
                Object o = vlistener.newInstance();
                Method method = vlistener.getDeclaredMethod("createListener", AndroidApplicationBase.class);
                method.invoke(o, this);
            } catch (Exception var7) {
                this.log("AndroidApplication", "Failed to create AndroidVisibilityListener", var7);
            }
        }

    }
}
 
Example 19
Source File: FuturePromiseTest.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    Gdx.app = Mockito.mock(Application.class);
    GdxFIRApp.setAutoSubscribePromises(false);
    GdxFIRApp.setThrowFailureByDefault(false);
}
 
Example 20
Source File: GdxAppTest.java    From gdx-fireapp with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    Gdx.app = Mockito.mock(Application.class);
}