Skip to content

Commit

Permalink
Revert "Removed unnecessary assertion that duplicates the JUnit asser…
Browse files Browse the repository at this point in the history
…tion in full"

This reverts commit 7f89558.
  • Loading branch information
lyubomyr-shaydariv committed Sep 22, 2024
1 parent 31970eb commit 668992e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/test/java/lsh/ext/gson/ParameterizedTypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Type;

import lsh.ext.gson.test.MoreAssertions;
import lsh.ext.gson.test.Types;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -17,19 +18,18 @@ public void testGetTypeArgumentForParameterizedType() {

@Test
public void testGetTypeArgumentForParameterizedTypeGoesBeyond() {
Assertions.assertThrows(
MoreAssertions.assertThrows(
IllegalArgumentException.class,
() -> ParameterizedTypes.getTypeArgument(Types.stringListTypeToken.getType(), 1),
"1 is out of bounds for java.util.List<java.lang.String> that has 1 type argument(s)"
"1 is out of bounds for java.util.List<java.lang.String> that has 1 type argument(s)",
() -> ParameterizedTypes.getTypeArgument(Types.stringListTypeToken.getType(), 1)
);
}

@Test
public void testGetTypeArgumentForParameterizedTypeIsBelowZero() {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> ParameterizedTypes.getTypeArgument(Types.stringListTypeToken.getType(), -1),
"-1 is out of bounds for java.util.List<java.lang.String> that has 1 type argument(s)"
MoreAssertions.assertThrows(
IllegalArgumentException.class, "-1 is out of bounds for java.util.List<java.lang.String> that has 1 type argument(s)",
() -> ParameterizedTypes.getTypeArgument(Types.stringListTypeToken.getType(), -1)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;

import com.google.gson.TypeAdapter;
import lsh.ext.gson.test.MoreAssertions;
import lsh.ext.gson.test.TypeAdapters;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -31,11 +32,7 @@ public void testReadForSingleProperty()

@Test
public void testReadForMultipleProperties() {
Assertions.assertThrows(
IllegalStateException.class,
() -> unit.fromJson("{\"3.14\":1,\"2.7\":3,\"UNREACHABLE\":\"UNREACHABLE\"}"),
"Expected a single property object with key `3.14` but also encountered `2.7`"
);
MoreAssertions.assertThrows(IllegalStateException.class, "Expected a single property object with key `3.14` but also encountered `2.7`", () -> unit.fromJson("{\"3.14\":1,\"2.7\":3,\"UNREACHABLE\":\"UNREACHABLE\"}"));
}

}
15 changes: 15 additions & 0 deletions src/test/java/lsh/ext/gson/test/MoreAssertions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lsh.ext.gson.test;

import lombok.experimental.UtilityClass;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;

@UtilityClass
public final class MoreAssertions {

public static <EX extends Throwable> void assertThrows(final Class<EX> expectedClass, final String expectedMessage, final Executable executable) {
final EX ex = Assertions.assertThrows(expectedClass, executable);
Assertions.assertEquals(expectedMessage, ex.getMessage());
}

}

0 comments on commit 668992e

Please sign in to comment.