Created
February 19, 2026 05:44
-
-
Save musketyr/1de0159cc38744834f109cfc459778ba to your computer and use it in GitHub Desktop.
Spock to JUnit 5 Migration Diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Spock → JUnit 5 Migration: RoiPostInsightServiceSpec</title> | |
| <style> | |
| * { box-sizing: border-box; margin: 0; padding: 0; } | |
| body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; padding: 20px; line-height: 1.6; } | |
| h1 { text-align: center; margin-bottom: 20px; color: #333; } | |
| .section { background: white; border-radius: 8px; margin-bottom: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); overflow: hidden; } | |
| .section-header { background: #2d3748; color: white; padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; } | |
| .section-header:hover { background: #4a5568; } | |
| .section-header h2 { font-size: 16px; font-weight: 600; } | |
| .section-header .toggle { font-size: 12px; } | |
| .section-content { display: block; } | |
| .section-content.collapsed { display: none; } | |
| .diff-container { display: grid; grid-template-columns: 1fr 1fr; } | |
| .diff-panel { padding: 16px; overflow-x: auto; } | |
| .diff-panel.left { background: #fff5f5; border-right: 1px solid #e2e8f0; } | |
| .diff-panel.right { background: #f0fff4; } | |
| .diff-panel h3 { font-size: 12px; text-transform: uppercase; color: #718096; margin-bottom: 12px; letter-spacing: 0.5px; } | |
| pre { font-family: 'SF Mono', Monaco, 'Courier New', monospace; font-size: 13px; white-space: pre-wrap; word-wrap: break-word; } | |
| .left pre { color: #c53030; } | |
| .right pre { color: #276749; } | |
| @media (max-width: 768px) { .diff-container { grid-template-columns: 1fr; } .diff-panel.left { border-right: none; border-bottom: 1px solid #e2e8f0; } } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>🦀 Spock → JUnit 5 Migration: RoiPostInsightServiceSpec</h1> | |
| <p style="text-align: center; color: #666; margin-bottom: 20px;">Story: <a href="https://app.shortcut.com/agorapulse/story/185900">sc185900</a> | PR: <a href="https://github.com/agorapulse/platform/pull/72992">#72992</a></p> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>📦 Imports</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre>package agorapulse.roi.postinsight.service | |
| import agorapulse.link.client.GetLinksRequest | |
| import agorapulse.link.client.GetLinksResponse | |
| import agorapulse.link.client.LinkClient | |
| import agorapulse.link.client.LinkSummary | |
| import agorapulse.organization.client.internal.AccountClient | |
| import agorapulse.organization.client.model.AccountManagerSummary | |
| import agorapulse.organization.client.model.AccountSummary | |
| import agorapulse.organization.client.model.ManagerSummary | |
| import agorapulse.organization.client.model.SpecificTwitterAccountData | |
| import agorapulse.report.client.PostInsightSummary | |
| import agorapulse.report.client.PostInsightSummaryClient | |
| import agorapulse.report.client.model.insight.GetPostInsightSummariesResponse | |
| import agorapulse.report.client.model.insight.request.PostInsightSummariesRequest | |
| import agorapulse.service.client.api.Service | |
| import agorapulse.service.client.api.TwitterIntegrationLevel | |
| import io.micronaut.http.client.exceptions.HttpClientException | |
| import spock.lang.Specification | |
| import java.time.Instant | |
| import java.time.LocalDate | |
| import java.time.LocalDateTime</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>package agorapulse.roi.postinsight.service; | |
| import agorapulse.link.client.GetLinksRequest; | |
| import agorapulse.link.client.GetLinksResponse; | |
| import agorapulse.link.client.LinkClient; | |
| import agorapulse.link.client.LinkSummary; | |
| import agorapulse.organization.client.internal.AccountClient; | |
| import agorapulse.organization.client.model.AccountManagerSummary; | |
| import agorapulse.organization.client.model.AccountSummary; | |
| import agorapulse.organization.client.model.ManagerSummary; | |
| import agorapulse.organization.client.model.SpecificTwitterAccountData; | |
| import agorapulse.report.client.PostInsightSummary; | |
| import agorapulse.report.client.PostInsightSummaryClient; | |
| import agorapulse.report.client.model.insight.GetPostInsightSummariesResponse; | |
| import agorapulse.report.client.model.insight.request.PostInsightSummariesRequest; | |
| import agorapulse.service.client.api.Service; | |
| import agorapulse.service.client.api.TwitterIntegrationLevel; | |
| import io.micronaut.http.client.exceptions.HttpClientException; | |
| import org.junit.jupiter.api.BeforeEach; | |
| import org.junit.jupiter.api.Test; | |
| import org.junit.jupiter.api.extension.ExtendWith; | |
| import org.junit.jupiter.params.ParameterizedTest; | |
| import org.junit.jupiter.params.provider.Arguments; | |
| import org.junit.jupiter.params.provider.MethodSource; | |
| import org.mockito.Mock; | |
| import org.mockito.junit.jupiter.MockitoExtension; | |
| import java.time.Instant; | |
| import java.time.LocalDate; | |
| import java.time.LocalDateTime; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.Set; | |
| import java.util.stream.Stream; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| import static org.mockito.ArgumentMatchers.any; | |
| import static org.mockito.ArgumentMatchers.eq; | |
| import static org.mockito.Mockito.never; | |
| import static org.mockito.Mockito.verify; | |
| import static org.mockito.Mockito.when;</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🏗️ Class & Fields</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre>class RoiPostInsightServiceSpec extends Specification { | |
| private final static String ACCOUNT_UID = 'ac123' | |
| private final static LocalDateTime DATE_05_13 = LocalDate.of(2023, 5, 13).atStartOfDay() | |
| private final static LocalDateTime DATE_05_14 = LocalDate.of(2023, 5, 14).atStartOfDay() | |
| private final static LocalDateTime DATE_05_15 = LocalDate.of(2023, 5, 15).atStartOfDay() | |
| RoiPostInsightService service | |
| AccountClient accountClient = Mock(AccountClient) | |
| LinkClient linkClient = Mock(LinkClient) | |
| PostInsightSummaryClient postInsightSummaryClient = Mock(PostInsightSummaryClient) | |
| void setup() { | |
| service = new RoiPostInsightService(accountClient, linkClient, postInsightSummaryClient) | |
| } | |
| </pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@ExtendWith(MockitoExtension.class) | |
| class RoiPostInsightServiceTest { | |
| private static final String ACCOUNT_UID = "ac123"; | |
| private static final LocalDateTime DATE_05_13 = LocalDate.of(2023, 5, 13).atStartOfDay(); | |
| private static final LocalDateTime DATE_05_14 = LocalDate.of(2023, 5, 14).atStartOfDay(); | |
| private static final LocalDateTime DATE_05_15 = LocalDate.of(2023, 5, 15).atStartOfDay(); | |
| @Mock | |
| private AccountClient accountClient; | |
| @Mock | |
| private LinkClient linkClient; | |
| @Mock | |
| private PostInsightSummaryClient postInsightSummaryClient; | |
| private RoiPostInsightService service; | |
| @BeforeEach | |
| void setUp() { | |
| service = new RoiPostInsightService(accountClient, linkClient, postInsightSummaryClient); | |
| } | |
| </pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should generate accounts by uid - empty</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should generate accounts by uid - empty'() { | |
| given: | |
| List<LinkSummary> links = [] | |
| when: | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(new ManagerSummary(), [], links) | |
| then: | |
| accountsByUid == [:] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGenerateAccountsByUidEmpty() { | |
| // given | |
| List<LinkSummary> links = List.of(); | |
| // when | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(new ManagerSummary(), List.of(), links); | |
| // then | |
| assertThat(accountsByUid).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should generate accounts by uid - one account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should generate accounts by uid - one account'() { | |
| given: | |
| List<LinkSummary> links = [new LinkSummary(accountUid: 'facebook_3')] | |
| ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false) | |
| AccountSummary fb3 = new AccountSummary(uid: 'facebook_3', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| when: | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, [fb3], links) | |
| then: | |
| 0 * _ | |
| accountsByUid == ['facebook_3': fb3] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGenerateAccountsByUidOneAccount() { | |
| // given | |
| LinkSummary link = new LinkSummary(); | |
| link.setAccountUid("facebook_3"); | |
| List<LinkSummary> links = List.of(link); | |
| ManagerSummary manager = new ManagerSummary(); | |
| manager.setId(123L); | |
| manager.setAdministratorEnabled(false); | |
| AccountManagerSummary accountManager = new AccountManagerSummary(); | |
| accountManager.setManagerId(123L); | |
| AccountSummary fb3 = new AccountSummary(); | |
| fb3.setUid("facebook_3"); | |
| fb3.setAccountManagers(List.of(accountManager)); | |
| // when | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, List.of(fb3), links); | |
| // then | |
| assertThat(accountsByUid).containsExactlyEntriesOf(Map.of("facebook_3", fb3)); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should generate accounts by uid - same account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should generate accounts by uid - same account'() { | |
| given: | |
| List<LinkSummary> links = [new LinkSummary(accountUid: 'facebook_3', uid: 'ap_g8h5eiou'), new LinkSummary(accountUid: 'facebook_3', uid: 'ap_vf1d4t47')] | |
| ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false) | |
| AccountSummary fb3 = new AccountSummary(uid: 'facebook_3', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| when: | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, [fb3], links) | |
| then: | |
| 0 * _ | |
| accountsByUid == ['facebook_3': fb3] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGenerateAccountsByUidSameAccount() { | |
| // given | |
| LinkSummary link1 = new LinkSummary(); | |
| link1.setAccountUid("facebook_3"); | |
| link1.setUid("ap_g8h5eiou"); | |
| LinkSummary link2 = new LinkSummary(); | |
| link2.setAccountUid("facebook_3"); | |
| link2.setUid("ap_vf1d4t47"); | |
| List<LinkSummary> links = List.of(link1, link2); | |
| ManagerSummary manager = new ManagerSummary(); | |
| manager.setId(123L); | |
| manager.setAdministratorEnabled(false); | |
| AccountManagerSummary accountManager = new AccountManagerSummary(); | |
| accountManager.setManagerId(123L); | |
| AccountSummary fb3 = new AccountSummary(); | |
| fb3.setUid("facebook_3"); | |
| fb3.setAccountManagers(List.of(accountManager)); | |
| // when | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, List.of(fb3), links); | |
| // then | |
| assertThat(accountsByUid).containsExactlyEntriesOf(Map.of("facebook_3", fb3)); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should generate accounts by uid - 2 accounts</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should generate accounts by uid - 2 accounts'() { | |
| given: | |
| List<LinkSummary> links = [new LinkSummary(accountUid: 'instagram_4', uid: 'ap_g8h5eiou'), new LinkSummary(accountUid: 'facebook_3', uid: 'ap_vf1d4t47')] | |
| ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false) | |
| AccountSummary ig4 = new AccountSummary(uid: 'instagram_4', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| AccountSummary fb3 = new AccountSummary(uid: 'facebook_3', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| when: | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, [ig4, fb3], links) | |
| then: | |
| 0 * _ | |
| accountsByUid == ['instagram_4': ig4, 'facebook_3': fb3] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGenerateAccountsByUidTwoAccounts() { | |
| // given | |
| LinkSummary link1 = new LinkSummary(); | |
| link1.setAccountUid("instagram_4"); | |
| link1.setUid("ap_g8h5eiou"); | |
| LinkSummary link2 = new LinkSummary(); | |
| link2.setAccountUid("facebook_3"); | |
| link2.setUid("ap_vf1d4t47"); | |
| List<LinkSummary> links = List.of(link1, link2); | |
| ManagerSummary manager = new ManagerSummary(); | |
| manager.setId(123L); | |
| manager.setAdministratorEnabled(false); | |
| AccountManagerSummary accountManager = new AccountManagerSummary(); | |
| accountManager.setManagerId(123L); | |
| AccountSummary ig4 = new AccountSummary(); | |
| ig4.setUid("instagram_4"); | |
| ig4.setAccountManagers(List.of(accountManager)); | |
| AccountSummary fb3 = new AccountSummary(); | |
| fb3.setUid("facebook_3"); | |
| fb3.setAccountManagers(List.of(accountManager)); | |
| // when | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, List.of(ig4, fb3), links); | |
| // then | |
| assertThat(accountsByUid).containsExactlyInAnyOrderEntriesOf(Map.of("instagram_4", ig4, "facebook_3", fb3)); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should generate accounts by uid - 2 accounts - admin mode</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should generate accounts by uid - 2 accounts - admin mode'() { | |
| given: | |
| List<LinkSummary> links = [new LinkSummary(accountUid: 'instagram_4', uid: 'ap_g8h5eiou'), new LinkSummary(accountUid: 'facebook_3', uid: 'ap_vf1d4t47')] | |
| ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: true) | |
| AccountSummary ig4 = new AccountSummary(uid: 'instagram_4', organizationUid: 'organization_123', workspaceUid: 'workspace_122', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| AccountSummary fb3 = new AccountSummary(uid: 'facebook_3', organizationUid: 'organization_123', workspaceUid: 'workspace_122', accountManagers: [new AccountManagerSummary(managerId: 123)]) | |
| when: | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, [], links) | |
| then: | |
| 1 * accountClient.getAccount('instagram_4') >> ig4 | |
| 1 * accountClient.getAccount('facebook_3') >> fb3 | |
| accountsByUid == ['instagram_4': ig4, 'facebook_3': fb3] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGenerateAccountsByUidTwoAccountsAdminMode() { | |
| // given | |
| LinkSummary link1 = new LinkSummary(); | |
| link1.setAccountUid("instagram_4"); | |
| link1.setUid("ap_g8h5eiou"); | |
| LinkSummary link2 = new LinkSummary(); | |
| link2.setAccountUid("facebook_3"); | |
| link2.setUid("ap_vf1d4t47"); | |
| List<LinkSummary> links = List.of(link1, link2); | |
| ManagerSummary manager = new ManagerSummary(); | |
| manager.setId(123L); | |
| manager.setAdministratorEnabled(true); | |
| AccountManagerSummary accountManager = new AccountManagerSummary(); | |
| accountManager.setManagerId(123L); | |
| AccountSummary ig4 = new AccountSummary(); | |
| ig4.setUid("instagram_4"); | |
| ig4.setOrganizationUid("organization_123"); | |
| ig4.setWorkspaceUid("workspace_122"); | |
| ig4.setAccountManagers(List.of(accountManager)); | |
| AccountSummary fb3 = new AccountSummary(); | |
| fb3.setUid("facebook_3"); | |
| fb3.setOrganizationUid("organization_123"); | |
| fb3.setWorkspaceUid("workspace_122"); | |
| fb3.setAccountManagers(List.of(accountManager)); | |
| when(accountClient.getAccount("instagram_4")).thenReturn(ig4); | |
| when(accountClient.getAccount("facebook_3")).thenReturn(fb3); | |
| // when | |
| Map<String, AccountSummary> accountsByUid = service.generateAccountsByUid(manager, List.of(), links); | |
| // then | |
| assertThat(accountsByUid).containsExactlyInAnyOrderEntriesOf(Map.of("instagram_4", ig4, "facebook_3", fb3)); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should filter out twitter light links</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should filter out twitter light links'() { | |
| given: | |
| List<LinkSummary> links = ['facebook_1', 'twitter_1', 'twitter_2', 'twitter_3'].collect { uid -> new LinkSummary(accountUid: uid, sourceType: 'publishingPost') } | |
| Map<String, AccountSummary> accountsByUid = [ | |
| 'facebook_1': new AccountSummary(service: Service.facebook), | |
| 'twitter_1' : new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_LIGHT)), | |
| 'twitter_2' : new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_PLUS)), | |
| ] | |
| when: | |
| List<LinkSummary> filteredLinks = service.filterOutUnauthorizedLinks(links, accountsByUid, ['publishingPost']) | |
| then: | |
| filteredLinks == [ | |
| new LinkSummary(accountUid: 'facebook_1', sourceType: 'publishingPost'), | |
| new LinkSummary(accountUid: 'twitter_2', sourceType: 'publishingPost'), | |
| ] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldFilterOutTwitterLightLinks() { | |
| // given | |
| List<LinkSummary> links = List.of("facebook_1", "twitter_1", "twitter_2", "twitter_3").stream() | |
| .map(uid -> { | |
| LinkSummary link = new LinkSummary(); | |
| link.setAccountUid(uid); | |
| link.setSourceType("publishingPost"); | |
| return link; | |
| }).toList(); | |
| SpecificTwitterAccountData lightData = new SpecificTwitterAccountData(); | |
| lightData.setIntegrationLevel(TwitterIntegrationLevel.TWITTER_LIGHT); | |
| SpecificTwitterAccountData plusData = new SpecificTwitterAccountData(); | |
| plusData.setIntegrationLevel(TwitterIntegrationLevel.TWITTER_PLUS); | |
| AccountSummary fb1 = new AccountSummary(); | |
| fb1.setService(Service.facebook); | |
| AccountSummary tw1 = new AccountSummary(); | |
| tw1.setService(Service.twitter); | |
| tw1.setSpecificServiceAccountData(lightData); | |
| AccountSummary tw2 = new AccountSummary(); | |
| tw2.setService(Service.twitter); | |
| tw2.setSpecificServiceAccountData(plusData); | |
| Map<String, AccountSummary> accountsByUid = Map.of( | |
| "facebook_1", fb1, | |
| "twitter_1", tw1, | |
| "twitter_2", tw2 | |
| ); | |
| // when | |
| List<LinkSummary> filteredLinks = service.filterOutUnauthorizedLinks(links, accountsByUid, List.of("publishingPost")); | |
| // then | |
| assertThat(filteredLinks).hasSize(2); | |
| assertThat(filteredLinks).extracting(LinkSummary::getAccountUid).containsExactly("facebook_1", "twitter_2"); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should determine if twitter plus is needed - facebook account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should determine if twitter plus is needed - facebook account'() { | |
| given: | |
| AccountSummary account = new AccountSummary(service: Service.facebook) | |
| when: | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account) | |
| then: | |
| !needed | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldDetermineIfTwitterPlusIsNeededForFacebookAccount() { | |
| // given | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.facebook); | |
| // when | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account); | |
| // then | |
| assertThat(needed).isFalse(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should determine if twitter plus is needed - twitter light account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should determine if twitter plus is needed - twitter light account'() { | |
| given: | |
| AccountSummary account = new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_LIGHT)) | |
| when: | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account) | |
| then: | |
| needed | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldDetermineIfTwitterPlusIsNeededForTwitterLightAccount() { | |
| // given | |
| SpecificTwitterAccountData lightData = new SpecificTwitterAccountData(); | |
| lightData.setIntegrationLevel(TwitterIntegrationLevel.TWITTER_LIGHT); | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.twitter); | |
| account.setSpecificServiceAccountData(lightData); | |
| // when | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account); | |
| // then | |
| assertThat(needed).isTrue(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should determine if twitter plus is needed - twitter plus account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should determine if twitter plus is needed - twitter plus account'() { | |
| given: | |
| AccountSummary account = new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_PLUS)) | |
| when: | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account) | |
| then: | |
| !needed | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldDetermineIfTwitterPlusIsNeededForTwitterPlusAccount() { | |
| // given | |
| SpecificTwitterAccountData plusData = new SpecificTwitterAccountData(); | |
| plusData.setIntegrationLevel(TwitterIntegrationLevel.TWITTER_PLUS); | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.twitter); | |
| account.setSpecificServiceAccountData(plusData); | |
| // when | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account); | |
| // then | |
| assertThat(needed).isFalse(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should determine if twitter plus is needed - twitter account</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should determine if twitter plus is needed - twitter account'() { | |
| given: | |
| AccountSummary account = new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData()) | |
| when: | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account) | |
| then: | |
| needed | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldDetermineIfTwitterPlusIsNeededForTwitterAccount() { | |
| // given | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.twitter); | |
| account.setSpecificServiceAccountData(new SpecificTwitterAccountData()); | |
| // when | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account); | |
| // then | |
| assertThat(needed).isTrue(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should determine if twitter plus is needed - twitter account 2</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should determine if twitter plus is needed - twitter account 2'() { | |
| given: | |
| AccountSummary account = new AccountSummary(service: Service.twitter) | |
| when: | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account) | |
| then: | |
| needed | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldDetermineIfTwitterPlusIsNeededForTwitterAccountWithNullData() { | |
| // given | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.twitter); | |
| // when | |
| boolean needed = RoiPostInsightService.isTwitterPlusNeeded(account); | |
| // then | |
| assertThat(needed).isTrue(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post insight summaries</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post insight summaries'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Map<String, AccountSummary> accountsByUid = [ | |
| 'facebook_1' : new AccountSummary(service: Service.facebook, serviceId: '4654354'), | |
| 'instagram_3': new AccountSummary(service: Service.instagram, serviceId: '789789798'), | |
| 'google_20' : new AccountSummary(service: Service.google, serviceId: '7823145'), | |
| ] | |
| String identityId = 'ferq4g64e6' | |
| List<LinkSummary> links = [new LinkSummary(accountUid: 'facebook_1', serviceId: '45486435113'), | |
| new LinkSummary(accountUid: 'instagram_3', serviceId: '684648615'), | |
| new LinkSummary(accountUid: 'instagram_3', serviceId: null), | |
| new LinkSummary(accountUid: 'google_20', serviceId: '15959159')] | |
| List<PostInsightSummary> expectedResponse = [new PostInsightSummary(accountUid: 'facebook_1'), new PostInsightSummary(accountUid: 'instagram_3')] | |
| when: | |
| List<PostInsightSummary> postInsightSummaries = service.getPostInsightSummaries(organizationId, workspaceId, accountsByUid, identityId, links, LocalDate.parse('2023-01-01'), LocalDate.parse('2023-03-01')) | |
| then: | |
| 1 * postInsightSummaryClient.getPostInsightSummaries(new PostInsightSummariesRequest(items: [ | |
| new PostInsightSummariesRequest.Item(accountUid: 'facebook_1', serviceAccountId: '4654354', servicePostId: '45486435113'), | |
| new PostInsightSummariesRequest.Item(accountUid: 'instagram_3', serviceAccountId: '789789798', servicePostId: '684648615') | |
| ]), identityId) >> new GetPostInsightSummariesResponse(postInsightSummaries: expectedResponse) | |
| postInsightSummaries == expectedResponse | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostInsightSummaries() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| AccountSummary fb1 = new AccountSummary(); | |
| fb1.setService(Service.facebook); | |
| fb1.setServiceId("4654354"); | |
| AccountSummary ig3 = new AccountSummary(); | |
| ig3.setService(Service.instagram); | |
| ig3.setServiceId("789789798"); | |
| AccountSummary g20 = new AccountSummary(); | |
| g20.setService(Service.google); | |
| g20.setServiceId("7823145"); | |
| Map<String, AccountSummary> accountsByUid = Map.of( | |
| "facebook_1", fb1, | |
| "instagram_3", ig3, | |
| "google_20", g20 | |
| ); | |
| String identityId = "ferq4g64e6"; | |
| LinkSummary link1 = new LinkSummary(); | |
| link1.setAccountUid("facebook_1"); | |
| link1.setServiceId("45486435113"); | |
| LinkSummary link2 = new LinkSummary(); | |
| link2.setAccountUid("instagram_3"); | |
| link2.setServiceId("684648615"); | |
| LinkSummary link3 = new LinkSummary(); | |
| link3.setAccountUid("instagram_3"); | |
| link3.setServiceId(null); | |
| LinkSummary link4 = new LinkSummary(); | |
| link4.setAccountUid("google_20"); | |
| link4.setServiceId("15959159"); | |
| List<LinkSummary> links = List.of(link1, link2, link3, link4); | |
| PostInsightSummary pi1 = new PostInsightSummary(); | |
| pi1.setAccountUid("facebook_1"); | |
| PostInsightSummary pi2 = new PostInsightSummary(); | |
| pi2.setAccountUid("instagram_3"); | |
| List<PostInsightSummary> expectedResponse = List.of(pi1, pi2); | |
| GetPostInsightSummariesResponse response = new GetPostInsightSummariesResponse(); | |
| response.setPostInsightSummaries(expectedResponse); | |
| when(postInsightSummaryClient.getPostInsightSummaries(any(PostInsightSummariesRequest.class), eq(identityId))).thenReturn(response); | |
| // when | |
| List<PostInsightSummary> postInsightSummaries = service.getPostInsightSummaries( | |
| organizationId, workspaceId, accountsByUid, identityId, links, | |
| LocalDate.parse("2023-01-01"), LocalDate.parse("2023-03-01") | |
| ); | |
| // then | |
| assertThat(postInsightSummaries).isEqualTo(expectedResponse); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post insight summaries - empty</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post insight summaries - empty'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Map<String, AccountSummary> accountsByUid = [:] | |
| String identityId = 'ferq4g64e6' | |
| List<LinkSummary> links = [] | |
| when: | |
| List<PostInsightSummary> postInsightSummaries = service.getPostInsightSummaries(organizationId, workspaceId, accountsByUid, identityId, links, LocalDate.parse('2023-01-01'), LocalDate.parse('2023-03-01')) | |
| then: | |
| 1 * postInsightSummaryClient.getPostInsightSummaries(*_) >> null | |
| postInsightSummaries == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostInsightSummariesEmpty() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Map<String, AccountSummary> accountsByUid = Map.of(); | |
| String identityId = "ferq4g64e6"; | |
| List<LinkSummary> links = List.of(); | |
| when(postInsightSummaryClient.getPostInsightSummaries(any(), any())).thenReturn(null); | |
| // when | |
| List<PostInsightSummary> postInsightSummaries = service.getPostInsightSummaries( | |
| organizationId, workspaceId, accountsByUid, identityId, links, | |
| LocalDate.parse("2023-01-01"), LocalDate.parse("2023-03-01") | |
| ); | |
| // then | |
| assertThat(postInsightSummaries).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by uids</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by uids'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Set<String> linkUids = ['ap_789', 'ap_456', 'ap_123', 'ap_111', 'ap222'] | |
| when: | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids) | |
| then: | |
| 1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) >> new GetLinksResponse(links: [ | |
| new LinkSummary(uid: 'ap_789', sourceType: 'inboxMessage', creationDate: DATE_05_13, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_456', sourceType: 'publishingPost', creationDate: DATE_05_14, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_123', sourceType: 'firstComment', creationDate: DATE_05_15, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_111', sourceType: 'firstComment', accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_222', sourceType: 'firstComment', creationDate: DATE_05_15), | |
| ]) | |
| links == [ | |
| new LinkSummary(uid: 'ap_789', sourceType: 'inboxMessage', creationDate: DATE_05_13, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_456', sourceType: 'publishingPost', creationDate: DATE_05_14, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_123', sourceType: 'firstComment', creationDate: DATE_05_15, accountUid: ACCOUNT_UID), | |
| ] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByUids() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Set<String> linkUids = Set.of("ap_789", "ap_456", "ap_123", "ap_111", "ap222"); | |
| GetLinksResponse response = new GetLinksResponse(); | |
| response.setLinks(List.of( | |
| createLink("ap_789", "inboxMessage", DATE_05_13, ACCOUNT_UID), | |
| createLink("ap_456", "publishingPost", DATE_05_14, ACCOUNT_UID), | |
| createLink("ap_123", "firstComment", DATE_05_15, ACCOUNT_UID), | |
| createLinkWithoutDate("ap_111", "firstComment", ACCOUNT_UID), | |
| createLinkWithoutAccount("ap_222", "firstComment", DATE_05_15) | |
| )); | |
| when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(response); | |
| // when | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids); | |
| // then | |
| assertThat(links).hasSize(3); | |
| assertThat(links).extracting(LinkSummary::getUid).containsExactly("ap_789", "ap_456", "ap_123"); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by uids - empty set</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by uids - empty set'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Set<String> linkUids = [] | |
| when: | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids) | |
| then: | |
| 0 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: [])) | |
| links == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByUidsEmptySet() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Set<String> linkUids = Set.of(); | |
| // when | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids); | |
| // then | |
| assertThat(links).isEmpty(); | |
| verify(linkClient, never()).getLinks(any(), any(), any()); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by uids - null responses</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by uids - null responses'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Set<String> linkUids = ['ap_123'] | |
| when: | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids) | |
| then: | |
| 1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) >> response | |
| links == [] | |
| where: | |
| response << [null, new GetLinksResponse(links: null)] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByUidsNullResponse() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Set<String> linkUids = Set.of("ap_123"); | |
| when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(null); | |
| // when | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by uids - exception</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by uids - exception'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| Set<String> linkUids = ['ap_123'] | |
| when: | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids) | |
| then: | |
| 1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) >> { | |
| throw new HttpClientException('time out') | |
| } | |
| links == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByUidsNullLinksInResponse() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Set<String> linkUids = Set.of("ap_123"); | |
| GetLinksResponse response = new GetLinksResponse(); | |
| response.setLinks(null); | |
| when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(response); | |
| // when | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by dates</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by dates'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| when: | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse('2023-05-12'), LocalDate.parse('2023-05-29')) | |
| then: | |
| 1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse('2023-05-12T00:00:00Z'), Instant.parse('2023-05-30T00:00:00Z')) >> new GetLinksResponse(links: [ | |
| new LinkSummary(uid: 'ap_789', sourceType: 'inboxMessage', creationDate: DATE_05_13, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_456', sourceType: 'publishingPost', creationDate: DATE_05_14, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_123', sourceType: 'firstComment', creationDate: DATE_05_15, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_111', sourceType: 'firstComment', accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_222', sourceType: 'firstComment', creationDate: DATE_05_15), | |
| ]) | |
| links == [ | |
| new LinkSummary(uid: 'ap_789', sourceType: 'inboxMessage', creationDate: DATE_05_13, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_456', sourceType: 'publishingPost', creationDate: DATE_05_14, accountUid: ACCOUNT_UID), | |
| new LinkSummary(uid: 'ap_123', sourceType: 'firstComment', creationDate: DATE_05_15, accountUid: ACCOUNT_UID), | |
| ] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByUidsException() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| Set<String> linkUids = Set.of("ap_123"); | |
| when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))) | |
| .thenThrow(new HttpClientException("time out")); | |
| // when | |
| List<LinkSummary> links = service.getLinksByUids(organizationId, workspaceId, linkUids); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by dates - null responses</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by dates - null responses'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| when: | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse('2023-05-12'), LocalDate.parse('2023-05-29')) | |
| then: | |
| 1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse('2023-05-12T00:00:00Z'), Instant.parse('2023-05-30T00:00:00Z')) >> response | |
| links == [] | |
| where: | |
| response << [null, new GetLinksResponse(links: null)] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByDates() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| GetLinksResponse response = new GetLinksResponse(); | |
| response.setLinks(List.of( | |
| createLink("ap_789", "inboxMessage", DATE_05_13, ACCOUNT_UID), | |
| createLink("ap_456", "publishingPost", DATE_05_14, ACCOUNT_UID), | |
| createLink("ap_123", "firstComment", DATE_05_15, ACCOUNT_UID), | |
| createLinkWithoutDate("ap_111", "firstComment", ACCOUNT_UID), | |
| createLinkWithoutAccount("ap_222", "firstComment", DATE_05_15) | |
| )); | |
| when(linkClient.getLinksByCreationTime(organizationId, workspaceId, | |
| Instant.parse("2023-05-12T00:00:00Z"), Instant.parse("2023-05-30T00:00:00Z"))).thenReturn(response); | |
| // when | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, | |
| LocalDate.parse("2023-05-12"), LocalDate.parse("2023-05-29")); | |
| // then | |
| assertThat(links).hasSize(3); | |
| assertThat(links).extracting(LinkSummary::getUid).containsExactly("ap_789", "ap_456", "ap_123"); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should get post links by dates - exception</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should get post links by dates - exception'() { | |
| given: | |
| Long organizationId = 123 | |
| Long workspaceId = 456 | |
| when: | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse('2023-05-12'), LocalDate.parse('2023-05-29')) | |
| then: | |
| 1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse('2023-05-12T00:00:00Z'), Instant.parse('2023-05-30T00:00:00Z')) >> { | |
| throw new HttpClientException('time out') | |
| } | |
| links == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByDatesNullResponse() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| when(linkClient.getLinksByCreationTime(organizationId, workspaceId, | |
| Instant.parse("2023-05-12T00:00:00Z"), Instant.parse("2023-05-30T00:00:00Z"))).thenReturn(null); | |
| // when | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, | |
| LocalDate.parse("2023-05-12"), LocalDate.parse("2023-05-29")); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should find a post insight summary when a urn is provided</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should find a post insight summary when a urn is provided'() { | |
| given: | |
| PostInsightSummary expectedPostInsightSummary = new PostInsightSummary( | |
| serviceId: '1234' | |
| ) | |
| List<PostInsightSummary> postInsightSummaries = [ | |
| expectedPostInsightSummary | |
| ] | |
| AccountSummary account = new AccountSummary( | |
| service: Service.linkedin | |
| ) | |
| when: | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, 'urn:li:share:1234', account) | |
| then: | |
| actualPostInsightSummary == expectedPostInsightSummary | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByDatesNullLinksInResponse() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| GetLinksResponse response = new GetLinksResponse(); | |
| response.setLinks(null); | |
| when(linkClient.getLinksByCreationTime(organizationId, workspaceId, | |
| Instant.parse("2023-05-12T00:00:00Z"), Instant.parse("2023-05-30T00:00:00Z"))).thenReturn(response); | |
| // when | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, | |
| LocalDate.parse("2023-05-12"), LocalDate.parse("2023-05-29")); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should find a post insight summary when a simple fb id is provided</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should find a post insight summary when a simple fb id is provided'() { | |
| given: | |
| PostInsightSummary expectedPostInsightSummary = new PostInsightSummary( | |
| serviceId: '3456_1234' | |
| ) | |
| List<PostInsightSummary> postInsightSummaries = [ | |
| expectedPostInsightSummary | |
| ] | |
| AccountSummary account = new AccountSummary( | |
| service: Service.facebook, | |
| serviceId: '3456' | |
| ) | |
| when: | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, '1234', account) | |
| then: | |
| actualPostInsightSummary == expectedPostInsightSummary | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldGetPostLinksByDatesException() { | |
| // given | |
| Long organizationId = 123L; | |
| Long workspaceId = 456L; | |
| when(linkClient.getLinksByCreationTime(organizationId, workspaceId, | |
| Instant.parse("2023-05-12T00:00:00Z"), Instant.parse("2023-05-30T00:00:00Z"))) | |
| .thenThrow(new HttpClientException("time out")); | |
| // when | |
| List<LinkSummary> links = service.getLinksByDates(organizationId, workspaceId, | |
| LocalDate.parse("2023-05-12"), LocalDate.parse("2023-05-29")); | |
| // then | |
| assertThat(links).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should find a post insight summary when an id is provided</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should find a post insight summary when an id is provided'() { | |
| given: | |
| PostInsightSummary expectedPostInsightSummary = new PostInsightSummary( | |
| serviceId: '1234' | |
| ) | |
| List<PostInsightSummary> postInsightSummaries = [ | |
| expectedPostInsightSummary | |
| ] | |
| AccountSummary account = new AccountSummary( | |
| service: Service.instagram, | |
| ) | |
| when: | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, '1234', account) | |
| then: | |
| actualPostInsightSummary == expectedPostInsightSummary | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldFindPostInsightSummaryWhenUrnIsProvided() { | |
| // given | |
| PostInsightSummary expectedPostInsightSummary = new PostInsightSummary(); | |
| expectedPostInsightSummary.setServiceId("1234"); | |
| List<PostInsightSummary> postInsightSummaries = List.of(expectedPostInsightSummary); | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.linkedin); | |
| // when | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink( | |
| postInsightSummaries, "urn:li:share:1234", account); | |
| // then | |
| assertThat(actualPostInsightSummary).isEqualTo(expectedPostInsightSummary); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should not find a post insight summary when an id is unknown</h2> | |
| <span class="toggle">▼</span> | |
| </div> | |
| <div class="section-content"> | |
| <div class="diff-container"> | |
| <div class="diff-panel left"> | |
| <h3>Spock (Groovy)</h3> | |
| <pre> void 'should not find a post insight summary when an id is unknown'() { | |
| given: | |
| PostInsightSummary expectedPostInsightSummary = null | |
| List<PostInsightSummary> postInsightSummaries = [ | |
| new PostInsightSummary( | |
| serviceId: '1234' | |
| ) | |
| ] | |
| AccountSummary account = new AccountSummary( | |
| service: Service.instagram, | |
| ) | |
| when: | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, '12345', account) | |
| then: | |
| actualPostInsightSummary == expectedPostInsightSummary | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre> @Test | |
| void shouldFindPostInsightSummaryWhenSimpleFbIdIsProvided() { | |
| // given | |
| PostInsightSummary expectedPostInsightSummary = new PostInsightSummary(); | |
| expectedPostInsightSummary.setServiceId("3456_1234"); | |
| List<PostInsightSummary> postInsightSummaries = List.of(expectedPostInsightSummary); | |
| AccountSummary account = new AccountSummary(); | |
| account.setService(Service.facebook); | |
| account.setServiceId("3456"); | |
| // when | |
| PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink( | |
| postInsightSummaries, "1234", account); | |
| // then | |
| assertThat(actualPostInsightSummary).isEqualTo(expectedPostInsightSummary); | |
| }</pre> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| function toggleSection(header) { | |
| const content = header.nextElementSibling; | |
| const toggle = header.querySelector('.toggle'); | |
| content.classList.toggle('collapsed'); | |
| toggle.textContent = content.classList.contains('collapsed') ? '▶' : '▼'; | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment