Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save musketyr/1de0159cc38744834f109cfc459778ba to your computer and use it in GitHub Desktop.

Select an option

Save musketyr/1de0159cc38744834f109cfc459778ba to your computer and use it in GitHub Desktop.
Spock to JUnit 5 Migration Diff
<!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 = &#x27;ac123&#x27;
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 = &quot;ac123&quot;;
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 &#x27;should generate accounts by uid - empty&#x27;() {
given:
List&lt;LinkSummary&gt; links = []
when:
Map&lt;String, AccountSummary&gt; 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&lt;LinkSummary&gt; links = List.of();
// when
Map&lt;String, AccountSummary&gt; 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 &#x27;should generate accounts by uid - one account&#x27;() {
given:
List&lt;LinkSummary&gt; links = [new LinkSummary(accountUid: &#x27;facebook_3&#x27;)]
ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false)
AccountSummary fb3 = new AccountSummary(uid: &#x27;facebook_3&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
when:
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, [fb3], links)
then:
0 * _
accountsByUid == [&#x27;facebook_3&#x27;: fb3]
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldGenerateAccountsByUidOneAccount() {
// given
LinkSummary link = new LinkSummary();
link.setAccountUid(&quot;facebook_3&quot;);
List&lt;LinkSummary&gt; 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(&quot;facebook_3&quot;);
fb3.setAccountManagers(List.of(accountManager));
// when
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, List.of(fb3), links);
// then
assertThat(accountsByUid).containsExactlyEntriesOf(Map.of(&quot;facebook_3&quot;, 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 &#x27;should generate accounts by uid - same account&#x27;() {
given:
List&lt;LinkSummary&gt; links = [new LinkSummary(accountUid: &#x27;facebook_3&#x27;, uid: &#x27;ap_g8h5eiou&#x27;), new LinkSummary(accountUid: &#x27;facebook_3&#x27;, uid: &#x27;ap_vf1d4t47&#x27;)]
ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false)
AccountSummary fb3 = new AccountSummary(uid: &#x27;facebook_3&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
when:
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, [fb3], links)
then:
0 * _
accountsByUid == [&#x27;facebook_3&#x27;: fb3]
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldGenerateAccountsByUidSameAccount() {
// given
LinkSummary link1 = new LinkSummary();
link1.setAccountUid(&quot;facebook_3&quot;);
link1.setUid(&quot;ap_g8h5eiou&quot;);
LinkSummary link2 = new LinkSummary();
link2.setAccountUid(&quot;facebook_3&quot;);
link2.setUid(&quot;ap_vf1d4t47&quot;);
List&lt;LinkSummary&gt; 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(&quot;facebook_3&quot;);
fb3.setAccountManagers(List.of(accountManager));
// when
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, List.of(fb3), links);
// then
assertThat(accountsByUid).containsExactlyEntriesOf(Map.of(&quot;facebook_3&quot;, 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 &#x27;should generate accounts by uid - 2 accounts&#x27;() {
given:
List&lt;LinkSummary&gt; links = [new LinkSummary(accountUid: &#x27;instagram_4&#x27;, uid: &#x27;ap_g8h5eiou&#x27;), new LinkSummary(accountUid: &#x27;facebook_3&#x27;, uid: &#x27;ap_vf1d4t47&#x27;)]
ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: false)
AccountSummary ig4 = new AccountSummary(uid: &#x27;instagram_4&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
AccountSummary fb3 = new AccountSummary(uid: &#x27;facebook_3&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
when:
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, [ig4, fb3], links)
then:
0 * _
accountsByUid == [&#x27;instagram_4&#x27;: ig4, &#x27;facebook_3&#x27;: fb3]
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldGenerateAccountsByUidTwoAccounts() {
// given
LinkSummary link1 = new LinkSummary();
link1.setAccountUid(&quot;instagram_4&quot;);
link1.setUid(&quot;ap_g8h5eiou&quot;);
LinkSummary link2 = new LinkSummary();
link2.setAccountUid(&quot;facebook_3&quot;);
link2.setUid(&quot;ap_vf1d4t47&quot;);
List&lt;LinkSummary&gt; 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(&quot;instagram_4&quot;);
ig4.setAccountManagers(List.of(accountManager));
AccountSummary fb3 = new AccountSummary();
fb3.setUid(&quot;facebook_3&quot;);
fb3.setAccountManagers(List.of(accountManager));
// when
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, List.of(ig4, fb3), links);
// then
assertThat(accountsByUid).containsExactlyInAnyOrderEntriesOf(Map.of(&quot;instagram_4&quot;, ig4, &quot;facebook_3&quot;, 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 &#x27;should generate accounts by uid - 2 accounts - admin mode&#x27;() {
given:
List&lt;LinkSummary&gt; links = [new LinkSummary(accountUid: &#x27;instagram_4&#x27;, uid: &#x27;ap_g8h5eiou&#x27;), new LinkSummary(accountUid: &#x27;facebook_3&#x27;, uid: &#x27;ap_vf1d4t47&#x27;)]
ManagerSummary manager = new ManagerSummary(id: 123, administratorEnabled: true)
AccountSummary ig4 = new AccountSummary(uid: &#x27;instagram_4&#x27;, organizationUid: &#x27;organization_123&#x27;, workspaceUid: &#x27;workspace_122&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
AccountSummary fb3 = new AccountSummary(uid: &#x27;facebook_3&#x27;, organizationUid: &#x27;organization_123&#x27;, workspaceUid: &#x27;workspace_122&#x27;, accountManagers: [new AccountManagerSummary(managerId: 123)])
when:
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, [], links)
then:
1 * accountClient.getAccount(&#x27;instagram_4&#x27;) &gt;&gt; ig4
1 * accountClient.getAccount(&#x27;facebook_3&#x27;) &gt;&gt; fb3
accountsByUid == [&#x27;instagram_4&#x27;: ig4, &#x27;facebook_3&#x27;: fb3]
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldGenerateAccountsByUidTwoAccountsAdminMode() {
// given
LinkSummary link1 = new LinkSummary();
link1.setAccountUid(&quot;instagram_4&quot;);
link1.setUid(&quot;ap_g8h5eiou&quot;);
LinkSummary link2 = new LinkSummary();
link2.setAccountUid(&quot;facebook_3&quot;);
link2.setUid(&quot;ap_vf1d4t47&quot;);
List&lt;LinkSummary&gt; 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(&quot;instagram_4&quot;);
ig4.setOrganizationUid(&quot;organization_123&quot;);
ig4.setWorkspaceUid(&quot;workspace_122&quot;);
ig4.setAccountManagers(List.of(accountManager));
AccountSummary fb3 = new AccountSummary();
fb3.setUid(&quot;facebook_3&quot;);
fb3.setOrganizationUid(&quot;organization_123&quot;);
fb3.setWorkspaceUid(&quot;workspace_122&quot;);
fb3.setAccountManagers(List.of(accountManager));
when(accountClient.getAccount(&quot;instagram_4&quot;)).thenReturn(ig4);
when(accountClient.getAccount(&quot;facebook_3&quot;)).thenReturn(fb3);
// when
Map&lt;String, AccountSummary&gt; accountsByUid = service.generateAccountsByUid(manager, List.of(), links);
// then
assertThat(accountsByUid).containsExactlyInAnyOrderEntriesOf(Map.of(&quot;instagram_4&quot;, ig4, &quot;facebook_3&quot;, 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 &#x27;should filter out twitter light links&#x27;() {
given:
List&lt;LinkSummary&gt; links = [&#x27;facebook_1&#x27;, &#x27;twitter_1&#x27;, &#x27;twitter_2&#x27;, &#x27;twitter_3&#x27;].collect { uid -&gt; new LinkSummary(accountUid: uid, sourceType: &#x27;publishingPost&#x27;) }
Map&lt;String, AccountSummary&gt; accountsByUid = [
&#x27;facebook_1&#x27;: new AccountSummary(service: Service.facebook),
&#x27;twitter_1&#x27; : new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_LIGHT)),
&#x27;twitter_2&#x27; : new AccountSummary(service: Service.twitter, specificServiceAccountData: new SpecificTwitterAccountData(integrationLevel: TwitterIntegrationLevel.TWITTER_PLUS)),
]
when:
List&lt;LinkSummary&gt; filteredLinks = service.filterOutUnauthorizedLinks(links, accountsByUid, [&#x27;publishingPost&#x27;])
then:
filteredLinks == [
new LinkSummary(accountUid: &#x27;facebook_1&#x27;, sourceType: &#x27;publishingPost&#x27;),
new LinkSummary(accountUid: &#x27;twitter_2&#x27;, sourceType: &#x27;publishingPost&#x27;),
]
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldFilterOutTwitterLightLinks() {
// given
List&lt;LinkSummary&gt; links = List.of(&quot;facebook_1&quot;, &quot;twitter_1&quot;, &quot;twitter_2&quot;, &quot;twitter_3&quot;).stream()
.map(uid -&gt; {
LinkSummary link = new LinkSummary();
link.setAccountUid(uid);
link.setSourceType(&quot;publishingPost&quot;);
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&lt;String, AccountSummary&gt; accountsByUid = Map.of(
&quot;facebook_1&quot;, fb1,
&quot;twitter_1&quot;, tw1,
&quot;twitter_2&quot;, tw2
);
// when
List&lt;LinkSummary&gt; filteredLinks = service.filterOutUnauthorizedLinks(links, accountsByUid, List.of(&quot;publishingPost&quot;));
// then
assertThat(filteredLinks).hasSize(2);
assertThat(filteredLinks).extracting(LinkSummary::getAccountUid).containsExactly(&quot;facebook_1&quot;, &quot;twitter_2&quot;);
}</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 &#x27;should determine if twitter plus is needed - facebook account&#x27;() {
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 &#x27;should determine if twitter plus is needed - twitter light account&#x27;() {
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 &#x27;should determine if twitter plus is needed - twitter plus account&#x27;() {
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 &#x27;should determine if twitter plus is needed - twitter account&#x27;() {
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 &#x27;should determine if twitter plus is needed - twitter account 2&#x27;() {
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 &#x27;should get post insight summaries&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Map&lt;String, AccountSummary&gt; accountsByUid = [
&#x27;facebook_1&#x27; : new AccountSummary(service: Service.facebook, serviceId: &#x27;4654354&#x27;),
&#x27;instagram_3&#x27;: new AccountSummary(service: Service.instagram, serviceId: &#x27;789789798&#x27;),
&#x27;google_20&#x27; : new AccountSummary(service: Service.google, serviceId: &#x27;7823145&#x27;),
]
String identityId = &#x27;ferq4g64e6&#x27;
List&lt;LinkSummary&gt; links = [new LinkSummary(accountUid: &#x27;facebook_1&#x27;, serviceId: &#x27;45486435113&#x27;),
new LinkSummary(accountUid: &#x27;instagram_3&#x27;, serviceId: &#x27;684648615&#x27;),
new LinkSummary(accountUid: &#x27;instagram_3&#x27;, serviceId: null),
new LinkSummary(accountUid: &#x27;google_20&#x27;, serviceId: &#x27;15959159&#x27;)]
List&lt;PostInsightSummary&gt; expectedResponse = [new PostInsightSummary(accountUid: &#x27;facebook_1&#x27;), new PostInsightSummary(accountUid: &#x27;instagram_3&#x27;)]
when:
List&lt;PostInsightSummary&gt; postInsightSummaries = service.getPostInsightSummaries(organizationId, workspaceId, accountsByUid, identityId, links, LocalDate.parse(&#x27;2023-01-01&#x27;), LocalDate.parse(&#x27;2023-03-01&#x27;))
then:
1 * postInsightSummaryClient.getPostInsightSummaries(new PostInsightSummariesRequest(items: [
new PostInsightSummariesRequest.Item(accountUid: &#x27;facebook_1&#x27;, serviceAccountId: &#x27;4654354&#x27;, servicePostId: &#x27;45486435113&#x27;),
new PostInsightSummariesRequest.Item(accountUid: &#x27;instagram_3&#x27;, serviceAccountId: &#x27;789789798&#x27;, servicePostId: &#x27;684648615&#x27;)
]), identityId) &gt;&gt; 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(&quot;4654354&quot;);
AccountSummary ig3 = new AccountSummary();
ig3.setService(Service.instagram);
ig3.setServiceId(&quot;789789798&quot;);
AccountSummary g20 = new AccountSummary();
g20.setService(Service.google);
g20.setServiceId(&quot;7823145&quot;);
Map&lt;String, AccountSummary&gt; accountsByUid = Map.of(
&quot;facebook_1&quot;, fb1,
&quot;instagram_3&quot;, ig3,
&quot;google_20&quot;, g20
);
String identityId = &quot;ferq4g64e6&quot;;
LinkSummary link1 = new LinkSummary();
link1.setAccountUid(&quot;facebook_1&quot;);
link1.setServiceId(&quot;45486435113&quot;);
LinkSummary link2 = new LinkSummary();
link2.setAccountUid(&quot;instagram_3&quot;);
link2.setServiceId(&quot;684648615&quot;);
LinkSummary link3 = new LinkSummary();
link3.setAccountUid(&quot;instagram_3&quot;);
link3.setServiceId(null);
LinkSummary link4 = new LinkSummary();
link4.setAccountUid(&quot;google_20&quot;);
link4.setServiceId(&quot;15959159&quot;);
List&lt;LinkSummary&gt; links = List.of(link1, link2, link3, link4);
PostInsightSummary pi1 = new PostInsightSummary();
pi1.setAccountUid(&quot;facebook_1&quot;);
PostInsightSummary pi2 = new PostInsightSummary();
pi2.setAccountUid(&quot;instagram_3&quot;);
List&lt;PostInsightSummary&gt; expectedResponse = List.of(pi1, pi2);
GetPostInsightSummariesResponse response = new GetPostInsightSummariesResponse();
response.setPostInsightSummaries(expectedResponse);
when(postInsightSummaryClient.getPostInsightSummaries(any(PostInsightSummariesRequest.class), eq(identityId))).thenReturn(response);
// when
List&lt;PostInsightSummary&gt; postInsightSummaries = service.getPostInsightSummaries(
organizationId, workspaceId, accountsByUid, identityId, links,
LocalDate.parse(&quot;2023-01-01&quot;), LocalDate.parse(&quot;2023-03-01&quot;)
);
// 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 &#x27;should get post insight summaries - empty&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Map&lt;String, AccountSummary&gt; accountsByUid = [:]
String identityId = &#x27;ferq4g64e6&#x27;
List&lt;LinkSummary&gt; links = []
when:
List&lt;PostInsightSummary&gt; postInsightSummaries = service.getPostInsightSummaries(organizationId, workspaceId, accountsByUid, identityId, links, LocalDate.parse(&#x27;2023-01-01&#x27;), LocalDate.parse(&#x27;2023-03-01&#x27;))
then:
1 * postInsightSummaryClient.getPostInsightSummaries(*_) &gt;&gt; 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&lt;String, AccountSummary&gt; accountsByUid = Map.of();
String identityId = &quot;ferq4g64e6&quot;;
List&lt;LinkSummary&gt; links = List.of();
when(postInsightSummaryClient.getPostInsightSummaries(any(), any())).thenReturn(null);
// when
List&lt;PostInsightSummary&gt; postInsightSummaries = service.getPostInsightSummaries(
organizationId, workspaceId, accountsByUid, identityId, links,
LocalDate.parse(&quot;2023-01-01&quot;), LocalDate.parse(&quot;2023-03-01&quot;)
);
// 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 &#x27;should get post links by uids&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Set&lt;String&gt; linkUids = [&#x27;ap_789&#x27;, &#x27;ap_456&#x27;, &#x27;ap_123&#x27;, &#x27;ap_111&#x27;, &#x27;ap222&#x27;]
when:
List&lt;LinkSummary&gt; links = service.getLinksByUids(organizationId, workspaceId, linkUids)
then:
1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) &gt;&gt; new GetLinksResponse(links: [
new LinkSummary(uid: &#x27;ap_789&#x27;, sourceType: &#x27;inboxMessage&#x27;, creationDate: DATE_05_13, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_456&#x27;, sourceType: &#x27;publishingPost&#x27;, creationDate: DATE_05_14, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_123&#x27;, sourceType: &#x27;firstComment&#x27;, creationDate: DATE_05_15, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_111&#x27;, sourceType: &#x27;firstComment&#x27;, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_222&#x27;, sourceType: &#x27;firstComment&#x27;, creationDate: DATE_05_15),
])
links == [
new LinkSummary(uid: &#x27;ap_789&#x27;, sourceType: &#x27;inboxMessage&#x27;, creationDate: DATE_05_13, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_456&#x27;, sourceType: &#x27;publishingPost&#x27;, creationDate: DATE_05_14, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_123&#x27;, sourceType: &#x27;firstComment&#x27;, 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&lt;String&gt; linkUids = Set.of(&quot;ap_789&quot;, &quot;ap_456&quot;, &quot;ap_123&quot;, &quot;ap_111&quot;, &quot;ap222&quot;);
GetLinksResponse response = new GetLinksResponse();
response.setLinks(List.of(
createLink(&quot;ap_789&quot;, &quot;inboxMessage&quot;, DATE_05_13, ACCOUNT_UID),
createLink(&quot;ap_456&quot;, &quot;publishingPost&quot;, DATE_05_14, ACCOUNT_UID),
createLink(&quot;ap_123&quot;, &quot;firstComment&quot;, DATE_05_15, ACCOUNT_UID),
createLinkWithoutDate(&quot;ap_111&quot;, &quot;firstComment&quot;, ACCOUNT_UID),
createLinkWithoutAccount(&quot;ap_222&quot;, &quot;firstComment&quot;, DATE_05_15)
));
when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(response);
// when
List&lt;LinkSummary&gt; links = service.getLinksByUids(organizationId, workspaceId, linkUids);
// then
assertThat(links).hasSize(3);
assertThat(links).extracting(LinkSummary::getUid).containsExactly(&quot;ap_789&quot;, &quot;ap_456&quot;, &quot;ap_123&quot;);
}</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 &#x27;should get post links by uids - empty set&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Set&lt;String&gt; linkUids = []
when:
List&lt;LinkSummary&gt; 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&lt;String&gt; linkUids = Set.of();
// when
List&lt;LinkSummary&gt; 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 &#x27;should get post links by uids - null responses&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Set&lt;String&gt; linkUids = [&#x27;ap_123&#x27;]
when:
List&lt;LinkSummary&gt; links = service.getLinksByUids(organizationId, workspaceId, linkUids)
then:
1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) &gt;&gt; response
links == []
where:
response &lt;&lt; [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&lt;String&gt; linkUids = Set.of(&quot;ap_123&quot;);
when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(null);
// when
List&lt;LinkSummary&gt; 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 &#x27;should get post links by uids - exception&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
Set&lt;String&gt; linkUids = [&#x27;ap_123&#x27;]
when:
List&lt;LinkSummary&gt; links = service.getLinksByUids(organizationId, workspaceId, linkUids)
then:
1 * linkClient.getLinks(organizationId, workspaceId, new GetLinksRequest(linkUids: linkUids.toList())) &gt;&gt; {
throw new HttpClientException(&#x27;time out&#x27;)
}
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&lt;String&gt; linkUids = Set.of(&quot;ap_123&quot;);
GetLinksResponse response = new GetLinksResponse();
response.setLinks(null);
when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class))).thenReturn(response);
// when
List&lt;LinkSummary&gt; 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 &#x27;should get post links by dates&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
when:
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse(&#x27;2023-05-12&#x27;), LocalDate.parse(&#x27;2023-05-29&#x27;))
then:
1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse(&#x27;2023-05-12T00:00:00Z&#x27;), Instant.parse(&#x27;2023-05-30T00:00:00Z&#x27;)) &gt;&gt; new GetLinksResponse(links: [
new LinkSummary(uid: &#x27;ap_789&#x27;, sourceType: &#x27;inboxMessage&#x27;, creationDate: DATE_05_13, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_456&#x27;, sourceType: &#x27;publishingPost&#x27;, creationDate: DATE_05_14, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_123&#x27;, sourceType: &#x27;firstComment&#x27;, creationDate: DATE_05_15, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_111&#x27;, sourceType: &#x27;firstComment&#x27;, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_222&#x27;, sourceType: &#x27;firstComment&#x27;, creationDate: DATE_05_15),
])
links == [
new LinkSummary(uid: &#x27;ap_789&#x27;, sourceType: &#x27;inboxMessage&#x27;, creationDate: DATE_05_13, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_456&#x27;, sourceType: &#x27;publishingPost&#x27;, creationDate: DATE_05_14, accountUid: ACCOUNT_UID),
new LinkSummary(uid: &#x27;ap_123&#x27;, sourceType: &#x27;firstComment&#x27;, 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&lt;String&gt; linkUids = Set.of(&quot;ap_123&quot;);
when(linkClient.getLinks(eq(organizationId), eq(workspaceId), any(GetLinksRequest.class)))
.thenThrow(new HttpClientException(&quot;time out&quot;));
// when
List&lt;LinkSummary&gt; 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 &#x27;should get post links by dates - null responses&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
when:
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse(&#x27;2023-05-12&#x27;), LocalDate.parse(&#x27;2023-05-29&#x27;))
then:
1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse(&#x27;2023-05-12T00:00:00Z&#x27;), Instant.parse(&#x27;2023-05-30T00:00:00Z&#x27;)) &gt;&gt; response
links == []
where:
response &lt;&lt; [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(&quot;ap_789&quot;, &quot;inboxMessage&quot;, DATE_05_13, ACCOUNT_UID),
createLink(&quot;ap_456&quot;, &quot;publishingPost&quot;, DATE_05_14, ACCOUNT_UID),
createLink(&quot;ap_123&quot;, &quot;firstComment&quot;, DATE_05_15, ACCOUNT_UID),
createLinkWithoutDate(&quot;ap_111&quot;, &quot;firstComment&quot;, ACCOUNT_UID),
createLinkWithoutAccount(&quot;ap_222&quot;, &quot;firstComment&quot;, DATE_05_15)
));
when(linkClient.getLinksByCreationTime(organizationId, workspaceId,
Instant.parse(&quot;2023-05-12T00:00:00Z&quot;), Instant.parse(&quot;2023-05-30T00:00:00Z&quot;))).thenReturn(response);
// when
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId,
LocalDate.parse(&quot;2023-05-12&quot;), LocalDate.parse(&quot;2023-05-29&quot;));
// then
assertThat(links).hasSize(3);
assertThat(links).extracting(LinkSummary::getUid).containsExactly(&quot;ap_789&quot;, &quot;ap_456&quot;, &quot;ap_123&quot;);
}</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 &#x27;should get post links by dates - exception&#x27;() {
given:
Long organizationId = 123
Long workspaceId = 456
when:
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId, LocalDate.parse(&#x27;2023-05-12&#x27;), LocalDate.parse(&#x27;2023-05-29&#x27;))
then:
1 * linkClient.getLinksByCreationTime(organizationId, workspaceId, Instant.parse(&#x27;2023-05-12T00:00:00Z&#x27;), Instant.parse(&#x27;2023-05-30T00:00:00Z&#x27;)) &gt;&gt; {
throw new HttpClientException(&#x27;time out&#x27;)
}
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(&quot;2023-05-12T00:00:00Z&quot;), Instant.parse(&quot;2023-05-30T00:00:00Z&quot;))).thenReturn(null);
// when
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId,
LocalDate.parse(&quot;2023-05-12&quot;), LocalDate.parse(&quot;2023-05-29&quot;));
// 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 &#x27;should find a post insight summary when a urn is provided&#x27;() {
given:
PostInsightSummary expectedPostInsightSummary = new PostInsightSummary(
serviceId: &#x27;1234&#x27;
)
List&lt;PostInsightSummary&gt; postInsightSummaries = [
expectedPostInsightSummary
]
AccountSummary account = new AccountSummary(
service: Service.linkedin
)
when:
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, &#x27;urn:li:share:1234&#x27;, 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(&quot;2023-05-12T00:00:00Z&quot;), Instant.parse(&quot;2023-05-30T00:00:00Z&quot;))).thenReturn(response);
// when
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId,
LocalDate.parse(&quot;2023-05-12&quot;), LocalDate.parse(&quot;2023-05-29&quot;));
// 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 &#x27;should find a post insight summary when a simple fb id is provided&#x27;() {
given:
PostInsightSummary expectedPostInsightSummary = new PostInsightSummary(
serviceId: &#x27;3456_1234&#x27;
)
List&lt;PostInsightSummary&gt; postInsightSummaries = [
expectedPostInsightSummary
]
AccountSummary account = new AccountSummary(
service: Service.facebook,
serviceId: &#x27;3456&#x27;
)
when:
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, &#x27;1234&#x27;, 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(&quot;2023-05-12T00:00:00Z&quot;), Instant.parse(&quot;2023-05-30T00:00:00Z&quot;)))
.thenThrow(new HttpClientException(&quot;time out&quot;));
// when
List&lt;LinkSummary&gt; links = service.getLinksByDates(organizationId, workspaceId,
LocalDate.parse(&quot;2023-05-12&quot;), LocalDate.parse(&quot;2023-05-29&quot;));
// 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 &#x27;should find a post insight summary when an id is provided&#x27;() {
given:
PostInsightSummary expectedPostInsightSummary = new PostInsightSummary(
serviceId: &#x27;1234&#x27;
)
List&lt;PostInsightSummary&gt; postInsightSummaries = [
expectedPostInsightSummary
]
AccountSummary account = new AccountSummary(
service: Service.instagram,
)
when:
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, &#x27;1234&#x27;, 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(&quot;1234&quot;);
List&lt;PostInsightSummary&gt; postInsightSummaries = List.of(expectedPostInsightSummary);
AccountSummary account = new AccountSummary();
account.setService(Service.linkedin);
// when
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(
postInsightSummaries, &quot;urn:li:share:1234&quot;, 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 &#x27;should not find a post insight summary when an id is unknown&#x27;() {
given:
PostInsightSummary expectedPostInsightSummary = null
List&lt;PostInsightSummary&gt; postInsightSummaries = [
new PostInsightSummary(
serviceId: &#x27;1234&#x27;
)
]
AccountSummary account = new AccountSummary(
service: Service.instagram,
)
when:
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(postInsightSummaries, &#x27;12345&#x27;, 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(&quot;3456_1234&quot;);
List&lt;PostInsightSummary&gt; postInsightSummaries = List.of(expectedPostInsightSummary);
AccountSummary account = new AccountSummary();
account.setService(Service.facebook);
account.setServiceId(&quot;3456&quot;);
// when
PostInsightSummary actualPostInsightSummary = service.getPostInsightSummaryFromLink(
postInsightSummaries, &quot;1234&quot;, 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