Skip to content

Commit

Permalink
Update JUnit and Mockito to versions 5.x, replace PowerMock
Browse files Browse the repository at this point in the history
  • Loading branch information
pathob committed Mar 18, 2024
1 parent e47fef1 commit 05bb65d
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 267 deletions.
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@
<atlassian.amps.version>8.0.2</atlassian.amps.version>
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<atlassian.spring.scanner.version>2.1.5</atlassian.spring.scanner.version>
<confapi-commons.version>0.0.32-SNAPSHOT</confapi-commons.version>
<confapi-commons.version>0.5.0</confapi-commons.version>
<glassfish.el-api.version>2.2.4</glassfish.el-api.version>
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
<javax.el-api.version>3.0.0</javax.el-api.version>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
<jira-lookandfeel-plugin.version>7.13.0</jira-lookandfeel-plugin.version>
<!-- Compiler must be 8 so that the plugin can run on jIRA instances using Java 11 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -230,12 +231,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand All @@ -251,6 +246,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet-api.version}</version>
<scope>provided</scope>
</dependency>

Expand All @@ -277,8 +273,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -288,6 +284,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,55 @@
import com.atlassian.sal.api.user.UserKey;
import com.atlassian.sal.api.user.UserManager;
import com.atlassian.sal.api.user.UserProfile;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class SysadminOnlyResourceFilterTest {
@ExtendWith(MockitoExtension.class)
class SysadminOnlyResourceFilterTest {

@Mock
private UserManager userManager;

private SysadminOnlyResourceFilter sysadminOnlyResourceFilter;

@Before
@BeforeEach
public void setup() {
sysadminOnlyResourceFilter = new SysadminOnlyResourceFilter(userManager);
}

@Test
public void testFilterDefaults() {
void testFilterDefaults() {
assertNull(sysadminOnlyResourceFilter.getResponseFilter());
assertEquals(sysadminOnlyResourceFilter, sysadminOnlyResourceFilter.getRequestFilter());
}

@Test(expected = AuthenticationRequiredException.class)
public void testAdminAccessNoUser() {
sysadminOnlyResourceFilter.filter(null);
@Test
void testAdminAccessNoUser() {
assertThrows(AuthenticationRequiredException.class, () -> {
sysadminOnlyResourceFilter.filter(null);
});
}

@Test(expected = AuthorisationException.class)
public void testNonSysadminAccess() {
@Test
void testNonSysadminAccess() {
final UserProfile userProfile = mock(UserProfile.class);
doReturn(userProfile).when(userManager).getRemoteUser();

sysadminOnlyResourceFilter.filter(null);
assertThrows(AuthorisationException.class, () -> {
sysadminOnlyResourceFilter.filter(null);
});
}

@Test
public void testSysadminAccess() {
void testSysadminAccess() {
final UserProfile userProfile = mock(UserProfile.class);
doReturn(new UserKey("user")).when(userProfile).getUserKey();
doReturn(userProfile).when(userManager).getRemoteUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@
import de.aservo.confapi.commons.model.ApplicationLinkBean;
import de.aservo.confapi.commons.model.ApplicationLinkBean.ApplicationLinkType;
import org.apache.commons.lang3.NotImplementedException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class ApplicationLinkBeanUtilTest {
@ExtendWith(MockitoExtension.class)
class ApplicationLinkBeanUtilTest {

@Test
public void testToApplicationLinkBean() throws URISyntaxException {
void testToApplicationLinkBean() throws URISyntaxException {
final ApplicationId applicationId = new ApplicationId(UUID.randomUUID().toString());
final URI displayUri = new URI("http://localhost");
final URI rpcUri = new URI("http://rpc.example.com");
Expand All @@ -48,7 +47,7 @@ public void testToApplicationLinkBean() throws URISyntaxException {
}

@Test
public void testToApplicationLinkDetails() {
void testToApplicationLinkDetails() {
final ApplicationLinkBean bean = ApplicationLinkBean.EXAMPLE_1;
final ApplicationLinkDetails linkDetails = ApplicationLinkBeanUtil.toApplicationLinkDetails(bean);

Expand All @@ -60,7 +59,7 @@ public void testToApplicationLinkDetails() {
}

@Test
public void testLinkTypeGenerator() throws URISyntaxException {
void testLinkTypeGenerator() throws URISyntaxException {
for (ApplicationLinkType linkType : ApplicationLinkType.values()) {
ApplicationType applicationType = null;
switch (linkType) {
Expand Down Expand Up @@ -92,14 +91,17 @@ public void testLinkTypeGenerator() throws URISyntaxException {
}
}

@Test(expected = NotImplementedException.class)
public void testNonImplementedLinkTypeGenerator() throws URISyntaxException {
@Test
void testNonImplementedLinkTypeGenerator() throws URISyntaxException {
ApplicationType applicationType = mock(RefAppApplicationType.class);
ApplicationId applicationId = new ApplicationId(UUID.randomUUID().toString());
URI uri = new URI("http://localhost");
ApplicationLink applicationLink = new DefaultApplicationLink(
applicationId, applicationType, "test", uri, uri, false, false);
ApplicationLinkBeanUtil.toApplicationLinkBean(applicationLink);

assertThrows(NotImplementedException.class, () -> {
ApplicationLinkBeanUtil.toApplicationLinkBean(applicationLink);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import com.atlassian.crowd.embedded.api.DirectoryType;
import com.atlassian.crowd.model.directory.DirectoryImpl;
import de.aservo.confapi.commons.model.DirectoryCrowdBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Map;

import static com.atlassian.crowd.directory.RemoteCrowdDirectory.*;
import static com.atlassian.crowd.directory.SynchronisableDirectoryProperties.INCREMENTAL_SYNC_ENABLED;
import static com.atlassian.crowd.model.directory.DirectoryImpl.ATTRIBUTE_KEY_USE_NESTED_GROUPS;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

@RunWith(MockitoJUnitRunner.class)
public class DirectoryBeanUtilTest {
@ExtendWith(MockitoExtension.class)
class DirectoryBeanUtilTest {

@Test
public void testToDirectoryWithoutProxy() {
void testToDirectoryWithoutProxy() {
final DirectoryCrowdBean bean = DirectoryCrowdBean.EXAMPLE_1;
final Directory directory = DirectoryBeanUtil.toDirectory(bean);

Expand All @@ -32,7 +32,7 @@ public void testToDirectoryWithoutProxy() {
}

@Test
public void testToDirectoryWithProxy() {
void testToDirectoryWithProxy() {
final DirectoryCrowdBean bean = DirectoryCrowdBean.EXAMPLE_1_WITH_PROXY;
final Directory directory = DirectoryBeanUtil.toDirectory(bean);

Expand All @@ -50,7 +50,7 @@ public void testToDirectoryWithProxy() {
}

@Test
public void testToDirectoryBeanWithProxy() {
void testToDirectoryBeanWithProxy() {
final DirectoryImpl directory = new DirectoryImpl("test", DirectoryType.CROWD, "test.class");
directory.setAttribute(CROWD_SERVER_URL, "http://localhost");
directory.setAttribute(APPLICATION_PASSWORD, "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import com.atlassian.jira.license.LicenseDetails;
import com.atlassian.jira.license.LicensedApplications;
import de.aservo.confapi.commons.model.LicenseBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

@RunWith(MockitoJUnitRunner.class)
public class LicenseBeanUtilTest {
@ExtendWith(MockitoExtension.class)
class LicenseBeanUtilTest {

@Test
public void testToLicenseBean() {
void testToLicenseBean() {
final LicenseBean exampleLicenseBean = LicenseBean.EXAMPLE_1;

final LicensedApplications licensedApplications = mock(LicensedApplications.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import atlassian.mail.server.DefaultTestPopMailServerImpl;
import com.atlassian.mail.server.PopMailServer;
import de.aservo.confapi.commons.model.MailServerPopBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

@RunWith(MockitoJUnitRunner.class)
public class MailServerPopBeanUtilTest {
@ExtendWith(MockitoExtension.class)
class MailServerPopBeanUtilTest {

@Test
public void testToMailServerPopBean() {
void testToMailServerPopBean() {
final PopMailServer server = new DefaultTestPopMailServerImpl();
final MailServerPopBean bean = MailServerPopBeanUtil.toMailServerPopBean(server);

Expand All @@ -29,7 +29,7 @@ public void testToMailServerPopBean() {
}

@Test
public void testToMailServerPopBeanHideEmptyDescription() {
void testToMailServerPopBeanHideEmptyDescription() {
final PopMailServer server = new DefaultTestPopMailServerImpl();
server.setDescription("");
final MailServerPopBean bean = MailServerPopBeanUtil.toMailServerPopBean(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import atlassian.mail.server.DefaultTestSmtpMailServerImpl;
import com.atlassian.mail.server.SMTPMailServer;
import de.aservo.confapi.commons.model.MailServerSmtpBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

@RunWith(MockitoJUnitRunner.class)
public class MailServerSmtpBeanUtilTest {
@ExtendWith(MockitoExtension.class)
class MailServerSmtpBeanUtilTest {

@Test
public void testToMailServerSmtpBean() {
void testToMailServerSmtpBean() {
final SMTPMailServer server = new DefaultTestSmtpMailServerImpl();
final MailServerSmtpBean bean = MailServerSmtpBeanUtil.toMailServerSmtpBean(server);

Expand All @@ -32,7 +32,7 @@ public void testToMailServerSmtpBean() {
}

@Test
public void testToMailServerSmtpBeanHideEmptyDescription() {
void testToMailServerSmtpBeanHideEmptyDescription() {
final SMTPMailServer server = new DefaultTestSmtpMailServerImpl();
server.setDescription("");
final MailServerSmtpBean bean = MailServerSmtpBeanUtil.toMailServerSmtpBean(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
import com.atlassian.jira.config.properties.APKeys;
import com.atlassian.jira.config.properties.ApplicationProperties;
import de.aservo.confapi.commons.model.SettingsBrandingColorSchemeBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class SettingsColourSchemeBeanUtilTest {

@Mock
private ApplicationProperties applicationProperties;

@Test
public void testToGlobalColorScheme() {
void testToGlobalColorScheme() {

SettingsBrandingColorSchemeBean schemeBean = SettingsBrandingColorSchemeBean.EXAMPLE_1;
SettingsBrandingColorSchemeBeanUtil.setGlobalColorScheme(schemeBean, true, applicationProperties);
Expand All @@ -34,7 +34,7 @@ public void testToGlobalColorScheme() {
}

@Test
public void testToSettingsBrandingColorSchemeBean() {
void testToSettingsBrandingColorSchemeBean() {

Map<String, Object> dummyBaseColourScheme = getDummyBaseColourScheme();
doReturn(dummyBaseColourScheme).when(applicationProperties).asMap();
Expand Down
Loading

0 comments on commit 05bb65d

Please sign in to comment.