Skip to content

Commit

Permalink
#99 made HostServices injectable in CDI applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-mauky committed Jul 29, 2014
1 parent 2b53be4 commit 7280673
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
package de.saxsys.jfx.mvvm.cdi.internal;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.stage.Stage;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;

import de.saxsys.jfx.mvvm.api.MvvmFX;

import javax.enterprise.inject.Produces;

/**
* The class is instantiated by the javafx framework. The purpose of this class is to startup the weld container and
* setup the {@link de.saxsys.jfx.mvvm.cdi.internal.CdiInjector} for the mvvmFX framework.
Expand Down Expand Up @@ -62,4 +65,9 @@ public void start(Stage stage) throws Exception {

weldContainer.event().fire(new StartupEvent(stage, this.getParameters()));
}

@Produces
HostServices produceHostServices(){
return getHostServices();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.inject.Inject;

import javafx.application.HostServices;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.Assert;
Expand All @@ -25,6 +26,8 @@
import de.saxsys.jfx.mvvm.notifications.NotificationCenter;
import de.saxsys.jfx.mvvm.viewloader.ViewLoader;

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

/**
* This test verifies that a simple application can be started with the CDI/Weld extension. When there is a problem with
* the cdi configuration, f.e. ambiguous dependencies for an internal class of mvvmfx, this kind of bug should be found
Expand All @@ -38,6 +41,9 @@ static class Example {

@Inject
ViewLoader viewLoader;

@Inject
HostServices hostServices;
}

/**
Expand All @@ -52,14 +58,12 @@ public void testCdiInjector() {
CdiInjector cdiInjector = weldContainer.instance().select(CdiInjector.class).get();

Object exampleObject = cdiInjector.call(Example.class);
Assert.assertNotNull(exampleObject);

Assert.assertTrue(exampleObject instanceof Example);
assertThat(exampleObject).isNotNull().isInstanceOf(Example.class);

Example example = (Example) exampleObject;
Assert.assertNotNull(example.notificationCenter);
Assert.assertNotNull(example.viewLoader);


assertThat(example.notificationCenter).isNotNull();
assertThat(example.viewLoader).isNotNull();
assertThat(example.hostServices).isNotNull();
}
}

0 comments on commit 7280673

Please sign in to comment.