Migrate to JUnit5
This commit is contained in:
@ -22,7 +22,7 @@
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -22,9 +22,6 @@
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -34,11 +31,9 @@ import java.util.List;
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class HobbitsTest extends WeatherObserverTest<Hobbits> {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
static Collection<Object[]> dataProvider() {
|
||||
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.RAINY, "The hobbits look for cover from the rain."});
|
||||
@ -49,12 +44,9 @@ public class HobbitsTest extends WeatherObserverTest<Hobbits> {
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*
|
||||
* @param weather The weather that should be unleashed on the observer
|
||||
* @param response The expected response from the observer
|
||||
*/
|
||||
public HobbitsTest(final WeatherType weather, final String response) {
|
||||
super(weather, response, Hobbits::new);
|
||||
public HobbitsTest() {
|
||||
super(Hobbits::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,9 +22,6 @@
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -34,11 +31,9 @@ import java.util.List;
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class OrcsTest extends WeatherObserverTest<Orcs> {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
static Collection<Object[]> dataProvider() {
|
||||
final List<Object[]> testData = new ArrayList<>();
|
||||
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
||||
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
||||
@ -49,12 +44,9 @@ public class OrcsTest extends WeatherObserverTest<Orcs> {
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*
|
||||
* @param weather The weather that should be unleashed on the observer
|
||||
* @param response The expected response from the observer
|
||||
*/
|
||||
public OrcsTest(final WeatherType weather, final String response) {
|
||||
super(weather, response, Orcs::new);
|
||||
public OrcsTest() {
|
||||
super(Orcs::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,13 +22,16 @@
|
||||
*/
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||
import java.util.function.Supplier;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/27/15 - 11:44 AM
|
||||
@ -40,12 +43,12 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
appender.stop();
|
||||
}
|
||||
@ -55,38 +58,25 @@ public abstract class WeatherObserverTest<O extends WeatherObserver> {
|
||||
*/
|
||||
private final Supplier<O> factory;
|
||||
|
||||
/**
|
||||
* The weather type currently tested
|
||||
*/
|
||||
private final WeatherType weather;
|
||||
|
||||
/**
|
||||
* The expected response from the observer
|
||||
*/
|
||||
private final String response;
|
||||
|
||||
/**
|
||||
* Create a new test instance using the given parameters
|
||||
*
|
||||
* @param weather The weather currently being tested
|
||||
* @param response The expected response from the observer
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
*/
|
||||
WeatherObserverTest(final WeatherType weather, final String response, final Supplier<O> factory) {
|
||||
this.weather = weather;
|
||||
this.response = response;
|
||||
WeatherObserverTest(final Supplier<O> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the weather has the expected influence on the observer
|
||||
*/
|
||||
@Test
|
||||
public void testObserver() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("dataProvider")
|
||||
public void testObserver(WeatherType weather, String response) {
|
||||
final O observer = this.factory.get();
|
||||
assertEquals(0, appender.getLogSize());
|
||||
|
||||
observer.update(this.weather);
|
||||
observer.update(weather);
|
||||
assertEquals(response, appender.getLastMessage());
|
||||
assertEquals(1, appender.getLogSize());
|
||||
}
|
||||
|
@ -23,12 +23,12 @@
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -44,12 +44,12 @@ public class WeatherTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender(Weather.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
appender.stop();
|
||||
}
|
||||
|
@ -22,13 +22,8 @@
|
||||
*/
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.Hobbits;
|
||||
import com.iluwatar.observer.WeatherObserverTest;
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -38,11 +33,9 @@ import java.util.List;
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class GHobbitsTest extends ObserverTest<GHobbits> {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
static Collection<Object[]> dataProvider() {
|
||||
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.RAINY, "The hobbits look for cover from the rain."});
|
||||
@ -53,12 +46,9 @@ public class GHobbitsTest extends ObserverTest<GHobbits> {
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*
|
||||
* @param weather The weather that should be unleashed on the observer
|
||||
* @param response The expected response from the observer
|
||||
*/
|
||||
public GHobbitsTest(final WeatherType weather, final String response) {
|
||||
super(weather, response, GHobbits::new);
|
||||
public GHobbitsTest() {
|
||||
super(GHobbits::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ package com.iluwatar.observer.generic;
|
||||
import com.iluwatar.observer.WeatherObserver;
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
@ -42,12 +42,12 @@ public class GWeatherTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender(GWeather.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
appender.stop();
|
||||
}
|
||||
|
@ -22,14 +22,16 @@
|
||||
*/
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import com.iluwatar.observer.utils.InMemoryAppender;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/27/15 - 11:44 AM
|
||||
@ -41,12 +43,12 @@ public abstract class ObserverTest<O extends Observer> {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
appender.stop();
|
||||
}
|
||||
@ -56,39 +58,26 @@ public abstract class ObserverTest<O extends Observer> {
|
||||
*/
|
||||
private final Supplier<O> factory;
|
||||
|
||||
/**
|
||||
* The weather type currently tested
|
||||
*/
|
||||
private final WeatherType weather;
|
||||
|
||||
/**
|
||||
* The expected response from the observer
|
||||
*/
|
||||
private final String response;
|
||||
|
||||
/**
|
||||
* Create a new test instance using the given parameters
|
||||
*
|
||||
* @param weather The weather currently being tested
|
||||
* @param response The expected response from the observer
|
||||
* @param factory The factory, used to create an instance of the tested observer
|
||||
*/
|
||||
ObserverTest(final WeatherType weather, final String response, final Supplier<O> factory) {
|
||||
this.weather = weather;
|
||||
this.response = response;
|
||||
ObserverTest(final Supplier<O> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the weather has the expected influence on the observer
|
||||
*/
|
||||
@Test
|
||||
public void testObserver() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("dataProvider")
|
||||
public void testObserver(WeatherType weather, String response) {
|
||||
final O observer = this.factory.get();
|
||||
assertEquals(0, appender.getLogSize());
|
||||
|
||||
observer.update(null, this.weather);
|
||||
assertEquals(this.response, appender.getLastMessage());
|
||||
observer.update(null, weather);
|
||||
assertEquals(response, appender.getLastMessage());
|
||||
assertEquals(1, appender.getLogSize());
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,6 @@ package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -36,11 +33,9 @@ import java.util.List;
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class OrcsTest extends ObserverTest<GOrcs> {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
static Collection<Object[]> dataProvider() {
|
||||
final List<Object[]> testData = new ArrayList<>();
|
||||
testData.add(new Object[]{WeatherType.SUNNY, "The sun hurts the orcs' eyes."});
|
||||
testData.add(new Object[]{WeatherType.RAINY, "The orcs are dripping wet."});
|
||||
@ -51,12 +46,9 @@ public class OrcsTest extends ObserverTest<GOrcs> {
|
||||
|
||||
/**
|
||||
* Create a new test with the given weather and expected response
|
||||
*
|
||||
* @param weather The weather that should be unleashed on the observer
|
||||
* @param response The expected response from the observer
|
||||
*/
|
||||
public OrcsTest(final WeatherType weather, final String response) {
|
||||
super(weather, response, GOrcs::new);
|
||||
public OrcsTest() {
|
||||
super(GOrcs::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user