I am writing a unit test case like this,
public class XMLUtilsTest {
private static final String XML_FOR_TEST ="a/b/c/xml_utils_test.xml";
@Before
public void setup() {
}
@Test
public void testGetElementValue() throws Exception {
InputStream inputStream = readTestXML(XML_FOR_TEST);
System.out.println("Input Stream: "+inputStream);
}
private InputStream readTestXML(String testXmlFile) {
//InputStream inputStream = XMLUtilsTest.class.getResourceAsStream(testXmlFile);
//InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(testXmlFile);
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile);
return inputStream;
}
}
While debugging, i observe that this.getClass().getClassLoader() call in the readTestXML method loads class properly but when getResourceAsStream(testXmlFile) is invoked on output of this.getClass().getClassLoader() , the output is null.
my project structure is like this,
--src
--main
--test
--java
--XMLUtilsTest.java
--resources
--a.b.c
--xml_utils_test.xml
Please suggest.
Thanks,
Vijay Bhore