Skip to content

Commit

Permalink
#136 Implement MvvmfxApplication interface for guice. Add Integration…
Browse files Browse the repository at this point in the history
… tests for CDI and guice to ensure that init and stop are called.
  • Loading branch information
manuel-mauky committed Oct 16, 2014
1 parent 8ebf14c commit 7334878
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public class IntegrationTest {

@Before
public void setup(){
MyApp.wasPostConstructCalled=false;
MyApp.wasPreDestroyCalled=false;
MyApp.wasPostConstructCalled = false;
MyApp.wasPreDestroyCalled = false;
MyApp.wasInitCalled = false;
MyApp.wasStopCalled = false;
}

@Test
Expand All @@ -22,6 +24,8 @@ public void test(){
assertThat(MyApp.wasPostConstructCalled).isTrue();
assertThat(MyApp.wasPreDestroyCalled).isTrue();

assertThat(MyApp.wasInitCalled).isTrue();
assertThat(MyApp.wasStopCalled).isTrue();

assertThat(MyApp.viewTuple).isNotNull();
assertThat(MyApp.stage).isNotNull();
Expand Down
14 changes: 14 additions & 0 deletions mvvmfx-cdi/src/test/java/de/saxsys/mvvmfx/cdi/it/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class MyApp extends MvvmfxCdiApplication {
static boolean wasPreDestroyCalled = false;
static boolean wasPostConstructCalled = false;

static boolean wasInitCalled = false;
static boolean wasStopCalled = false;



static ViewTuple<MyView, MyViewModel> viewTuple;
Expand All @@ -36,4 +39,15 @@ public void postConstruct(){
public void preDestroy(){
wasPreDestroyCalled = true;
}


@Override
public void initMvvmfx() throws Exception {
wasInitCalled = true;
}

@Override
public void stopMvvmfx() throws Exception {
wasStopCalled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package de.saxsys.mvvmfx.guice;

import java.util.List;

import de.saxsys.mvvmfx.internal.MvvmfxApplication;
import javafx.application.HostServices;
import javafx.stage.Stage;

Expand All @@ -34,7 +36,7 @@
*
* @author manuel.mauky
*/
public abstract class MvvmfxGuiceApplication extends GuiceApplication {
public abstract class MvvmfxGuiceApplication extends GuiceApplication implements MvvmfxApplication{


@Inject
Expand All @@ -50,19 +52,20 @@ public final void init(List<Module> modules) throws Exception {
@Override
protected void configure() {
bind(HostServices.class).toProvider(new Provider<HostServices>() {
@Override public HostServices get() {
@Override
public HostServices get() {
return getHostServices();
}
});

bind(Stage.class).toProvider(new Provider<Stage>() {
@Override
public Stage get() {
return primaryStage;
}
});

bind(Parameters.class).toProvider(new Provider<Parameters> (){
bind(Parameters.class).toProvider(new Provider<Parameters>() {
@Override
public Parameters get() {
return getParameters();
Expand All @@ -73,6 +76,7 @@ public Parameters get() {


this.initGuiceModules(modules);
this.initMvvmfx();
}

/**
Expand All @@ -86,14 +90,12 @@ public final void start(Stage stage) throws Exception {

this.startMvvmfx(stage);
}

/**
* Override this method with your application startup logic.
* <p/>
* This method is a wrapper method for javafx's {@link javafx.application.Application#start(javafx.stage.Stage)}.
*/
public abstract void startMvvmfx(Stage stage) throws Exception;


@Override
public final void stop() throws Exception {
stopMvvmfx();
}

/**
* Configure the guice modules.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

import static org.assertj.core.api.Assertions.*;

import org.junit.Before;
import org.junit.Test;

import de.saxsys.mvvmfx.guice.internal.GuiceInjector;

public class IntegrationTest {

@Before
public void setup(){
MyApp.wasInitCalled = false;
MyApp.wasStopCalled = false;
}

@Test
public void testInjectionOfPrimaryStage(){
MyApp.main("test");


assertThat(MyApp.wasInitCalled).isTrue();
assertThat(MyApp.wasStopCalled).isTrue();

assertThat(MyApp.stage).isNotNull();
assertThat(MyApp.parameters).isNotNull();
assertThat(MyApp.parameters.getUnnamed()).contains("test");
Expand Down
14 changes: 14 additions & 0 deletions mvvmfx-guice/src/test/java/de/saxsys/mvvmfx/guice/it/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@


public class MyApp extends MvvmfxGuiceApplication {


static boolean wasInitCalled = false;
static boolean wasStopCalled = false;

public static void main(String...args){
launch(args);
Expand Down Expand Up @@ -47,4 +51,14 @@ public void startMvvmfx(Stage stage) throws Exception {
// we can't shutdown the application in the test case so we need to do it here.
Platform.exit();
}

@Override
public void initMvvmfx() throws Exception {
wasInitCalled = true;
}

@Override
public void stopMvvmfx() throws Exception {
wasStopCalled = true;
}
}

0 comments on commit 7334878

Please sign in to comment.