Move to junit5 in all framework tests

- Just a migration
- Replace RedisRule with EnabledOnRedis
- Replace MongoDbRule with EnabledOnMongoDb
- spring-statemachine-test and some docs contains refs to junit4
  but those are support packages and will stay in place.
- Fixes #779
- Relates #771
This commit is contained in:
Janne Valkealahti
2019-12-24 16:52:05 +00:00
parent 0adae262c4
commit 10ce7a65a4
28 changed files with 289 additions and 161 deletions

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.statemachine.data.redis;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ExtendWith(EnabledOnRedisCondition.class)
public @interface EnabledOnRedis {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,38 +15,34 @@
*/
package org.springframework.statemachine.data.redis;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
/**
* Rule skipping tests if redis is not available from localhost with default settings.
*
* @author Janne Valkealahti
*
*/
public class RedisRule extends TestWatcher implements TestRule {
public class EnabledOnRedisCondition implements ExecutionCondition {
static final ConditionEvaluationResult ENABLED_ON_REDIS = enabled("Redis found");
static final ConditionEvaluationResult DISABLED_ON_REDIS = disabled("Redis not found");
@Override
public Statement apply(Statement base, Description description) {
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
JedisConnectionFactory connectionFactory = null;
try {
connectionFactory = new JedisConnectionFactory();
connectionFactory.afterPropertiesSet();
connectionFactory.getConnection().close();
return ENABLED_ON_REDIS;
} catch (Exception e) {
return super.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
}
}, Description.EMPTY);
} finally {
if (connectionFactory != null) {
connectionFactory.destroy();
}
}
return super.apply(base, description);
return DISABLED_ON_REDIS;
}
}

View File

@@ -25,8 +25,7 @@ import static org.springframework.statemachine.TestUtils.resolveMachine;
import java.util.ArrayList;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -48,11 +47,9 @@ import org.springframework.statemachine.transition.TransitionKind;
*
* @author Janne Valkealahti
*/
@EnabledOnRedis
public class RedisRepositoryTests extends AbstractRepositoryTests {
@Rule
public RedisRule redisAvailableRule = new RedisRule();
@Override
protected void cleanInternal() {
AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext();