下面列出了org.apache.commons.lang.reflect.FieldUtils#writeStaticField ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@BeforeClass
public static void hackPropsUi() throws Exception {
Field props = getPropsField();
if ( props == null ) {
throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
}
Object value = FieldUtils.readStaticField( props, true );
if ( value == null ) {
PropsUI mock = mock( PropsUI.class );
FieldUtils.writeStaticField( props, mock, true );
changedPropsUi = true;
} else {
changedPropsUi = false;
}
}
@BeforeClass
public static void hackPropsUi() throws Exception {
Field props = getPropsField();
if ( props == null ) {
throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
}
Object value = FieldUtils.readStaticField( props, true );
if ( value == null ) {
PropsUI mock = mock( PropsUI.class );
FieldUtils.writeStaticField( props, mock, true );
changedPropsUi = true;
} else {
changedPropsUi = false;
}
}
@BeforeClass
public static void hackPropsUi() throws Exception {
Field props = getPropsField();
if ( props == null ) {
throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
}
Object value = FieldUtils.readStaticField( props, true );
if ( value == null ) {
PropsUI mock = mock( PropsUI.class );
FieldUtils.writeStaticField( props, mock, true );
changedPropsUi = true;
} else {
changedPropsUi = false;
}
}
@BeforeClass
public static void hackPropsUi() throws Exception {
Field props = getPropsField();
if ( props == null ) {
throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
}
Object value = FieldUtils.readStaticField( props, true );
if ( value == null ) {
PropsUI mock = mock( PropsUI.class );
FieldUtils.writeStaticField( props, mock, true );
changedPropsUi = true;
} else {
changedPropsUi = false;
}
}
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
if ( changedPropsUi ) {
Field props = getPropsField();
FieldUtils.writeStaticField( props, null, true );
}
}
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
if ( changedPropsUi ) {
Field props = getPropsField();
FieldUtils.writeStaticField( props, null, true );
}
}
public static void resetArchaius() throws Exception {
//super hacky and brittle, but archaius provides no way to reset its configuration
FieldUtils.writeStaticField(ConfigurationManager.class, "customConfigurationInstalled", false, true);
FieldUtils.writeStaticField(DynamicPropertyFactory.class, "initializedWithDefaultConfig", false, true);
FieldUtils.writeStaticField(ConfigurationManager.class, "instance", null, true);
FieldUtils.writeStaticField(DynamicPropertyFactory.class, "config", null, true);
}
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
if ( changedPropsUi ) {
Field props = getPropsField();
FieldUtils.writeStaticField( props, null, true );
}
}
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
if ( changedPropsUi ) {
Field props = getPropsField();
FieldUtils.writeStaticField( props, null, true );
}
}
@BeforeClass
public static void hackPropsUi() throws Exception {
Field props = getPropsField();
if ( props == null ) {
throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
}
Object value = FieldUtils.readStaticField( props, true );
if ( value == null ) {
PropsUI mock = mock( PropsUI.class );
FieldUtils.writeStaticField( props, mock, true );
changedPropsUi = true;
} else {
changedPropsUi = false;
}
}
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
if ( changedPropsUi ) {
Field props = getPropsField();
FieldUtils.writeStaticField( props, null, true );
}
}