Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save musketyr/024b09b1b60b7a95636d5a40e9cea7a8 to your computer and use it in GitHub Desktop.

Select an option

Save musketyr/024b09b1b60b7a95636d5a40e9cea7a8 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: RoiPostInsightSpec</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: RoiPostInsightSpec</h1>
<p style="text-align: center; color: #666; margin-bottom: 20px;">Story: <a href="https://app.shortcut.com/agorapulse/story/185898">sc185898</a> | PR: <a href="https://github.com/agorapulse/platform/pull/72987">#72987</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.model
import agorapulse.link.client.LinkSummary
import agorapulse.organization.client.model.AccountSummary
import agorapulse.report.client.PostInsightSummary
import agorapulse.report.client.insights.PostInsightAttachment
import agorapulse.roi.core.models.RoiContentAttachment
import agorapulse.service.client.api.Service
import spock.lang.Specification
import java.time.Instant
import java.time.LocalDateTime</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre>package agorapulse.roi.postinsight.model;
import agorapulse.link.client.LinkSummary;
import agorapulse.organization.client.model.AccountSummary;
import agorapulse.report.client.PostInsightSummary;
import agorapulse.report.client.insights.PostInsightAttachment;
import agorapulse.roi.core.models.RoiContentAttachment;
import agorapulse.service.client.api.Service;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;</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 RoiPostInsightSpec extends Specification {
</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre>class RoiPostInsightTest {
</pre>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-header" onclick="toggleSection(this)">
<h2>🧪 should fill insight - nulls</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 fill insight - nulls&#x27;() {
given:
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&#x27;ap_4f8erg34g&#x27;).build()
LinkSummary link = null
PostInsightSummary reportPostInsight = null
AccountSummary account = null
when:
roiPostInsight.fillInsight(link, reportPostInsight, account)
then:
roiPostInsight == RoiPostInsight.builder().linkUid(&#x27;ap_4f8erg34g&#x27;).attachment(new RoiContentAttachment()).build()
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldFillInsightWithNulls() {
// given
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&quot;ap_4f8erg34g&quot;).build();
LinkSummary link = null;
PostInsightSummary reportPostInsight = null;
AccountSummary account = null;
// when
roiPostInsight.fillInsight(link, reportPostInsight, account);
// then
RoiPostInsight expected = RoiPostInsight.builder()
.linkUid(&quot;ap_4f8erg34g&quot;)
.attachment(new RoiContentAttachment())
.build();
assertThat(roiPostInsight).isEqualTo(expected);
}</pre>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-header" onclick="toggleSection(this)">
<h2>🧪 should fill insight - no attachment</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 fill insight - no attachment&#x27;() {
given:
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&#x27;ap_4f8erg34g&#x27;).build()
LinkSummary link = new LinkSummary(uid: &#x27;ap_4f8erg34g&#x27;, accountUid: &#x27;facebook_3&#x27;, serviceId: &#x27;1654643534&#x27;, creationDate: LocalDateTime.of(2023, 1, 1, 10, 20))
PostInsightSummary reportPostInsight = new PostInsightSummary(message: &#x27;message&#x27;, publishingDate: Instant.parse(&#x27;2020-02-16T00:00:00Z&#x27;), tags: [&#x27;fun&#x27;])
AccountSummary account = new AccountSummary(name: &#x27;testName&#x27;, service: Service.facebook)
when:
roiPostInsight.fillInsight(link, reportPostInsight, account)
then:
roiPostInsight == RoiPostInsight.builder()
.linkUid(&#x27;ap_4f8erg34g&#x27;)
.accountName(&#x27;testName&#x27;)
.accountUid(&#x27;facebook_3&#x27;)
.attachment(new RoiContentAttachment())
.message(&#x27;message&#x27;)
.postId(&#x27;1654643534&#x27;)
.postType(null)
.publishingDate(Instant.parse(&#x27;2020-02-16T00:00:00Z&#x27;))
.service(Service.facebook)
.tags([&#x27;fun&#x27;])
.build()
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldFillInsightWithNoAttachment() {
// given
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&quot;ap_4f8erg34g&quot;).build();
LinkSummary link = new LinkSummary();
link.setUid(&quot;ap_4f8erg34g&quot;);
link.setAccountUid(&quot;facebook_3&quot;);
link.setServiceId(&quot;1654643534&quot;);
link.setCreationDate(LocalDateTime.of(2023, 1, 1, 10, 20));
PostInsightSummary reportPostInsight = new PostInsightSummary();
reportPostInsight.setMessage(&quot;message&quot;);
reportPostInsight.setPublishingDate(Instant.parse(&quot;2020-02-16T00:00:00Z&quot;));
reportPostInsight.setTags(List.of(&quot;fun&quot;));
AccountSummary account = new AccountSummary();
account.setName(&quot;testName&quot;);
account.setService(Service.facebook);
// when
roiPostInsight.fillInsight(link, reportPostInsight, account);
// then
RoiPostInsight expected = RoiPostInsight.builder()
.linkUid(&quot;ap_4f8erg34g&quot;)
.accountName(&quot;testName&quot;)
.accountUid(&quot;facebook_3&quot;)
.attachment(new RoiContentAttachment())
.message(&quot;message&quot;)
.postId(&quot;1654643534&quot;)
.postType(null)
.publishingDate(Instant.parse(&quot;2020-02-16T00:00:00Z&quot;))
.service(Service.facebook)
.tags(List.of(&quot;fun&quot;))
.build();
assertThat(roiPostInsight).isEqualTo(expected);
}</pre>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-header" onclick="toggleSection(this)">
<h2>🧪 should fill insight - carousel attachment</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 fill insight - carousel attachment&#x27;() {
given:
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&#x27;ap_4f8erg34g&#x27;).build()
LinkSummary link = new LinkSummary(uid: &#x27;ap_4f8erg34g&#x27;, accountUid: &#x27;facebook_3&#x27;, serviceId: &#x27;1654643534&#x27;, creationDate: LocalDateTime.of(2023, 1, 1, 10, 20))
PostInsightSummary reportPostInsight = new PostInsightSummary(
message: &#x27;message&#x27;,
carousel: true,
attachment: new PostInsightAttachment(multiAttachmentEnabled: true, type: &#x27;image&#x27;, url: &#x27;https://url.com&#x27;),
tags: [&#x27;fun&#x27;]
)
AccountSummary account = new AccountSummary(name: &#x27;testName&#x27;, service: Service.facebook)
when:
roiPostInsight.fillInsight(link, reportPostInsight, account)
then:
roiPostInsight == RoiPostInsight.builder()
.linkUid(&#x27;ap_4f8erg34g&#x27;)
.accountName(&#x27;testName&#x27;)
.accountUid(&#x27;facebook_3&#x27;)
.attachment(new RoiContentAttachment(multiAttachmentEnabled: true, type: &#x27;image&#x27;, url: &#x27;https://url.com&#x27;))
.message(&#x27;message&#x27;)
.postId(&#x27;1654643534&#x27;)
.postType(&#x27;carousel&#x27;)
.publishingDate(Instant.parse(&#x27;2023-01-01T10:20:00Z&#x27;))
.service(Service.facebook)
.tags([&#x27;fun&#x27;])
.build()
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldFillInsightWithCarouselAttachment() {
// given
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&quot;ap_4f8erg34g&quot;).build();
LinkSummary link = new LinkSummary();
link.setUid(&quot;ap_4f8erg34g&quot;);
link.setAccountUid(&quot;facebook_3&quot;);
link.setServiceId(&quot;1654643534&quot;);
link.setCreationDate(LocalDateTime.of(2023, 1, 1, 10, 20));
PostInsightAttachment attachment = new PostInsightAttachment();
attachment.setMultiAttachmentEnabled(true);
attachment.setType(&quot;image&quot;);
attachment.setUrl(&quot;https://url.com&quot;);
PostInsightSummary reportPostInsight = new PostInsightSummary();
reportPostInsight.setMessage(&quot;message&quot;);
reportPostInsight.setCarousel(true);
reportPostInsight.setAttachment(attachment);
reportPostInsight.setTags(List.of(&quot;fun&quot;));
AccountSummary account = new AccountSummary();
account.setName(&quot;testName&quot;);
account.setService(Service.facebook);
// when
roiPostInsight.fillInsight(link, reportPostInsight, account);
// then
RoiContentAttachment expectedAttachment = new RoiContentAttachment();
expectedAttachment.setMultiAttachmentEnabled(true);
expectedAttachment.setType(&quot;image&quot;);
expectedAttachment.setUrl(&quot;https://url.com&quot;);
RoiPostInsight expected = RoiPostInsight.builder()
.linkUid(&quot;ap_4f8erg34g&quot;)
.accountName(&quot;testName&quot;)
.accountUid(&quot;facebook_3&quot;)
.attachment(expectedAttachment)
.message(&quot;message&quot;)
.postId(&quot;1654643534&quot;)
.postType(&quot;carousel&quot;)
.publishingDate(Instant.parse(&quot;2023-01-01T10:20:00Z&quot;))
.service(Service.facebook)
.tags(List.of(&quot;fun&quot;))
.build();
assertThat(roiPostInsight).isEqualTo(expected);
}</pre>
</div>
</div>
</div>
</div>
<div class="section">
<div class="section-header" onclick="toggleSection(this)">
<h2>🧪 should fill insight - reel attachment</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 fill insight - reel attachment&#x27;() {
given:
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&#x27;ap_4f8erg34g&#x27;).build()
LinkSummary link = new LinkSummary(uid: &#x27;ap_4f8erg34g&#x27;, accountUid: &#x27;facebook_3&#x27;, serviceId: &#x27;1654643534&#x27;, creationDate: LocalDateTime.of(2023, 1, 1, 10, 20))
PostInsightSummary reportPostInsight = new PostInsightSummary(
message: &#x27;message&#x27;,
reel: true,
attachment: new PostInsightAttachment(multiAttachmentEnabled: false, type: &#x27;video&#x27;, url: &#x27;https://url.com&#x27;),
tags: [&#x27;fun&#x27;]
)
AccountSummary account = new AccountSummary(name: &#x27;testName&#x27;, service: Service.facebook)
when:
roiPostInsight.fillInsight(link, reportPostInsight, account)
then:
roiPostInsight == RoiPostInsight.builder()
.linkUid(&#x27;ap_4f8erg34g&#x27;)
.accountName(&#x27;testName&#x27;)
.accountUid(&#x27;facebook_3&#x27;)
.attachment(new RoiContentAttachment(multiAttachmentEnabled: false, type: &#x27;video&#x27;, url: &#x27;https://url.com&#x27;))
.message(&#x27;message&#x27;)
.postId(&#x27;1654643534&#x27;)
.postType(&#x27;reel&#x27;)
.publishingDate(Instant.parse(&#x27;2023-01-01T10:20:00Z&#x27;))
.service(Service.facebook)
.tags([&#x27;fun&#x27;])
.build()
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre> @Test
void shouldFillInsightWithReelAttachment() {
// given
RoiPostInsight roiPostInsight = RoiPostInsight.builder().linkUid(&quot;ap_4f8erg34g&quot;).build();
LinkSummary link = new LinkSummary();
link.setUid(&quot;ap_4f8erg34g&quot;);
link.setAccountUid(&quot;facebook_3&quot;);
link.setServiceId(&quot;1654643534&quot;);
link.setCreationDate(LocalDateTime.of(2023, 1, 1, 10, 20));
PostInsightAttachment attachment = new PostInsightAttachment();
attachment.setMultiAttachmentEnabled(false);
attachment.setType(&quot;video&quot;);
attachment.setUrl(&quot;https://url.com&quot;);
PostInsightSummary reportPostInsight = new PostInsightSummary();
reportPostInsight.setMessage(&quot;message&quot;);
reportPostInsight.setReel(true);
reportPostInsight.setAttachment(attachment);
reportPostInsight.setTags(List.of(&quot;fun&quot;));
AccountSummary account = new AccountSummary();
account.setName(&quot;testName&quot;);
account.setService(Service.facebook);
// when
roiPostInsight.fillInsight(link, reportPostInsight, account);
// then
RoiContentAttachment expectedAttachment = new RoiContentAttachment();
expectedAttachment.setMultiAttachmentEnabled(false);
expectedAttachment.setType(&quot;video&quot;);
expectedAttachment.setUrl(&quot;https://url.com&quot;);
RoiPostInsight expected = RoiPostInsight.builder()
.linkUid(&quot;ap_4f8erg34g&quot;)
.accountName(&quot;testName&quot;)
.accountUid(&quot;facebook_3&quot;)
.attachment(expectedAttachment)
.message(&quot;message&quot;)
.postId(&quot;1654643534&quot;)
.postType(&quot;reel&quot;)
.publishingDate(Instant.parse(&quot;2023-01-01T10:20:00Z&quot;))
.service(Service.facebook)
.tags(List.of(&quot;fun&quot;))
.build();
assertThat(roiPostInsight).isEqualTo(expected);
}</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