Skip to content

Commit

Permalink
update AssetThat
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 committed Apr 24, 2021
1 parent ab1ce5e commit 5497670
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/tvd12/test/assertion/AssertSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tvd12.test.assertion;

public interface AssertSupplier {
public interface AssertSupplier<T> {

Object apply() throws Throwable;
T apply() throws Throwable;

}
22 changes: 11 additions & 11 deletions src/main/java/com/tvd12/test/assertion/AssertThat.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

public class AssertThat {
public class AssertThat<T> {

private Object actual;
private AssertSupplier actualSupplier;
private T actual;
private AssertSupplier<T> actualSupplier;

public AssertThat(Object actual) {
public AssertThat(T actual) {
this.actual = actual;
}

public AssertThat(AssertSupplier actualSupplier) {
public AssertThat(AssertSupplier<T> actualSupplier) {
this.actualSupplier = actualSupplier;
}

Expand All @@ -37,7 +37,7 @@ public boolean isNotNull() {
return Asserts.assertNotNull(actual);
}

public boolean test(Predicate<Object> predicate) {
public boolean test(Predicate<T> predicate) {
try {
actual = getActualValue();
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public boolean isEqualsTo(Object expected, boolean mustEqualsType) {
return Asserts.assertEquals(expected, actual, mustEqualsType);
}

public boolean isEqualsTo(AssertSupplier expectedSupplier) {
public boolean isEqualsTo(AssertSupplier<T> expectedSupplier) {
Object expected = null;
try {
expected = expectedSupplier.apply();
Expand Down Expand Up @@ -120,11 +120,11 @@ public boolean testException(Predicate<Throwable> exceptionPredicate) {
}
}

@SuppressWarnings("rawtypes")
private Object getActualValue() throws Throwable {
Object answer = actualSupplier != null ? actualSupplier.apply() : actual;
@SuppressWarnings("unchecked")
private T getActualValue() throws Throwable {
T answer = actualSupplier != null ? actualSupplier.apply() : actual;
if(answer instanceof Future)
answer = ((Future)answer).get();
answer = ((Future<T>)answer).get();
return answer;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/tvd12/test/assertion/Asserts.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public static boolean assertNotNull(Object actual) {
return true;
}

public static AssertThat assertThat(Object actual) {
return new AssertThat(actual);
public static <T> AssertThat<T> assertThat(T actual) {
return new AssertThat<>(actual);
}

public static AssertThat assertThat(AssertSupplier actualSuppler) {
return new AssertThat(actualSuppler);
public static <T> AssertThat<T> assertThat(AssertSupplier<T> actualSuppler) {
return new AssertThat<>(actualSuppler);
}

public static Throwable assertThrows(AssertApplier func) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/tvd12/test/testing/util/RandomUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void randomWrapperArray() {
}

@Test
@SuppressWarnings("unchecked")
public void randomWrapperListByType() {
Asserts.assertThat(RandomUtil.randomList(8, Boolean.class))
.test(it -> ((List<Boolean>)it).size() == 8);
Expand All @@ -137,7 +136,6 @@ public void randomWrapperListByType() {
}

@Test
@SuppressWarnings("unchecked")
public void randomWrapperListByRandom() {
Asserts.assertThat(RandomUtil.randomList(8, it -> it.nextBoolean()))
.test(it -> ((List<Boolean>)it).size() == 8);
Expand Down

0 comments on commit 5497670

Please sign in to comment.