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

Commit 53eff48

Browse files
committed
Reusing Podam factory, to use caching
1 parent 58daf36 commit 53eff48

File tree

9 files changed

+33
-28
lines changed

9 files changed

+33
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Changelog of Pull Request Notifier for Bitbucket.
1313
### No issue
1414
Defaulting proxy port to null
1515

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

1818
doc
1919

src/test/java/se/bjurr/prnfb/presentation/ButtonServletTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.mockito.Mockito.when;
88
import static org.mockito.MockitoAnnotations.initMocks;
99
import static se.bjurr.prnfb.settings.USER_LEVEL.EVERYONE;
10+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
1011
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;
1112

1213
import java.util.List;
@@ -25,7 +26,6 @@
2526
import se.bjurr.prnfb.service.SettingsService;
2627
import se.bjurr.prnfb.service.UserCheckService;
2728
import se.bjurr.prnfb.settings.PrnfbButton;
28-
import uk.co.jemos.podam.api.PodamFactoryImpl;
2929

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

52-
this.buttonDto1 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
52+
this.buttonDto1 = populatedInstanceOf(ButtonDTO.class);
5353
this.button1 = toPrnfbButton(this.buttonDto1);
54-
this.buttonDto2 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
54+
this.buttonDto2 = populatedInstanceOf(ButtonDTO.class);
5555
this.button2 = toPrnfbButton(this.buttonDto2);
5656
}
5757

src/test/java/se/bjurr/prnfb/presentation/NotificationServletTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.mockito.Mockito.when;
99
import static org.mockito.MockitoAnnotations.initMocks;
1010
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
11+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
1112
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;
1213

1314
import java.util.List;
@@ -23,7 +24,6 @@
2324
import se.bjurr.prnfb.service.SettingsService;
2425
import se.bjurr.prnfb.service.UserCheckService;
2526
import se.bjurr.prnfb.settings.PrnfbNotification;
26-
import uk.co.jemos.podam.api.PodamFactoryImpl;
2727

2828
import com.google.common.collect.Lists;
2929

@@ -46,11 +46,11 @@ public void before() throws Exception {
4646
when(this.userCheckService.isAdminAllowed())//
4747
.thenReturn(true);
4848
this.sut = new NotificationServlet(this.settingsService, this.userCheckService);
49-
this.notificationDto1 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
49+
this.notificationDto1 = populatedInstanceOf(NotificationDTO.class);
5050
this.notificationDto1.setUrl("http://hej.com/");
5151
this.notificationDto1.setTriggerIgnoreStateList(newArrayList(DECLINED.name()));
5252
this.notificationDto1.setTriggers(newArrayList(MERGED.name()));
53-
this.notificationDto2 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
53+
this.notificationDto2 = populatedInstanceOf(NotificationDTO.class);
5454
this.notificationDto2.setUrl("http://hej.com/");
5555
this.notificationDto2.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
5656
this.notificationDto2.setTriggers(newArrayList(MERGED.name()));
@@ -60,7 +60,7 @@ public void before() throws Exception {
6060

6161
@Test
6262
public void testNotificationCanBeCreated() throws Exception {
63-
NotificationDTO incomingDto = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
63+
NotificationDTO incomingDto = populatedInstanceOf(NotificationDTO.class);
6464
incomingDto.setUrl("http://hej.com/");
6565
incomingDto.setTriggerIgnoreStateList(newArrayList(DECLINED.name()));
6666
incomingDto.setTriggers(newArrayList(MERGED.name()));

src/test/java/se/bjurr/prnfb/service/ButtonsServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.mockito.internal.verification.VerificationModeFactory.times;
1212
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.BUTTON_TRIGGER;
1313
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
14+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
1415
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;
1516
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;
1617

@@ -29,7 +30,6 @@
2930
import se.bjurr.prnfb.settings.PrnfbButton;
3031
import se.bjurr.prnfb.settings.PrnfbNotification;
3132
import se.bjurr.prnfb.settings.ValidationException;
32-
import uk.co.jemos.podam.api.PodamFactoryImpl;
3333

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

89-
this.buttonDto1 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
89+
this.buttonDto1 = populatedInstanceOf(ButtonDTO.class);
9090
this.buttonDto1.setProjectKey("a");
9191
this.button1 = toPrnfbButton(this.buttonDto1);
92-
this.buttonDto2 = new PodamFactoryImpl().manufacturePojo(ButtonDTO.class);
92+
this.buttonDto2 = populatedInstanceOf(ButtonDTO.class);
9393
this.buttonDto2.setProjectKey("b");
9494
this.button2 = toPrnfbButton(this.buttonDto2);
9595

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

101-
this.notificationDto1 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
101+
this.notificationDto1 = populatedInstanceOf(NotificationDTO.class);
102102
this.notificationDto1.setUrl("http://hej.com");
103103
this.notificationDto1.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
104104
this.notificationDto1.setTriggers(newArrayList(MERGED.name()));
105105
this.notification1 = toPrnfbNotification(this.notificationDto1);
106106

107-
this.notificationDto2 = new PodamFactoryImpl().manufacturePojo(NotificationDTO.class);
107+
this.notificationDto2 = populatedInstanceOf(NotificationDTO.class);
108108
this.notificationDto2.setUrl("http://hej.com");
109109
this.notificationDto2.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
110110
this.notificationDto2.setTriggers(newArrayList(MERGED.name()));

src/test/java/se/bjurr/prnfb/service/SettingsServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static se.bjurr.prnfb.settings.PrnfbSettingsDataBuilder.prnfbSettingsDataBuilder;
1111
import static se.bjurr.prnfb.settings.USER_LEVEL.ADMIN;
1212
import static se.bjurr.prnfb.settings.USER_LEVEL.EVERYONE;
13+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
1314

1415
import java.util.List;
1516
import java.util.Set;
@@ -22,7 +23,6 @@
2223
import se.bjurr.prnfb.settings.PrnfbNotification;
2324
import se.bjurr.prnfb.settings.PrnfbSettings;
2425
import se.bjurr.prnfb.settings.ValidationException;
25-
import uk.co.jemos.podam.api.PodamFactoryImpl;
2626

2727
import com.atlassian.bitbucket.permission.Permission;
2828
import com.atlassian.bitbucket.user.EscalatedSecurityContext;
@@ -127,7 +127,7 @@ public void testThatButtonCanBeAddedUpdatedAndDeleted() {
127127

128128
@Test
129129
public void testThatButtonsCanBeRetrievedByProject() {
130-
PrnfbButton button1 = new PodamFactoryImpl().manufacturePojo(PrnfbButton.class);
130+
PrnfbButton button1 = populatedInstanceOf(PrnfbButton.class);
131131
this.sut.addOrUpdateButton(button1);
132132

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

139139
@Test
140140
public void testThatButtonsCanBeRetrievedByProjectAndRepo() {
141-
PrnfbButton button1 = new PodamFactoryImpl().manufacturePojo(PrnfbButton.class);
141+
PrnfbButton button1 = populatedInstanceOf(PrnfbButton.class);
142142
this.sut.addOrUpdateButton(button1);
143143

144144
List<PrnfbButton> actual = this.sut.getButtons(button1.getProjectKey().get(), button1.getRepositorySlug().get());
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package se.bjurr.prnfb.test;
2+
3+
import uk.co.jemos.podam.api.PodamFactoryImpl;
4+
5+
public class Podam {
6+
private static PodamFactoryImpl factory = new PodamFactoryImpl();
7+
8+
public static <T> T populatedInstanceOf(Class<T> clazz) {
9+
return factory.manufacturePojo(clazz);
10+
}
11+
}

src/test/java/se/bjurr/prnfb/transformer/ButtonTransformerTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package se.bjurr.prnfb.transformer;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
45
import static se.bjurr.prnfb.transformer.SettingsTransformer.toDto;
56
import static se.bjurr.prnfb.transformer.SettingsTransformer.toPrnfbSettingsData;
67

78
import org.junit.Test;
89

910
import se.bjurr.prnfb.presentation.dto.SettingsDataDTO;
1011
import se.bjurr.prnfb.settings.ValidationException;
11-
import uk.co.jemos.podam.api.PodamFactory;
12-
import uk.co.jemos.podam.api.PodamFactoryImpl;
1312

1413
public class ButtonTransformerTest {
1514
@Test
1615
public void testTransformation() throws ValidationException {
17-
PodamFactory factory = new PodamFactoryImpl();
18-
SettingsDataDTO originalDto = factory.manufacturePojo(SettingsDataDTO.class);
16+
SettingsDataDTO originalDto = populatedInstanceOf(SettingsDataDTO.class);
1917
SettingsDataDTO retransformedDto = toDto(toPrnfbSettingsData(originalDto));
2018

2119
assertThat(retransformedDto)//

src/test/java/se/bjurr/prnfb/transformer/NotificationTransformerTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
import static com.google.common.collect.Lists.newArrayList;
55
import static org.assertj.core.api.Assertions.assertThat;
66
import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.MERGED;
7+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
78
import static se.bjurr.prnfb.transformer.NotificationTransformer.toNotificationDto;
89
import static se.bjurr.prnfb.transformer.NotificationTransformer.toPrnfbNotification;
910

1011
import org.junit.Test;
1112

1213
import se.bjurr.prnfb.presentation.dto.NotificationDTO;
1314
import se.bjurr.prnfb.settings.ValidationException;
14-
import uk.co.jemos.podam.api.PodamFactory;
15-
import uk.co.jemos.podam.api.PodamFactoryImpl;
1615

1716
import com.google.common.collect.Lists;
1817

1918
public class NotificationTransformerTest {
2019
@Test
2120
public void testTransformation() throws ValidationException {
22-
PodamFactory factory = new PodamFactoryImpl();
23-
NotificationDTO originalDto = factory.manufacturePojo(NotificationDTO.class);
21+
NotificationDTO originalDto = populatedInstanceOf(NotificationDTO.class);
2422
originalDto.setUrl("http://hej.com/");
2523
originalDto.setTriggerIgnoreStateList(Lists.newArrayList(DECLINED.name()));
2624
originalDto.setTriggers(newArrayList(MERGED.name()));

src/test/java/se/bjurr/prnfb/transformer/SettingsDataTransformerTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package se.bjurr.prnfb.transformer;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static se.bjurr.prnfb.test.Podam.populatedInstanceOf;
45
import static se.bjurr.prnfb.transformer.ButtonTransformer.toButtonDto;
56
import static se.bjurr.prnfb.transformer.ButtonTransformer.toPrnfbButton;
67

78
import org.junit.Test;
89

910
import se.bjurr.prnfb.presentation.dto.ButtonDTO;
1011
import se.bjurr.prnfb.settings.ValidationException;
11-
import uk.co.jemos.podam.api.PodamFactory;
12-
import uk.co.jemos.podam.api.PodamFactoryImpl;
1312

1413
public class SettingsDataTransformerTest {
1514
@Test
1615
public void testTransformation() throws ValidationException {
17-
PodamFactory factory = new PodamFactoryImpl();
18-
ButtonDTO originalDto = factory.manufacturePojo(ButtonDTO.class);
16+
ButtonDTO originalDto = populatedInstanceOf(ButtonDTO.class);
1917
ButtonDTO retransformedDto = toButtonDto(toPrnfbButton(originalDto));
2018

2119
assertThat(retransformedDto)//

0 commit comments

Comments
 (0)