Skip to content

Commit

Permalink
Switch to junit-native MethodSource for data. (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clockwork-Muse committed Jun 8, 2022
1 parent e8f3c94 commit a32fd5d
Show file tree
Hide file tree
Showing 31 changed files with 423 additions and 674 deletions.
31 changes: 12 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@
</build>

<!-- ==================================================================== -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.joda</groupId>
Expand Down Expand Up @@ -523,28 +534,10 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.junit.dataprovider</groupId>
<artifactId>junit-jupiter-params-dataprovider</artifactId>
<version>2.8</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- ==================================================================== -->
Expand Down
28 changes: 9 additions & 19 deletions src/test/java/org/threeten/extra/TestAmountFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

import com.tngtech.junit.dataprovider.DataProvider;
import com.tngtech.junit.dataprovider.UseDataProvider;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test AmountFormats.
Expand All @@ -62,7 +60,6 @@ public void test_iso8601() {
}

//-----------------------------------------------------------------------
@DataProvider
public static Object[][] data_wordBased() {
return new Object[][] {
{Period.ofYears(0), Locale.ROOT, "0 days"},
Expand Down Expand Up @@ -100,12 +97,11 @@ public static Object[][] data_wordBased() {
}

@ParameterizedTest
@UseDataProvider("data_wordBased")
@MethodSource("data_wordBased")
public void test_wordBased(Period period, Locale locale, String expected) {
assertEquals(expected, AmountFormats.wordBased(period, locale));
}

@DataProvider
public static Object[][] duration_wordBased() {
return new Object[][] {
{Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours and 2 minutes"},
Expand Down Expand Up @@ -136,12 +132,11 @@ public static Object[][] duration_wordBased() {
}

@ParameterizedTest
@UseDataProvider("duration_wordBased")
@MethodSource("duration_wordBased")
public void test_wordBased(Duration duration, Locale locale, String expected) {
assertEquals(expected, AmountFormats.wordBased(duration, locale));
}

@DataProvider
public static Object[][] period_duration_wordBased() {
return new Object[][] {
{Period.ofDays(1), Duration.ofMinutes(180 + 2), Locale.ROOT, "1 day, 3 hours and 2 minutes"},
Expand All @@ -163,7 +158,7 @@ public static Object[][] period_duration_wordBased() {
}

@ParameterizedTest
@UseDataProvider("period_duration_wordBased")
@MethodSource("period_duration_wordBased")
public void test_wordBased(Period period, Duration duration, Locale locale, String expected) {
assertEquals(expected, AmountFormats.wordBased(period, duration, locale));
}
Expand Down Expand Up @@ -296,12 +291,11 @@ public void test_wordBased_ru_formatStandard() {

// -----------------------------------------------------------------------
@ParameterizedTest
@UseDataProvider("wordBased_ru_formatSeparator")
@MethodSource("wordBased_ru_formatSeparator")
public void test_wordBased_ru_formatSeparator(String expected, Duration duration) {
assertEquals(expected, AmountFormats.wordBased(duration, RU));
}

@DataProvider
public static Object[][] wordBased_ru_formatSeparator() {
return new Object[][]{
{"18 \u0447\u0430\u0441\u043E\u0432 \u0438 32 \u043C\u0438\u043D\u0443\u0442\u044B", Duration.ofMinutes(1112)},
Expand All @@ -311,12 +305,11 @@ public static Object[][] wordBased_ru_formatSeparator() {

// -----------------------------------------------------------------------
@ParameterizedTest
@UseDataProvider("wordBased_ru_period_predicate")
@MethodSource("wordBased_ru_period_predicate")
public void test_wordBased_ru_period_predicate(String expected, Period period) {
assertEquals(expected, AmountFormats.wordBased(period, RU));
}

@DataProvider
public static Object[][] wordBased_ru_period_predicate() {
return new Object[][]{

Expand Down Expand Up @@ -439,12 +432,11 @@ public static Object[][] wordBased_ru_period_predicate() {

// -----------------------------------------------------------------------
@ParameterizedTest
@UseDataProvider("wordBased_ru_duration_predicate")
@MethodSource("wordBased_ru_duration_predicate")
public void test_wordBased_ru_duration_predicate(String expected, Duration duration) {
assertEquals(expected, AmountFormats.wordBased(duration, RU));
}

@DataProvider
public static Object[][] wordBased_ru_duration_predicate() {
return new Object[][]{

Expand Down Expand Up @@ -544,12 +536,11 @@ public static Object[][] wordBased_ru_duration_predicate() {

// -----------------------------------------------------------------------
@ParameterizedTest
@UseDataProvider("duration_unitBased")
@MethodSource("duration_unitBased")
public void test_parseUnitBasedDuration(Duration expected, String input) {
assertEquals(expected, AmountFormats.parseUnitBasedDuration(input));
}

@DataProvider
public static Object[][] duration_unitBased() {
return new Object[][] {
{Duration.ZERO, "0"},
Expand All @@ -574,7 +565,7 @@ public static Object[][] duration_unitBased() {
}

@ParameterizedTest
@UseDataProvider("duration_unitBasedErrors")
@MethodSource("duration_unitBasedErrors")
public void test_parseUnitBasedDurationErrors(Exception e, String input) {
Exception thrown =
assertThrows(e.getClass(), () -> AmountFormats.parseUnitBasedDuration(input));
Expand All @@ -587,7 +578,6 @@ public void test_parseUnitBasedDurationErrors(Exception e, String input) {
}
}

@DataProvider
public static Object[][] duration_unitBasedErrors() {
return new Object[][] {
{new NullPointerException("durationText must not be null"), null},
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/org/threeten/extra/TestConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@

import org.joda.convert.StringConvert;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.threeten.extra.scale.TaiInstant;
import org.threeten.extra.scale.UtcInstant;

import com.tngtech.junit.dataprovider.DataProvider;
import com.tngtech.junit.dataprovider.UseDataProvider;

public class TestConvert {

@DataProvider
public static Object[][] data_inputs() {
return new Object[][] {
{Seconds.of(23), "PT23S"},
Expand All @@ -69,13 +66,13 @@ public static Object[][] data_inputs() {
}

@ParameterizedTest
@UseDataProvider("data_inputs")
@MethodSource("data_inputs")
public void test_convertToString(Object obj, String str) {
assertEquals(str, StringConvert.INSTANCE.convertToString(obj));
}

@ParameterizedTest
@UseDataProvider("data_inputs")
@MethodSource("data_inputs")
public void test_convertFromString(Object obj, String str) {
assertEquals(obj, StringConvert.INSTANCE.convertFromString(obj.getClass(), str));
}
Expand Down
14 changes: 5 additions & 9 deletions src/test/java/org/threeten/extra/TestDays.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

import com.tngtech.junit.dataprovider.DataProvider;
import com.tngtech.junit.dataprovider.UseDataProvider;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test class.
Expand Down Expand Up @@ -182,7 +180,6 @@ public void test_from_null() {
}

//-----------------------------------------------------------------------
@DataProvider
public static Object[][] data_valid() {
return new Object[][] {
{"P0D", 0},
Expand Down Expand Up @@ -214,24 +211,23 @@ public static Object[][] data_valid() {
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid(String str, int expectedDays) {
assertEquals(Days.of(expectedDays), Days.parse(str));
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) {
assertEquals(Days.of(expectedDays), Days.parse("+" + str));
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) {
assertEquals(Days.of(-expectedDays), Days.parse("-" + str));
}

@DataProvider
public static Object[][] data_invalid() {
return new Object[][] {
{"P3Y"},
Expand All @@ -252,7 +248,7 @@ public static Object[][] data_invalid() {
}

@ParameterizedTest
@UseDataProvider("data_invalid")
@MethodSource("data_invalid")
public void test_parse_CharSequence_invalid(String str) {
assertThrows(DateTimeParseException.class, () -> Days.parse(str));
}
Expand Down
14 changes: 5 additions & 9 deletions src/test/java/org/threeten/extra/TestHours.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

import com.tngtech.junit.dataprovider.DataProvider;
import com.tngtech.junit.dataprovider.UseDataProvider;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test class.
Expand Down Expand Up @@ -116,7 +114,6 @@ public void test_ofPlusOne() {
}

//-----------------------------------------------------------------------
@DataProvider
public static Object[][] data_valid() {
return new Object[][] {
{"PT0H", 0},
Expand All @@ -143,24 +140,23 @@ public static Object[][] data_valid() {
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid(String str, int expectedDays) {
assertEquals(Hours.of(expectedDays), Hours.parse(str));
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) {
assertEquals(Hours.of(expectedDays), Hours.parse("+" + str));
}

@ParameterizedTest
@UseDataProvider("data_valid")
@MethodSource("data_valid")
public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) {
assertEquals(Hours.of(-expectedDays), Hours.parse("-" + str));
}

@DataProvider
public static Object[][] data_invalid() {
return new Object[][] {
{"P3W"},
Expand All @@ -181,7 +177,7 @@ public static Object[][] data_invalid() {
}

@ParameterizedTest
@UseDataProvider("data_invalid")
@MethodSource("data_invalid")
public void test_parse_CharSequence_invalid(String str) {
assertThrows(DateTimeParseException.class, () -> Hours.parse(str));
}
Expand Down

0 comments on commit a32fd5d

Please sign in to comment.