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

Commit

Permalink
Reusing Podam factory, to use caching
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed May 12, 2016
1 parent 58daf36 commit 53eff48
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Changelog of Pull Request Notifier for Bitbucket.
### No issue
Defaulting proxy port to null

[b47ee2751e43fdf](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/b47ee2751e43fdf) Tomas Bjerre *2016-05-12 16:18:16*
[4761aa53d58cf06](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/4761aa53d58cf06) Tomas Bjerre *2016-05-12 16:37:39*

doc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static se.bjurr.prnfb.settings.USER_LEVEL.EVERYONE;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;

import java.util.List;
Expand All @@ -25,7 +26,6 @@
import se.bjurr.prnfb.service.SettingsService;
import se.bjurr.prnfb.service.UserCheckService;
import se.bjurr.prnfb.settings.PrnfbButton;
import uk.co.jemos.podam.api.PodamFactoryImpl;

public class ButtonServletTest {
private PrnfbButton button1;
Expand All @@ -49,9 +49,9 @@ public void before() throws Exception {
.thenReturn(true);
this.sut = new ButtonServlet(this.buttonsService, this.settingsService, this.userCheckService);

this.buttonDto1 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
this.buttonDto1 = populatedInstanceOf(ButtonDTO.class);
this.button1 = toPrnfbButton(this.buttonDto1);
this.buttonDto2 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
this.buttonDto2 = populatedInstanceOf(ButtonDTO.class);
this.button2 = toPrnfbButton(this.buttonDto2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;

import java.util.List;
Expand All @@ -23,7 +24,6 @@
import se.bjurr.prnfb.service.SettingsService;
import se.bjurr.prnfb.service.UserCheckService;
import se.bjurr.prnfb.settings.PrnfbNotification;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import com.google.common.collect.Lists;

Expand All @@ -46,11 +46,11 @@ public void before() throws Exception {
when(this.userCheckService.isAdminAllowed())//
.thenReturn(true);
this.sut = new NotificationServlet(this.settingsService, this.userCheckService);
this.notificationDto1 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
this.notificationDto1 = populatedInstanceOf(NotificationDTO.class);
this.notificationDto1.setUrl("http://hej.com/");
this.notificationDto1.setTriggerIgnoreStateList(newArrayList(DECLINED.name()));
this.notificationDto1.setTriggers(newArrayList(MERGED.name()));
this.notificationDto2 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
this.notificationDto2 = populatedInstanceOf(NotificationDTO.class);
this.notificationDto2.setUrl("http://hej.com/");
this.notificationDto2.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
this.notificationDto2.setTriggers(newArrayList(MERGED.name()));
Expand All @@ -60,7 +60,7 @@ public void before() throws Exception {

@Test
public void testNotificationCanBeCreated() throws Exception {
NotificationDTO incomingDto = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
NotificationDTO incomingDto = populatedInstanceOf(NotificationDTO.class);
incomingDto.setUrl("http://hej.com/");
incomingDto.setTriggerIgnoreStateList(newArrayList(DECLINED.name()));
incomingDto.setTriggers(newArrayList(MERGED.name()));
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/se/bjurr/prnfb/service/ButtonsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.mockito.internal.verification.VerificationModeFactory.times;
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.BUTTON_TRIGGER;
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;

Expand All @@ -29,7 +30,6 @@
import se.bjurr.prnfb.settings.PrnfbButton;
import se.bjurr.prnfb.settings.PrnfbNotification;
import se.bjurr.prnfb.settings.ValidationException;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import com.atlassian.bitbucket.auth.AuthenticationContext;
import com.atlassian.bitbucket.pull.PullRequest;
Expand Down Expand Up @@ -86,10 +86,10 @@ public void before() throws ValidationException {
any(PrnfbNotification.class), anyMap()))//
.thenReturn(this.renderer);

this.buttonDto1 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
this.buttonDto1 = populatedInstanceOf(ButtonDTO.class);
this.buttonDto1.setProjectKey("a");
this.button1 = toPrnfbButton(this.buttonDto1);
this.buttonDto2 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
this.buttonDto2 = populatedInstanceOf(ButtonDTO.class);
this.buttonDto2.setProjectKey("b");
this.button2 = toPrnfbButton(this.buttonDto2);

Expand All @@ -98,13 +98,13 @@ public void before() throws ValidationException {
when(this.settingsService.getButton(this.button2.getUuid()))//
.thenReturn(this.button2);

this.notificationDto1 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
this.notificationDto1 = populatedInstanceOf(NotificationDTO.class);
this.notificationDto1.setUrl("http://hej.com");
this.notificationDto1.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
this.notificationDto1.setTriggers(newArrayList(MERGED.name()));
this.notification1 = toPrnfbNotification(this.notificationDto1);

this.notificationDto2 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
this.notificationDto2 = populatedInstanceOf(NotificationDTO.class);
this.notificationDto2.setUrl("http://hej.com");
this.notificationDto2.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
this.notificationDto2.setTriggers(newArrayList(MERGED.name()));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static se.bjurr.prnfb.settings.PrnfbSettingsDataBuilder.prnfbSettingsDataBuilder;
import static se.bjurr.prnfb.settings.USER_LEVEL.ADMIN;
import static se.bjurr.prnfb.settings.USER_LEVEL.EVERYONE;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;

import java.util.List;
import java.util.Set;
Expand All @@ -22,7 +23,6 @@
import se.bjurr.prnfb.settings.PrnfbNotification;
import se.bjurr.prnfb.settings.PrnfbSettings;
import se.bjurr.prnfb.settings.ValidationException;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.user.EscalatedSecurityContext;
Expand Down Expand Up @@ -127,7 +127,7 @@ public void testThatButtonCanBeAddedUpdatedAndDeleted() {

@Test
public void testThatButtonsCanBeRetrievedByProject() {
PrnfbButton button1 = new PodamFactoryImpl().manufacturePojo(PrnfbButton.class);
PrnfbButton button1 = populatedInstanceOf(PrnfbButton.class);
this.sut.addOrUpdateButton(button1);

List<PrnfbButton> actual = this.sut.getButtons(button1.getProjectKey().get());
Expand All @@ -138,7 +138,7 @@ public void testThatButtonsCanBeRetrievedByProject() {

@Test
public void testThatButtonsCanBeRetrievedByProjectAndRepo() {
PrnfbButton button1 = new PodamFactoryImpl().manufacturePojo(PrnfbButton.class);
PrnfbButton button1 = populatedInstanceOf(PrnfbButton.class);
this.sut.addOrUpdateButton(button1);

List<PrnfbButton> actual = this.sut.getButtons(button1.getProjectKey().get(), button1.getRepositorySlug().get());
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/se/bjurr/prnfb/test/Podam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package se.bjurr.prnfb.test;

import uk.co.jemos.podam.api.PodamFactoryImpl;

public class Podam {
private static PodamFactoryImpl factory = new PodamFactoryImpl();

public static <T> T populatedInstanceOf(Class<T> clazz) {
return factory.manufacturePojo(clazz);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package se.bjurr.prnfb.transformer;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.SettingsTransformer.toDto;
import static se.bjurr.prnfb.transformer.SettingsTransformer.toPrnfbSettingsData;

import org.junit.Test;

import se.bjurr.prnfb.presentation.dto.SettingsDataDTO;
import se.bjurr.prnfb.settings.ValidationException;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

public class ButtonTransformerTest {
@Test
public void testTransformation() throws ValidationException {
PodamFactory factory = new PodamFactoryImpl();
SettingsDataDTO originalDto = factory.manufacturePojo(SettingsDataDTO.class);
SettingsDataDTO originalDto = populatedInstanceOf(SettingsDataDTO.class);
SettingsDataDTO retransformedDto = toDto(toPrnfbSettingsData(originalDto));

assertThat(retransformedDto)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.NotificationTransformer.toNotificationDto;
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;

import org.junit.Test;

import se.bjurr.prnfb.presentation.dto.NotificationDTO;
import se.bjurr.prnfb.settings.ValidationException;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

import com.google.common.collect.Lists;

public class NotificationTransformerTest {
@Test
public void testTransformation() throws ValidationException {
PodamFactory factory = new PodamFactoryImpl();
NotificationDTO originalDto = factory.manufacturePojo(NotificationDTO.class);
NotificationDTO originalDto = populatedInstanceOf(NotificationDTO.class);
originalDto.setUrl("http://hej.com/");
originalDto.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
originalDto.setTriggers(newArrayList(MERGED.name()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package se.bjurr.prnfb.transformer;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
import static se.bjurr.prnfb.transformer.ButtonTransformer.toButtonDto;
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;

import org.junit.Test;

import se.bjurr.prnfb.presentation.dto.ButtonDTO;
import se.bjurr.prnfb.settings.ValidationException;
import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl;

public class SettingsDataTransformerTest {
@Test
public void testTransformation() throws ValidationException {
PodamFactory factory = new PodamFactoryImpl();
ButtonDTO originalDto = factory.manufacturePojo(ButtonDTO.class);
ButtonDTO originalDto = populatedInstanceOf(ButtonDTO.class);
ButtonDTO retransformedDto = toButtonDto(toPrnfbButton(originalDto));

assertThat(retransformedDto)//
Expand Down

0 comments on commit 53eff48

Please sign in to comment.