mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Support @Order-ing of JUnit tests
This commit is contained in:
parent
e17480ad8f
commit
080952b1d7
56
apitest/src/main/java/bisq/apitest/OrderedRunner.java
Normal file
56
apitest/src/main/java/bisq/apitest/OrderedRunner.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.apitest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
|
||||
|
||||
import bisq.apitest.annotation.Order;
|
||||
|
||||
// Credit to Aman Goel
|
||||
// https://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4
|
||||
|
||||
public class OrderedRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
public OrderedRunner(Class<?> clazz) throws InitializationError {
|
||||
super(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FrameworkMethod> computeTestMethods() {
|
||||
List<FrameworkMethod> list = super.computeTestMethods();
|
||||
List<FrameworkMethod> copy = new ArrayList<>(list);
|
||||
copy.sort((f1, f2) -> {
|
||||
Order o1 = f1.getAnnotation(Order.class);
|
||||
Order o2 = f2.getAnnotation(Order.class);
|
||||
|
||||
if (o1 == null || o2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return o1.value() - o2.value();
|
||||
});
|
||||
return copy;
|
||||
}
|
||||
}
|
32
apitest/src/main/java/bisq/apitest/annotation/Order.java
Normal file
32
apitest/src/main/java/bisq/apitest/annotation/Order.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.apitest.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// Credit to Aman Goel
|
||||
// https://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface Order {
|
||||
int value();
|
||||
}
|
@ -609,6 +609,7 @@ configure(project(':apitest')) {
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "ch.qos.logback:logback-core:$logbackVersion"
|
||||
implementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
implementation "junit:junit:$junitVersion"
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
compileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
|
Loading…
Reference in New Issue
Block a user