Slow Harry
Slow Harry

Reputation: 1897

Global object onStart fails all my tests

I had a number of tests, it ran perfectly, untill I write Global object:

    @Override
    public void onStart(Application app) {
        Mails.plugin = app.plugin(MailerPlugin.class).email();
        Mails.from = app.configuration().getString("smtp.from");
        if (Mails.plugin != null) Logger.info("Mailer plugin successfully loaded"); 
        if (Mails.from != null) Logger.info("Mail account is " + Mails.from);

    }

Here I am loading plugin for email messages. Now when I try to run my fakeApplication with inMemoryDatabase I get a null pointer exception. Probably it is becouse fakeApplication don't use configuration file, and can't load configuration from this file. Please help me to sort out this problem.

Upvotes: 0

Views: 698

Answers (2)

Slow Harry
Slow Harry

Reputation: 1897

I find the solution , for this reason I create fake Global class (or you also can mock it):

class Global extends GlobalSettings{

}

and Then can pass it:

@BeforeClass
    public static void startApp() { 
        app = Helpers.fakeApplication(new Global());
        Helpers.start(app);
    }

Upvotes: 1

ndeverge
ndeverge

Reputation: 21564

Try adding custom config parameters in your FakeApplication:

Map<String, Object> additionalConfiguration = new HashMap<String, Object>();
additionalConfiguration.put("smtp.from", "[email protected]");

running(fakeApplication(additionalConfiguration), new Runnable() {
...

Upvotes: 2

Related Questions