Skip to content

Commit 1550442

Browse files
authored
Address junit deprecations (#29)
Signed-off-by: Dan Siwiec <daniel.siwiec@gmail.com>
1 parent c2d2e6f commit 1550442

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

core/src/test/java/feast/core/service/ProjectServiceTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
*/
1717
package feast.core.service;
1818

19-
import static org.mockito.Mockito.mock;
20-
import static org.mockito.Mockito.times;
21-
import static org.mockito.Mockito.verify;
22-
import static org.mockito.Mockito.when;
19+
import static org.junit.jupiter.api.Assertions.assertThrows;
20+
import static org.mockito.Mockito.*;
2321
import static org.mockito.MockitoAnnotations.initMocks;
2422

2523
import feast.core.dao.ProjectRepository;
@@ -29,16 +27,12 @@
2927
import java.util.Optional;
3028
import org.junit.Assert;
3129
import org.junit.Before;
32-
import org.junit.Rule;
3330
import org.junit.Test;
34-
import org.junit.rules.ExpectedException;
3531
import org.mockito.Mock;
3632

3733
public class ProjectServiceTest {
3834

3935
@Mock private ProjectRepository projectRepository;
40-
@Rule public final ExpectedException expectedException = ExpectedException.none();
41-
4236
private ProjectService projectService;
4337

4438
@Before
@@ -75,8 +69,9 @@ public void shouldArchiveProjectIfItExists() {
7569

7670
@Test
7771
public void shouldNotArchiveDefaultProject() {
78-
expectedException.expect(IllegalArgumentException.class);
79-
this.projectService.archiveProject(Project.DEFAULT_NAME);
72+
assertThrows(
73+
IllegalArgumentException.class,
74+
() -> this.projectService.archiveProject(Project.DEFAULT_NAME));
8075
}
8176

8277
@Test(expected = IllegalArgumentException.class)

core/src/test/java/feast/core/util/TypeConversionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package feast.core.util;
1818

1919
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
20+
import static org.hamcrest.MatcherAssert.assertThat;
2021
import static org.hamcrest.Matchers.equalTo;
21-
import static org.junit.Assert.*;
2222

2323
import com.google.protobuf.Timestamp;
2424
import java.util.*;

core/src/test/java/feast/core/validators/MatchersTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import static feast.core.validators.Matchers.checkLowerSnakeCase;
2020
import static feast.core.validators.Matchers.checkUpperSnakeCase;
2121
import static feast.core.validators.Matchers.checkValidClassPath;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
2223

2324
import com.google.common.base.Strings;
24-
import org.junit.Rule;
2525
import org.junit.Test;
26-
import org.junit.rules.ExpectedException;
2726

2827
public class MatchersTest {
29-
@Rule public final ExpectedException exception = ExpectedException.none();
3028

3129
@Test
3230
public void checkUpperSnakeCaseShouldPassForLegitUpperSnakeCase() {
@@ -42,15 +40,15 @@ public void checkUpperSnakeCaseShouldPassForLegitUpperSnakeCaseWithNumbers() {
4240

4341
@Test
4442
public void checkUpperSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForInvalidString() {
45-
exception.expect(IllegalArgumentException.class);
46-
exception.expectMessage(
43+
String in = "redis";
44+
assertThrows(
45+
IllegalArgumentException.class,
46+
() -> checkUpperSnakeCase(in, "featuretable"),
4747
Strings.lenientFormat(
4848
"invalid value for %s resource, %s: %s",
4949
"featuretable",
5050
"redis",
5151
"argument must be in upper snake case, and cannot include any special characters."));
52-
String in = "redis";
53-
checkUpperSnakeCase(in, "featuretable");
5452
}
5553

5654
@Test
@@ -61,15 +59,15 @@ public void checkLowerSnakeCaseShouldPassForLegitLowerSnakeCase() {
6159

6260
@Test
6361
public void checkLowerSnakeCaseShouldThrowIllegalArgumentExceptionWithFieldForInvalidString() {
64-
exception.expect(IllegalArgumentException.class);
65-
exception.expectMessage(
62+
String in = "Invalid_feature name";
63+
assertThrows(
64+
IllegalArgumentException.class,
65+
() -> checkLowerSnakeCase(in, "feature"),
6666
Strings.lenientFormat(
6767
"invalid value for %s resource, %s: %s",
6868
"feature",
6969
"Invalid_feature name",
7070
"argument must be in lower snake case, and cannot include any special characters."));
71-
String in = "Invalid_feature name";
72-
checkLowerSnakeCase(in, "feature");
7371
}
7472

7573
@Test
@@ -80,13 +78,11 @@ public void checkValidClassPathSuccess() {
8078

8179
@Test
8280
public void checkValidClassPathEmpty() {
83-
exception.expect(IllegalArgumentException.class);
84-
checkValidClassPath("", "FeatureTable");
81+
assertThrows(IllegalArgumentException.class, () -> checkValidClassPath("", "FeatureTable"));
8582
}
8683

8784
@Test
8885
public void checkValidClassPathDigits() {
89-
exception.expect(IllegalArgumentException.class);
90-
checkValidClassPath("123", "FeatureTable");
86+
assertThrows(IllegalArgumentException.class, () -> checkValidClassPath("123", "FeatureTable"));
9187
}
9288
}

0 commit comments

Comments
 (0)