Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa0865b

Browse filesBrowse files
committed
Fix assertThat arch test
1 parent e629a23 commit fa0865b
Copy full SHA for fa0865b

File tree

Expand file treeCollapse file tree

3 files changed

+32
-19
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-19
lines changed

‎src/test/java/org/kohsuke/github/ArchTests.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/ArchTests.java
+17-9Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
import com.tngtech.archunit.base.DescribedPredicate;
44
import com.tngtech.archunit.core.domain.JavaAnnotation;
55
import com.tngtech.archunit.core.domain.JavaClasses;
6+
import com.tngtech.archunit.core.domain.properties.HasName;
67
import com.tngtech.archunit.core.importer.ClassFileImporter;
78
import com.tngtech.archunit.core.importer.ImportOption;
89
import com.tngtech.archunit.lang.ArchRule;
910
import org.junit.BeforeClass;
1011
import org.junit.Test;
1112

13+
import static com.tngtech.archunit.core.domain.JavaCall.Predicates.target;
14+
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.name;
15+
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.nameContaining;
1216
import static com.tngtech.archunit.lang.conditions.ArchConditions.*;
1317
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
1418
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
1519
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
16-
import static org.junit.Assert.assertTrue;
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.hamcrest.Matchers.greaterThan;
1722

1823
public class ArchTests {
1924

@@ -22,7 +27,9 @@ public class ArchTests {
2227
.withImportOption(new ImportOption.DoNotIncludeJars())
2328
.importPackages("org.kohsuke.github");
2429

25-
private static final JavaClasses tesetClassFiles = new ClassFileImporter()
30+
private static final JavaClasses apacheCommons = new ClassFileImporter().importPackages("org.apache.commons.lang3");
31+
32+
private static final JavaClasses testClassFiles = new ClassFileImporter()
2633
.withImportOption(new ImportOption.OnlyIncludeTests())
2734
.withImportOption(new ImportOption.DoNotIncludeJars())
2835
.importPackages("org.kohsuke.github");
@@ -40,7 +47,7 @@ public boolean apply(JavaAnnotation<?> javaAnnotation) {
4047

4148
@BeforeClass
4249
public static void beforeClass() {
43-
assertTrue(classFiles.size() > 0);
50+
assertThat(classFiles.size(), greaterThan(0));
4451
}
4552

4653
@Test
@@ -113,14 +120,15 @@ public void testBetaApisAreFlaggedAsDeprecated() {
113120
@Test
114121
public void testRequireUseOfAssertThat() {
115122

116-
String reason = "This project uses `assertThat(...)` instead of other assert*() methods.";
123+
final String reason = "This project uses `assertThat(...)` instead of other `assert*()` methods.";
117124

118-
ArchRule onlyAssertThatRule = methods().that()
119-
.haveNameContaining("assert")
120-
.should()
121-
.haveName("assertThat")
125+
final DescribedPredicate<HasName> assertMethodOtherThanAssertThat = nameContaining("assert")
126+
.and(DescribedPredicate.not(name("assertThat")));
127+
128+
final ArchRule onlyAssertThatRule = classes()
129+
.should(not(callMethodWhere(target(assertMethodOtherThanAssertThat))))
122130
.because(reason);
123131

124-
onlyAssertThatRule.check(tesetClassFiles);
132+
onlyAssertThatRule.check(testClassFiles);
125133
}
126134
}

‎src/test/java/org/kohsuke/github/GHPullRequestMockTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHPullRequestMockTest.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.io.IOException;
66

7-
import static org.junit.Assert.assertTrue;
7+
import static org.hamcrest.MatcherAssert.assertThat;
88
import static org.mockito.Mockito.mock;
99
import static org.mockito.Mockito.when;
1010

@@ -15,7 +15,7 @@ public void shouldMockGHPullRequest() throws IOException {
1515
GHPullRequest pullRequest = mock(GHPullRequest.class);
1616
when(pullRequest.isDraft()).thenReturn(true);
1717

18-
assertTrue("Mock should return true", pullRequest.isDraft());
18+
assertThat("Mock should return true", pullRequest.isDraft());
1919
}
2020

2121
}

‎src/test/java/org/kohsuke/github/internal/EnumUtilsTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/internal/EnumUtilsTest.java
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22

33
import org.junit.Test;
44

5-
import static org.junit.Assert.assertEquals;
6-
import static org.junit.Assert.assertNull;
5+
import static org.hamcrest.MatcherAssert.assertThat;
6+
import static org.hamcrest.Matchers.*;
77

88
public class EnumUtilsTest {
99

1010
@Test
1111
public void testGetEnum() {
12-
assertNull(EnumUtils.getNullableEnumOrDefault(TestEnum.class, null, TestEnum.UNKNOWN));
13-
assertEquals(TestEnum.UNKNOWN, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "foobar", TestEnum.UNKNOWN));
14-
assertEquals(TestEnum.VALUE_1, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_1", TestEnum.UNKNOWN));
15-
assertEquals(TestEnum.VALUE_1, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "value_1", TestEnum.UNKNOWN));
16-
assertEquals(TestEnum.VALUE_2, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_2", TestEnum.UNKNOWN));
17-
assertEquals(TestEnum.VALUE_2, EnumUtils.getNullableEnumOrDefault(TestEnum.class, "value_2", TestEnum.UNKNOWN));
12+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, null, TestEnum.UNKNOWN), nullValue());
13+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, "foobar", TestEnum.UNKNOWN),
14+
equalTo(TestEnum.UNKNOWN));
15+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_1", TestEnum.UNKNOWN),
16+
equalTo(TestEnum.VALUE_1));
17+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, "value_1", TestEnum.UNKNOWN),
18+
equalTo(TestEnum.VALUE_1));
19+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, "VALUE_2", TestEnum.UNKNOWN),
20+
equalTo(TestEnum.VALUE_2));
21+
assertThat(EnumUtils.getNullableEnumOrDefault(TestEnum.class, "vAlUe_2 ", TestEnum.UNKNOWN),
22+
equalTo(TestEnum.VALUE_2));
1823
}
1924

2025
private enum TestEnum {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.