diff --git a/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java index 014467b..c512b2a 100644 --- a/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java @@ -34,6 +34,7 @@ import se.bjurr.prnfb.http.HttpResponse; import se.bjurr.prnfb.http.Invoker; import se.bjurr.prnfb.http.UrlInvoker; +import se.bjurr.prnfb.service.MockedEscalatedSecurityContext; import se.bjurr.prnfb.service.PrnfbRenderer; import se.bjurr.prnfb.service.PrnfbRendererFactory; import se.bjurr.prnfb.service.SettingsService; @@ -91,18 +92,9 @@ public String apply(UrlInvoker input) { public void before() throws ValidationException { initMocks(this); SecurityService securityService = mock(SecurityService.class); - EscalatedSecurityContext escalatedSecurityContext = mock(EscalatedSecurityContext.class); + EscalatedSecurityContext escalatedSecurityContext = new MockedEscalatedSecurityContext(); when(securityService.withPermission(Mockito.any(), Mockito.any())) // .thenReturn(escalatedSecurityContext); - when(escalatedSecurityContext.call(Mockito.any())) // - .thenAnswer( - new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - return (Boolean) invocation.callRealMethod(); - } - }); - sut = new PrnfbPullRequestEventListener( prnfbRendererFactory, diff --git a/src/test/java/se/bjurr/prnfb/service/MockedEscalatedSecurityContext.java b/src/test/java/se/bjurr/prnfb/service/MockedEscalatedSecurityContext.java new file mode 100644 index 0000000..844c03f --- /dev/null +++ b/src/test/java/se/bjurr/prnfb/service/MockedEscalatedSecurityContext.java @@ -0,0 +1,33 @@ +package se.bjurr.prnfb.service; + +import java.util.Set; + +import com.atlassian.bitbucket.permission.Permission; +import com.atlassian.bitbucket.user.EscalatedSecurityContext; +import com.atlassian.bitbucket.util.Operation; + +public class MockedEscalatedSecurityContext implements EscalatedSecurityContext { + + @Override + public void applyToRequest() {} + + @Override + public T call(Operation arg0) throws E { + return arg0.perform(); + } + + @Override + public EscalatedSecurityContext withPermission(Object arg0, Permission arg1) { + return null; + } + + @Override + public EscalatedSecurityContext withPermission(Permission arg0) { + return null; + } + + @Override + public EscalatedSecurityContext withPermissions(Set arg0) { + return null; + } +} diff --git a/src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java b/src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java index 1c36684..e56e326 100644 --- a/src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java +++ b/src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java @@ -13,27 +13,25 @@ import static se.bjurr.prnfb.test.Podam.populatedInstanceOf; import java.util.List; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import se.bjurr.prnfb.presentation.dto.ON_OR_OFF; +import se.bjurr.prnfb.settings.PrnfbButton; +import se.bjurr.prnfb.settings.PrnfbNotification; +import se.bjurr.prnfb.settings.PrnfbSettings; +import se.bjurr.prnfb.settings.ValidationException; + import com.atlassian.bitbucket.permission.Permission; import com.atlassian.bitbucket.user.EscalatedSecurityContext; import com.atlassian.bitbucket.user.SecurityService; -import com.atlassian.bitbucket.util.Operation; import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; import com.atlassian.sal.api.transaction.TransactionCallback; import com.atlassian.sal.api.transaction.TransactionTemplate; import com.google.gson.Gson; -import se.bjurr.prnfb.presentation.dto.ON_OR_OFF; -import se.bjurr.prnfb.settings.PrnfbButton; -import se.bjurr.prnfb.settings.PrnfbNotification; -import se.bjurr.prnfb.settings.PrnfbSettings; -import se.bjurr.prnfb.settings.ValidationException; - public class SettingsServiceTest { private EscalatedSecurityContext escalatedSecurityContext; private PrnfbNotification notification1; @@ -49,30 +47,7 @@ public void before() throws ValidationException { when(this.pluginSettingsFactory.createGlobalSettings()) // .thenReturn(this.pluginSettings); this.escalatedSecurityContext = - new EscalatedSecurityContext() { - @Override - public void applyToRequest() {} - - @Override - public T call(Operation arg0) throws E { - return arg0.perform(); - } - - @Override - public EscalatedSecurityContext withPermission(Object arg0, Permission arg1) { - return null; - } - - @Override - public EscalatedSecurityContext withPermission(Permission arg0) { - return null; - } - - @Override - public EscalatedSecurityContext withPermissions(Set arg0) { - return null; - } - }; + new MockedEscalatedSecurityContext(); when(this.securityService.withPermission(Permission.ADMIN, "Getting config")) // .thenReturn(this.escalatedSecurityContext); this.transactionTemplate =