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.mongodb;
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(EnabledOnMongoDbCondition.class)
public @interface EnabledOnMongoDb {
}

View File

@@ -0,0 +1,41 @@
/*
* 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.mongodb;
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.util.SocketUtils;
public class EnabledOnMongoDbCondition implements ExecutionCondition {
static final ConditionEvaluationResult ENABLED_ON_MONGO = enabled("Mongo DB found");
static final ConditionEvaluationResult DISABLED_ON_MONGO = disabled("Mongo DB not found");
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
try {
SocketUtils.findAvailableTcpPort(27017, 27017);
return DISABLED_ON_MONGO;
} catch (Exception e) {
}
return ENABLED_ON_MONGO;
}
}

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;
@@ -50,11 +49,9 @@ import org.springframework.statemachine.transition.TransitionKind;
*
* @author Janne Valkealahti
*/
@EnabledOnMongoDb
public class MongoDbRepositoryTests extends AbstractRepositoryTests {
@Rule
public MongoDbRule MongoDbAvailableRule = new MongoDbRule();
@Override
protected void cleanInternal() {
AnnotationConfigApplicationContext c = new AnnotationConfigApplicationContext();