30 lines
774 B
Java
30 lines
774 B
Java
|
package com.baeldung.resource;
|
||
|
import static org.junit.Assert.assertNotNull;
|
||
|
|
||
|
import java.io.File;
|
||
|
|
||
|
import javax.annotation.Resource;
|
||
|
|
||
|
import org.junit.Test;
|
||
|
import org.junit.runner.RunWith;
|
||
|
import org.springframework.test.context.ContextConfiguration;
|
||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||
|
|
||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||
|
@ContextConfiguration(locations={
|
||
|
"/applicationContextTest-@Resource-NameType.xml"})
|
||
|
public class MethodResourceInjectionDemo {
|
||
|
|
||
|
private File defaultFile;
|
||
|
|
||
|
@Resource(name="namedFile")
|
||
|
protected void setDefaultFile(File defaultFile) {
|
||
|
this.defaultFile = defaultFile;
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void defaultFile_MUST_BE_INJECTED_Correctly() {
|
||
|
assertNotNull(defaultFile);
|
||
|
}
|
||
|
}
|