Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 6a13298

Browse files
committed
fixed test issues in CI
1 parent 4d562cd commit 6a13298

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

webtester-core/src/main/java/info/novatec/testit/webtester/internal/proxies/impls/AbstractIdentifyUsingCollectionImpl.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import java.lang.reflect.Method;
77
import java.lang.reflect.ParameterizedType;
8-
import java.util.Arrays;
8+
import java.util.Collections;
99
import java.util.List;
1010
import java.util.function.Supplier;
1111

@@ -36,49 +36,49 @@ abstract class AbstractIdentifyUsingCollectionImpl implements Implementation {
3636
List<? extends PageFragment> getStreamOfPageFragmentsFor(Method method) {
3737

3838
IdentifyUsing identifyUsing = method.getAnnotation(IdentifyUsing.class);
39-
Class<?> type = method.getReturnType();
4039
Class<PageFragment> genericType = getGenericType(method);
4140
By by = ByProducers.createBy(identifyUsing);
4241

43-
waitIfAnnotationPresent(method, type, genericType, by);
42+
waitIfAnnotationPresent(method, genericType, by);
4443
return findPageFragments(genericType, by);
4544

4645
}
4746

48-
private void waitIfAnnotationPresent(Method method, Class<?> type, Class<PageFragment> genericType, By by) {
47+
private void waitIfAnnotationPresent(Method method, Class<PageFragment> genericType, By by) {
4948
WaitUntil annotation = method.getAnnotation(WaitUntil.class);
5049
if (annotation != null) {
51-
doWaitUntil(annotation, type, genericType, by);
50+
doWaitUntil(annotation, genericType, by);
5251
}
5352
}
5453

5554
@SuppressWarnings("unchecked")
56-
private void doWaitUntil(WaitUntil annotation, Class<?> type, Class<PageFragment> genericType, By by) {
55+
private void doWaitUntil(WaitUntil annotation, Class<PageFragment> genericType, By by) {
56+
Condition condition = getConditionInstance(annotation);
57+
assertConditionCanHandleCollection(condition);
58+
if (annotation.timeout() > 0) {
59+
Wait.withTimeoutOf(annotation.timeout(), annotation.unit())
60+
.untilSupplied(() -> findPageFragments(genericType, by))
61+
.is(condition);
62+
} else {
63+
Wait.untilSupplied(() -> findPageFragments(genericType, by)).is(condition);
64+
}
65+
}
66+
67+
private Condition getConditionInstance(WaitUntil annotation) {
5768
try {
58-
Condition condition = annotation.value().newInstance();
59-
assertConditionCanHandleCollection(type, condition);
60-
if (annotation.timeout() > 0) {
61-
Wait.withTimeoutOf(annotation.timeout(), annotation.unit())
62-
.untilSupplied(() -> findPageFragments(genericType, by))
63-
.is(condition);
64-
} else {
65-
Wait.untilSupplied(() -> findPageFragments(genericType, by)).is(condition);
66-
}
69+
return annotation.value().newInstance();
6770
} catch (InstantiationException | IllegalAccessException e) {
6871
throw new IllegalSignatureException(COULD_NOT_CREATE_PREDICATE_INSTANCE_MSG, e);
6972
}
7073
}
7174

72-
private void assertConditionCanHandleCollection(Class<?> type, Condition condition) {
73-
Class<? extends Condition> conditionClass = condition.getClass();
74-
Method testMethod = Arrays.stream(conditionClass.getMethods())//
75-
.filter(method -> "test".equals(method.getName()))
76-
.findFirst()
77-
.orElseThrow(() -> new IllegalStateException("test method not found"));
78-
if (!testMethod.getParameterTypes()[0].isAssignableFrom(type)) {
75+
@SuppressWarnings("unchecked")
76+
private void assertConditionCanHandleCollection(Condition condition) {
77+
try {
78+
condition.test(Collections.<List<? extends PageFragment>>emptyList());
79+
} catch (ClassCastException e) {
7980
throw new IllegalSignatureException(
80-
"Condition '" + conditionClass.getSimpleName() + "' cant't handle method return type '"
81-
+ type.getSimpleName() + "'");
81+
"Condition '" + condition.getClass().getSimpleName() + "' cant't handle List<? extends PageFragment>");
8282
}
8383
}
8484

webtester-core/src/test/java/info/novatec/testit/webtester/pagefragments/annotations/WaitUntilIntTest.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package info.novatec.testit.webtester.pagefragments.annotations;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.List;
67
import java.util.concurrent.TimeUnit;
78

8-
import org.junit.Before;
9-
import org.junit.Test;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
1011

1112
import utils.integration.BaseIntTest;
1213

@@ -19,38 +20,44 @@
1920
import info.novatec.testit.webtester.waiting.TimeoutException;
2021

2122

22-
public class WaitUntilIntTest extends BaseIntTest {
23+
class WaitUntilIntTest extends BaseIntTest {
2324

24-
@Before
25-
public void openPage() {
25+
@BeforeEach
26+
void openPage() {
2627
open("html/features/wait-annotation.html");
2728
}
2829

2930
@Test
30-
public void waitIsExecutedUntilConditionIsMet_PageFragment() {
31+
void waitIsExecutedUntilConditionIsMet_PageFragment() {
3132
FeaturePage page = browser().create(FeaturePage.class);
3233
assertThat(page.becomesVisibleLater().isVisible());
3334
}
3435

3536
@Test
36-
public void waitIsExecutedUntilConditionIsMet_Collection() {
37+
void waitIsExecutedUntilConditionIsMet_Collection() {
3738
CollectionsPage page = browser().create(CollectionsPage.class);
3839
assertThat(!page.becomeVisibleLater().isEmpty());
3940
}
4041

41-
@Test(expected = TimeoutException.class)
42-
public void timeoutExceptionIsThrownIfElementNeverMatches_PageFragment() {
43-
create(FeaturePage.class).neverPresent();
42+
@Test
43+
void timeoutExceptionIsThrownIfElementNeverMatches_PageFragment() {
44+
assertThrows(TimeoutException.class, () -> {
45+
create(FeaturePage.class).neverPresent();
46+
});
4447
}
4548

46-
@Test(expected = TimeoutException.class)
47-
public void timeoutExceptionIsThrownIfElementNeverMatches_Collection() {
48-
create(CollectionsPage.class).neverPresent();
49+
@Test
50+
void timeoutExceptionIsThrownIfElementNeverMatches_Collection() {
51+
assertThrows(TimeoutException.class, () -> {
52+
create(CollectionsPage.class).neverPresent();
53+
});
4954
}
5055

51-
@Test(expected = IllegalSignatureException.class)
52-
public void exceptionInCaseTheConditionDoesNotSupportTheMethodsReturnType() {
53-
create(CollectionsPage.class).wrongConditionType();
56+
@Test
57+
void exceptionInCaseTheConditionDoesNotSupportTheMethodsReturnType() {
58+
assertThrows(IllegalSignatureException.class, () -> {
59+
create(CollectionsPage.class).wrongConditionType();
60+
});
5461
}
5562

5663
/* test pages */

0 commit comments

Comments
 (0)