Unit Tests Cannot Load Application Context

@wyclif thanks for this however it looks like my test cannot find the forms in the directory - not sure what is happening https://github.com/ssmusoke/openmrs-module-aijar/blob/master/omod/src/test/java/org/openmrs/module/aijar/activator/HTMLFormsInitializerTest.java

I think the problem is here , I did say that you need to get rid of the code that creates and sets the resource provider, you need to call get Resource on the resourceFactory directly

Aren’t the forms found? Or are you running into errors?

When I run the test I the path seems to have a duplicated omod reference {mypath}/openmrs-module-aijar/omod/omod/src/main/webapp/resources/htmlforms

I think HtmlFormsInitializer was not well written to allow testability. From this, formsPath really depends on the environment and should be factored out to be set outside of the class. I would change the code so that it is passed in as a constructor argument, that way in your test you set it to match your mock path

@wyclif what inbuilt methods are available for me to get the resources paths? from the resource factory so that I do not have to hardwire it

Not sure what you’re saying, I’m saying the formPath field in the HtmlFormInitializer, that’s not inbuilt

@wyclif I am asking what inbuilt methods or functionality can I use to replace the formPath variable?

The value of this needs to be set depending on the environment, in the test phase it should be the mock value omod/src/main/webapp/resources/htmlforms/ and it defaults to htmlforms/ at runtime.

You will also need to make more mocks so that you return the right file instance for each path some like below:

Mockito.when(rp.getResource(Mockito.endsWith("035a-SafeMaleCircumcisionClientCard.xml"))).thenReturn(
        new File("omod/src/main/webapp/resources/htmlforms/035a-SafeMaleCircumcisionClientCard.xml"));