Use the @TestInstance annotation
This commit is contained in:
parent
e7b119c95c
commit
36f5947cd7
@ -23,6 +23,7 @@
|
|||||||
package com.iluwatar.interpreter;
|
package com.iluwatar.interpreter;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||||||
* @param <E> Type of Expression
|
* @param <E> Type of Expression
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public abstract class ExpressionTest<E extends Expression> {
|
public abstract class ExpressionTest<E extends Expression> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,6 +90,13 @@ public abstract class ExpressionTest<E extends Expression> {
|
|||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new set of test entries with the expected result
|
||||||
|
*
|
||||||
|
* @return The list of parameters used during this test
|
||||||
|
*/
|
||||||
|
public abstract Stream<Arguments> expressionProvider();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the expression calculates the correct result when calling {@link E#interpret()}
|
* Verify if the expression calculates the correct result when calling {@link E#interpret()}
|
||||||
*/
|
*/
|
||||||
|
@ -38,7 +38,8 @@ public class MinusExpressionTest extends ExpressionTest<MinusExpression> {
|
|||||||
*
|
*
|
||||||
* @return The list of parameters used during this test
|
* @return The list of parameters used during this test
|
||||||
*/
|
*/
|
||||||
public static Stream<Arguments> expressionProvider() {
|
@Override
|
||||||
|
public Stream<Arguments> expressionProvider() {
|
||||||
return prepareParameters((f, s) -> f - s);
|
return prepareParameters((f, s) -> f - s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ public class MultiplyExpressionTest extends ExpressionTest<MultiplyExpression> {
|
|||||||
*
|
*
|
||||||
* @return The list of parameters used during this test
|
* @return The list of parameters used during this test
|
||||||
*/
|
*/
|
||||||
public static Stream<Arguments> expressionProvider() {
|
@Override
|
||||||
|
public Stream<Arguments> expressionProvider() {
|
||||||
return prepareParameters((f, s) -> f * s);
|
return prepareParameters((f, s) -> f * s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ public class NumberExpressionTest extends ExpressionTest<NumberExpression> {
|
|||||||
*
|
*
|
||||||
* @return The list of parameters used during this test
|
* @return The list of parameters used during this test
|
||||||
*/
|
*/
|
||||||
public static Stream<Arguments> expressionProvider() {
|
@Override
|
||||||
|
public Stream<Arguments> expressionProvider() {
|
||||||
return prepareParameters((f, s) -> f);
|
return prepareParameters((f, s) -> f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ public class PlusExpressionTest extends ExpressionTest<PlusExpression> {
|
|||||||
*
|
*
|
||||||
* @return The list of parameters used during this test
|
* @return The list of parameters used during this test
|
||||||
*/
|
*/
|
||||||
public static Stream<Arguments> expressionProvider() {
|
@Override
|
||||||
|
public Stream<Arguments> expressionProvider() {
|
||||||
return prepareParameters((f, s) -> f + s);
|
return prepareParameters((f, s) -> f + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class HobbitsTest extends WeatherObserverTest<Hobbits> {
|
public class HobbitsTest extends WeatherObserverTest<Hobbits> {
|
||||||
|
|
||||||
static Collection<Object[]> dataProvider() {
|
@Override
|
||||||
|
public Collection<Object[]> dataProvider() {
|
||||||
final List<Object[]> testData = new ArrayList<>();
|
final List<Object[]> testData = new ArrayList<>();
|
||||||
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
|
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
|
||||||
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
|
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
|
||||||
|
@ -33,7 +33,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class OrcsTest extends WeatherObserverTest<Orcs> {
|
public class OrcsTest extends WeatherObserverTest<Orcs> {
|
||||||
|
|
||||||
static Collection<Object[]> dataProvider() {
|
@Override
|
||||||
|
public Collection<Object[]> dataProvider() {
|
||||||
final List<Object[]> testData = new ArrayList<>();
|
final List<Object[]> testData = new ArrayList<>();
|
||||||
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
||||||
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
||||||
|
@ -23,11 +23,14 @@
|
|||||||
package com.iluwatar.observer;
|
package com.iluwatar.observer;
|
||||||
|
|
||||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
* @param <O> Type of WeatherObserver
|
* @param <O> Type of WeatherObserver
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||||
|
|
||||||
private InMemoryAppender appender;
|
private InMemoryAppender appender;
|
||||||
@ -67,6 +71,8 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
|||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Collection<Object[]> dataProvider();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the weather has the expected influence on the observer
|
* Verify if the weather has the expected influence on the observer
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class GHobbitsTest extends ObserverTest<GHobbits> {
|
public class GHobbitsTest extends ObserverTest<GHobbits> {
|
||||||
|
|
||||||
static Collection<Object[]> dataProvider() {
|
@Override
|
||||||
|
public Collection<Object[]> dataProvider() {
|
||||||
final List<Object[]> testData = new ArrayList<>();
|
final List<Object[]> testData = new ArrayList<>();
|
||||||
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
|
testData.add(new Object[]{WeatherType.SUNNY, "The happy hobbits bade in the warm sun."});
|
||||||
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
|
testData.add(new Object[]{WeatherType.RAINY, "The hobbits look for cover from the rain."});
|
||||||
|
@ -26,9 +26,11 @@ import com.iluwatar.observer.WeatherType;
|
|||||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
@ -39,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
* @param <O> Type of Observer
|
* @param <O> Type of Observer
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public abstract class ObserverTest<O extends Observer> {
|
public abstract class ObserverTest<O extends Observer> {
|
||||||
|
|
||||||
private InMemoryAppender appender;
|
private InMemoryAppender appender;
|
||||||
@ -67,6 +70,8 @@ public abstract class ObserverTest<O extends Observer> {
|
|||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Collection<Object[]> dataProvider();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the weather has the expected influence on the observer
|
* Verify if the weather has the expected influence on the observer
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class OrcsTest extends ObserverTest<GOrcs> {
|
public class OrcsTest extends ObserverTest<GOrcs> {
|
||||||
|
|
||||||
static Collection<Object[]> dataProvider() {
|
@Override
|
||||||
|
public Collection<Object[]> dataProvider() {
|
||||||
final List<Object[]> testData = new ArrayList<>();
|
final List<Object[]> testData = new ArrayList<>();
|
||||||
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
||||||
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user