Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gitar] Migrating from JUnit4 to JUnit5 #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions java/junit4to5/SampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,44 @@
package co.gitar;

import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class SampleTest extends BaseTest {
@BeforeClass
@BeforeAll
public static void setup() {
// ...
}

@Before
@BeforeEach
public void reset() {
// ...
}

@Test
public void test1() {
Assert.assertThat(asList("c", "a", "b"), containsInAnyOrder("a", "b", "c"));
assertThat(asList("c", "a", "b"), containsInAnyOrder("a", "b", "c"));
}

@Test
@Ignore
@Disabled
public void test2() {
String[] a1 = new String[] {"c", "a", "b"};
String[] a2 = new String[3];
a2[0] = "a";
a2[1] = "b";
a2[2] = "c";
Assert.assertEquals(a1[0], "c");
Assert.assertEquals(a1, a2);
assertThat("c", equalTo(a1[0]));
assertArrayEquals(a1, a2);
}
}