Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Fixing compile error in Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jun 2, 2017
1 parent 305d071 commit 338ae44
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
return (Boolean) invocation.callRealMethod();
}
});

sut =
new PrnfbPullRequestEventListener(
prnfbRendererFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -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, E extends Throwable> T call(Operation<T, E> 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<Permission> arg0) {
return null;
}
}
39 changes: 7 additions & 32 deletions src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, E extends Throwable> T call(Operation<T, E> 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<Permission> arg0) {
return null;
}
};
new MockedEscalatedSecurityContext();
when(this.securityService.withPermission(Permission.ADMIN, "Getting config")) //
.thenReturn(this.escalatedSecurityContext);
this.transactionTemplate =
Expand Down

0 comments on commit 338ae44

Please sign in to comment.