Search in sources :

Example 1 with SuccessWhen

use of com.dtflys.forest.callback.SuccessWhen in project forest by dromara.

the class ForestRequest method setSuccessWhen.

/**
 * 设置SuccessWhen回调函数,该回调函数用于判断请求是否成功
 * <p>如果成功, 执行 onSuccess
 * <p>如果失败, 执行 onError
 * <p>输入参数为 {@link SuccessWhen} 实现类的 {@link Class} 对象
 * <p>方法会自动将其实例化,并设置为请求成功条件回调函数
 *
 * @param conditionClass  {@link SuccessWhen} 实现类的 {@link Class} 对象
 * @return {@link ForestRequest}类实例
 */
public ForestRequest<T> setSuccessWhen(Class<? extends SuccessWhen> conditionClass) {
    if (conditionClass != null && !conditionClass.isInterface()) {
        SuccessWhen condition = configuration.getForestObject(conditionClass);
        setSuccessWhen(condition);
    }
    return this;
}
Also used : SuccessWhen(com.dtflys.forest.callback.SuccessWhen)

Example 2 with SuccessWhen

use of com.dtflys.forest.callback.SuccessWhen in project forest by dromara.

the class TestObjectConstructor method testRegisterConstructor.

@Test
public void testRegisterConstructor() {
    ForestConfiguration configuration = ForestConfiguration.createConfiguration();
    configuration.getForestObjectFactory().registerConstructor(SuccessWhen.class, MySuccessWhen::new);
    SuccessWhen forestObject = configuration.getForestObject(SuccessWhen.class);
    assertEquals(MySuccessWhen.class, forestObject.getClass());
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) SuccessWhen(com.dtflys.forest.callback.SuccessWhen) Test(org.junit.Test)

Example 3 with SuccessWhen

use of com.dtflys.forest.callback.SuccessWhen in project forest by dromara.

the class TestObjectConstructor method testRegisterObject.

@Test
public void testRegisterObject() {
    ForestConfiguration configuration = ForestConfiguration.createConfiguration();
    configuration.getForestObjectFactory().registerObject(SuccessWhen.class, new MySuccessWhen2());
    SuccessWhen forestObject = configuration.getForestObject(SuccessWhen.class);
    assertEquals(MySuccessWhen2.class, forestObject.getClass());
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) SuccessWhen(com.dtflys.forest.callback.SuccessWhen) Test(org.junit.Test)

Aggregations

SuccessWhen (com.dtflys.forest.callback.SuccessWhen)3 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)2 Test (org.junit.Test)2