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 6737519
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 174 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,27 +5,26 @@
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)
@ExtendWith(MockitoExtension.class)
public class SysadminOnlyResourceFilterTest {

@Mock
private UserManager userManager;

private SysadminOnlyResourceFilter sysadminOnlyResourceFilter;

@Before
@BeforeEach
public void setup() {
sysadminOnlyResourceFilter = new SysadminOnlyResourceFilter(userManager);
}
Expand All @@ -36,17 +35,21 @@ public void testFilterDefaults() {
assertEquals(sysadminOnlyResourceFilter, sysadminOnlyResourceFilter.getRequestFilter());
}

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

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

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
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)
@ExtendWith(MockitoExtension.class)
public class ApplicationLinkBeanUtilTest {

@Test
Expand Down Expand Up @@ -92,14 +91,17 @@ public void testLinkTypeGenerator() throws URISyntaxException {
}
}

@Test(expected = NotImplementedException.class)
@Test
public 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,18 +4,18 @@
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)
@ExtendWith(MockitoExtension.class)
public class DirectoryBeanUtilTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
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)
@ExtendWith(MockitoExtension.class)
public class LicenseBeanUtilTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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)
@ExtendWith(MockitoExtension.class)
public class MailServerPopBeanUtilTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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)
@ExtendWith(MockitoExtension.class)
public class MailServerSmtpBeanUtilTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import de.aservo.confapi.commons.model.ApplicationLinksBean;
import de.aservo.confapi.jira.model.type.DefaultAuthenticationScenario;
import de.aservo.confapi.jira.model.util.ApplicationLinkBeanUtil;
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 java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -42,11 +42,11 @@
import static de.aservo.confapi.commons.model.ApplicationLinkBean.ApplicationLinkStatus.AVAILABLE;
import static de.aservo.confapi.commons.model.ApplicationLinkBean.ApplicationLinkStatus.CONFIGURATION_ERROR;
import static de.aservo.confapi.commons.model.ApplicationLinkBean.ApplicationLinkType.CROWD;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

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

@Mock
Expand All @@ -60,7 +60,7 @@ public class ApplicationLinkServiceTest {

private ApplicationLinkServiceImpl applicationLinkService;

@Before
@BeforeEach
public void setup() {
applicationLinkService = new ApplicationLinkServiceImpl(mutatingApplicationLinkService, typeAccessor, applinkStatusService);
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testAddApplicationLinkWithAuthenticatorErrorIgnored() throws URISynt
assertNotEquals(applicationLinkResponse, applicationLinkBean);
}

@Test(expected = BadRequestException.class)
@Test
public void testAddApplicationLinkWithAuthenticatorErrorNOTIgnored() throws URISyntaxException, ManifestNotFoundException, AuthenticationConfigurationException {
ApplicationLink applicationLink = createApplicationLink();
ApplicationLinkBean applicationLinkBean = createApplicationLinkBean();
Expand All @@ -216,7 +216,9 @@ public void testAddApplicationLinkWithAuthenticatorErrorNOTIgnored() throws URIS
doReturn(new DefaultApplicationType()).when(typeAccessor).getApplicationType(any());
doThrow(new AuthenticationConfigurationException("")).when(mutatingApplicationLinkService).configureAuthenticationForApplicationLink(any(), any(), any(), any());

applicationLinkService.addApplicationLink(applicationLinkBean, false);
assertThrows(BadRequestException.class, () -> {
applicationLinkService.addApplicationLink(applicationLinkBean, false);
});
}

@Test
Expand Down Expand Up @@ -247,9 +249,11 @@ public void testDeleteApplicationLinks() throws URISyntaxException {
verify(mutatingApplicationLinkService).deleteApplicationLink(any());
}

@Test(expected = BadRequestException.class)
@Test
public void testDeleteApplicationLinksWithoutForceParameter() {
applicationLinkService.deleteApplicationLinks(false);
assertThrows(BadRequestException.class, () -> {
applicationLinkService.deleteApplicationLinks(false);
});
}

@Test
Expand Down
Loading

0 comments on commit 6737519

Please sign in to comment.