类如下 我想用junit测试USERUSERNAME 与配置文件中配置的值是否相等 该怎么写测试
public class PublicConsts {
public static final String USERUSERNAME = PublicConsts.getProperty("username");private static void init() {
InputStream inputStream = null;
try {
String path = System.getProperty("user.dir") +File.separator+"bin"+File.separator+"props.properties";
inputStream = new FileInputStream(path);
property.load(inputStream);
} catch (IOException e) {
logger.info(e.getMessage(), e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
logger.info(e.getMessage(), e);
}
}
}
/**
* 【描 述】:获得属性值
*
* @param key String 键
* @return String 值
* @since 2011-3-18 v1.0
*/
private static String getProperty(String key) {
return property.getProperty(key);
}}
public class PublicConsts {
public static final String USERUSERNAME = PublicConsts.getProperty("username");private static void init() {
InputStream inputStream = null;
try {
String path = System.getProperty("user.dir") +File.separator+"bin"+File.separator+"props.properties";
inputStream = new FileInputStream(path);
property.load(inputStream);
} catch (IOException e) {
logger.info(e.getMessage(), e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
logger.info(e.getMessage(), e);
}
}
}
/**
* 【描 述】:获得属性值
*
* @param key String 键
* @return String 值
* @since 2011-3-18 v1.0
*/
private static String getProperty(String key) {
return property.getProperty(key);
}}
* 【描 述】:属性变量
*
* @since 2011-3-18 v1.0
*/
private static Properties property = new Properties();
/**
* 静态块,先初始化property的值
*/
static {
PublicConsts.init();
}