Created
March 3, 2026 13:52
-
-
Save musketyr/7bb67737265fe609456426e8de69c329 to your computer and use it in GitHub Desktop.
Spock to JUnit 5 Migration Diff - GoogleAnalyticsAccountSummarySpec (sc185905)
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: GoogleAnalyticsAccountSummarySpec</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; } | |
| .summary { background: #c6f6d5; border-left: 4px solid #38a169; padding: 12px 16px; margin: 0; } | |
| .summary p { color: #276749; font-size: 14px; } | |
| .summary strong { color: #22543d; } | |
| @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: GoogleAnalyticsAccountSummarySpec</h1> | |
| <p style="text-align: center; color: #666; margin-bottom: 20px;">Story: <a href="https://app.shortcut.com/agorapulse/story/185905">sc185905</a> | PR: <a href="https://github.com/agorapulse/platform/pull/73541">#73541</a></p> | |
| <!-- Section: Imports --> | |
| <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.service.google.client.connect.api | |
| import spock.lang.Specification</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>package agorapulse.roi.service.google.client.connect.api; | |
| import org.junit.jupiter.api.Test; | |
| import java.util.List; | |
| import static org.assertj.core.api.Assertions.assertThat;</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Replaced Spock's Specification import with JUnit 5 @Test and AssertJ assertThat. Added java.util.List import for immutable list creation.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Class & Fields --> | |
| <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 GoogleAnalyticsAccountSummarySpec extends Specification { | |
| // No fields | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>class GoogleAnalyticsAccountSummaryTest { | |
| // No fields - added helper method instead | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Removed extends Specification. Renamed from *Spec to *Test convention. Added private helper method createProfileSummary() for cleaner object construction.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Test - should filterGa4PropertiesByDashboardIds --> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 should filterGa4PropertiesByDashboardIds</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 filterGa4PropertiesByDashboardIds'() { | |
| given: | |
| GoogleAnalyticsAccountSummary summary = new GoogleAnalyticsAccountSummary( | |
| ga4Properties: [ | |
| new GoogleAnalyticsProfileSummary( | |
| name: 'ga4p1', | |
| id: '123' | |
| ), | |
| new GoogleAnalyticsProfileSummary( | |
| name: 'ga4p2', | |
| id: '456' | |
| ), | |
| new GoogleAnalyticsProfileSummary( | |
| name: 'ga4p3', | |
| id: '789' | |
| ) | |
| ] | |
| ) | |
| when: | |
| GoogleAnalyticsAccountSummary filtered = summary.filterGa4PropertiesByDashboardIds(['123', '789']) | |
| then: | |
| filtered.ga4Properties == [ | |
| new GoogleAnalyticsProfileSummary( | |
| name: 'ga4p1', | |
| id: '123' | |
| ), | |
| new GoogleAnalyticsProfileSummary( | |
| name: 'ga4p3', | |
| id: '789' | |
| ) | |
| ] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@Test | |
| void shouldFilterGa4PropertiesByDashboardIds() { | |
| // given | |
| GoogleAnalyticsAccountSummary summary = new GoogleAnalyticsAccountSummary(); | |
| summary.setGa4Properties(List.of( | |
| createProfileSummary("ga4p1", "123"), | |
| createProfileSummary("ga4p2", "456"), | |
| createProfileSummary("ga4p3", "789") | |
| )); | |
| // when | |
| GoogleAnalyticsAccountSummary filtered = summary.filterGa4PropertiesByDashboardIds(List.of("123", "789")); | |
| // then | |
| assertThat(filtered.getGa4Properties()) | |
| .hasSize(2) | |
| .extracting(GoogleAnalyticsProfileSummary::getId) | |
| .containsExactly("123", "789"); | |
| } | |
| private GoogleAnalyticsProfileSummary createProfileSummary(String name, String id) { | |
| GoogleAnalyticsProfileSummary profile = new GoogleAnalyticsProfileSummary(); | |
| profile.setName(name); | |
| profile.setId(id); | |
| return profile; | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Added @Test annotation. Replaced Groovy map-style constructor with setter methods via helper. Converted Groovy list literals to List.of(). Replaced Spock's == equality with AssertJ's fluent assertions (hasSize, extracting, containsExactly) for better error messages.</p> | |
| </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