Unverified Commit ece38ecd authored by Gautier de Saint Martin Lacaze's avatar Gautier de Saint Martin Lacaze Committed by GitHub
Browse files

Merge pull request #750 from gitlab4j/issue-691

Migrate from JUnit 4 to JUnit 5
parents 73817d15 a1b28ea1
package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.util.List;
import java.util.Optional;
......@@ -15,13 +15,12 @@ import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProtectedTag;
import org.gitlab4j.api.models.Release;
import org.gitlab4j.api.models.Tag;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@Category(IntegrationTest.class)
@org.junit.jupiter.api.Tag("integration")
public class TestTagsApi extends AbstractIntegrationTest {
private static final String TEST_TAG_NAME_1 = "test-tag-1";
......@@ -36,7 +35,7 @@ public class TestTagsApi extends AbstractIntegrationTest {
super();
}
@BeforeClass
@BeforeAll
public static void testSetup() {
// Must setup the connection to the GitLab test server and get the test Project instance
......@@ -52,7 +51,7 @@ public class TestTagsApi extends AbstractIntegrationTest {
}
}
@AfterClass
@AfterAll
public static void tearDown() {
deleteTestTags();
}
......@@ -82,7 +81,7 @@ public class TestTagsApi extends AbstractIntegrationTest {
}
}
@Before
@BeforeEach
public void beforeMethod() {
assumeTrue(testProject != null);
}
......
package org.gitlab4j.api;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.util.List;
import java.util.Random;
import org.gitlab4j.api.Constants.TodoState;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.Todo;
import org.gitlab4j.api.models.User;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeNotNull;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
......@@ -25,7 +28,8 @@ import static org.junit.Assume.assumeNotNull;
* <p>
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
@Tag("integration")
@ExtendWith(SetupIntegrationTestExtension.class)
public class TestTodosApi extends AbstractIntegrationTest {
private static GitLabApi gitLabApi;
......@@ -39,7 +43,7 @@ public class TestTodosApi extends AbstractIntegrationTest {
super();
}
@BeforeClass
@BeforeAll
public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
......@@ -49,7 +53,7 @@ public class TestTodosApi extends AbstractIntegrationTest {
deleteAllTestIssues();
}
@AfterClass
@AfterAll
public static void teardown() throws GitLabApiException {
deleteAllTestIssues();
}
......@@ -72,9 +76,9 @@ public class TestTodosApi extends AbstractIntegrationTest {
}
}
@Before
@BeforeEach
public void beforeMethod() {
assumeNotNull(gitLabApi);
assumeTrue(gitLabApi != null);
}
private static String getUniqueTitle() {
......
......@@ -2,18 +2,18 @@ package org.gitlab4j.api;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.MockitoAnnotations.openMocks;
import java.util.Collections;
import javax.ws.rs.core.MultivaluedMap;
import org.gitlab4j.api.models.MergeRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
......@@ -26,9 +26,9 @@ public class TestUnitMergeRequestApi {
@Captor private ArgumentCaptor<MultivaluedMap<String, String>> attributeCaptor;
private MockResponse mockedResponse;
@Before
@BeforeEach
public void setUp() throws Exception {
initMocks(this);
openMocks(this);
mockedResponse = new MockResponse(MergeRequest.class, "merge-request.json", null);
when(mockGitLabApi.getApiClient()).thenReturn(mockedGitLabApiClient);
......
......@@ -3,9 +3,8 @@ package org.gitlab4j.api;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.io.FileInputStream;
......@@ -13,12 +12,13 @@ import java.io.FileNotFoundException;
import java.util.Map;
import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Project;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
......@@ -30,8 +30,10 @@ import org.junit.runners.MethodSorters;
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Tag("integration")
@ExtendWith(SetupIntegrationTestExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestUpload extends AbstractIntegrationTest {
// The following needs to be set to your test repository
......@@ -45,15 +47,15 @@ public class TestUpload extends AbstractIntegrationTest {
super();
}
@BeforeClass
@BeforeAll
public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi = baseTestSetup();
}
@Before
@BeforeEach
public void beforeMethod() {
assumeNotNull(gitLabApi);
assumeTrue(gitLabApi != null);
}
@Test
......
......@@ -2,14 +2,13 @@ package org.gitlab4j.api;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.text.ParseException;
import java.util.Date;
......@@ -29,10 +28,11 @@ import org.gitlab4j.api.models.SshKey;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.models.Version;
import org.gitlab4j.api.utils.ISO8601;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
......@@ -52,7 +52,8 @@ import org.junit.experimental.categories.Category;
* If this is null the SSH key tests will be skipped.
*
*/
@Category(IntegrationTest.class)
@Tag("integration")
@ExtendWith(SetupIntegrationTestExtension.class)
public class TestUserApi extends AbstractIntegrationTest {
// The following needs to be set to your test repository
......@@ -132,7 +133,7 @@ public class TestUserApi extends AbstractIntegrationTest {
super();
}
@BeforeClass
@BeforeAll
public static void setup() {
String problems = "";
......@@ -193,9 +194,9 @@ public class TestUserApi extends AbstractIntegrationTest {
}
}
@Before
@BeforeEach
public void beforeMethod() {
assumeNotNull(gitLabApi);
assumeTrue(gitLabApi != null);
}
@Test
......@@ -223,7 +224,7 @@ public class TestUserApi extends AbstractIntegrationTest {
@Test
public void testBlockUnblockUser() throws GitLabApiException {
assumeNotNull(blockUser);
assumeTrue(blockUser != null);
assertNotEquals("blocked", blockUser.getState());
gitLabApi.getUserApi().blockUser(blockUser.getId());
......@@ -251,9 +252,9 @@ public class TestUserApi extends AbstractIntegrationTest {
@Test
public void testExternalUid() throws GitLabApiException {
assumeNotNull(TEST_EXTERNAL_USERNAME);
assumeNotNull(TEST_EXTERNAL_PROVIDER);
assumeNotNull(TEST_EXTERNAL_UID);
assumeTrue(TEST_EXTERNAL_USERNAME != null);
assumeTrue(TEST_EXTERNAL_PROVIDER != null);
assumeTrue(TEST_EXTERNAL_UID != null);
User externalUser = null;
try {
......@@ -423,18 +424,18 @@ public class TestUserApi extends AbstractIntegrationTest {
assumeTrue(TEST_SSH_KEY != null);
SshKey sshKey = gitLabApi.getUserApi().addSshKey("Test-Key", TEST_SSH_KEY);
assertNotNull(sshKey);
assertTrue(TEST_SSH_KEY, sshKey.getKey().startsWith(TEST_SSH_KEY));
assertTrue(sshKey.getKey().startsWith(TEST_SSH_KEY), TEST_SSH_KEY);
gitLabApi.getUserApi().deleteSshKey(sshKey.getId());
User user = gitLabApi.getUserApi().getCurrentUser();
sshKey = gitLabApi.getUserApi().addSshKey(user.getId(), "Test-Key1", TEST_SSH_KEY);
assertNotNull(sshKey);
assertTrue(TEST_SSH_KEY, sshKey.getKey().startsWith(TEST_SSH_KEY));
assertTrue(sshKey.getKey().startsWith(TEST_SSH_KEY), TEST_SSH_KEY);
assertEquals(user.getId(), sshKey.getUserId());
Optional<SshKey> optional = gitLabApi.getUserApi().getOptionalSshKey(sshKey.getId());
assertNotNull(optional.isPresent());
assertTrue(TEST_SSH_KEY, sshKey.getKey().startsWith(TEST_SSH_KEY));
assertTrue(sshKey.getKey().startsWith(TEST_SSH_KEY), TEST_SSH_KEY);
gitLabApi.getUserApi().deleteSshKey(sshKey.getId());
}
......
......@@ -23,10 +23,10 @@
package org.gitlab4j.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.util.List;
......@@ -34,11 +34,12 @@ import java.util.List;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.WikiAttachment;
import org.gitlab4j.api.models.WikiPage;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
......@@ -50,7 +51,8 @@ import org.junit.experimental.categories.Category;
* <p>
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
@Tag("integration")
@ExtendWith(SetupIntegrationTestExtension.class)
public class TestWikisApi extends AbstractIntegrationTest {
private static final String TEST_WIKI_TITLE_PREFIX = "Test Wiki: ";
......@@ -62,7 +64,7 @@ public class TestWikisApi extends AbstractIntegrationTest {
super();
}
@BeforeClass
@BeforeAll
public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
......@@ -73,7 +75,7 @@ public class TestWikisApi extends AbstractIntegrationTest {
deleteAllTestWikiPages();
}
@AfterClass
@AfterAll
public static void teardown() throws GitLabApiException {
deleteAllTestWikiPages();
}
......@@ -94,9 +96,9 @@ public class TestWikisApi extends AbstractIntegrationTest {
}
}
@Before
@BeforeEach
public void beforeMethod() {
assumeNotNull(testProject);
assumeTrue(testProject != null);
}
private WikiPage createWikiPage(String title, String content) throws GitLabApiException {
......
package org.gitlab4j.api.models;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
public class MembershipSourceTypeTest {
@Test
public void forValue() {
final MembershipSourceType namespace = MembershipSourceType.forValue("Namespace");
Assert.assertEquals(MembershipSourceType.NAMESPACE, namespace);
Assert.assertEquals("Namespace", namespace.toValue());
Assert.assertEquals("Namespace", namespace.toString());
assertEquals(MembershipSourceType.NAMESPACE, namespace);
assertEquals("Namespace", namespace.toValue());
assertEquals("Namespace", namespace.toString());
final MembershipSourceType project = MembershipSourceType.forValue("Project");
Assert.assertEquals(MembershipSourceType.PROJECT, project);
Assert.assertEquals("Project", project.toValue());
Assert.assertEquals("Project", project.toString());
assertEquals(MembershipSourceType.PROJECT, project);
assertEquals("Project", project.toValue());
assertEquals("Project", project.toString());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment