Created
February 12, 2026 09:07
-
-
Save musketyr/6860562f8f20d99f51fa01bd540d5060 to your computer and use it in GitHub Desktop.
Spock to JUnit 5 Migration: GoogleAnalyticsAccountSummaryFactorySpec (sc185908)
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: GoogleAnalyticsAccountSummaryFactorySpec</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: GoogleAnalyticsAccountSummaryFactorySpec</h1> | |
| <p style="text-align: center; color: #666; margin-bottom: 20px;">Story: <a href="https://app.shortcut.com/agorapulse/story/185908">sc185908</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.accountmanagement.admin | |
| import agorapulse.roi.service.google.client.connect.api.GoogleAnalyticsAccountSummary | |
| import agorapulse.roi.service.google.client.connect.api.GoogleAnalyticsProfileSummary | |
| import spock.lang.Specification</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>package agorapulse.roi.service.google.client.accountmanagement.admin; | |
| import agorapulse.roi.service.google.client.connect.api.GoogleAnalyticsAccountSummary; | |
| import agorapulse.roi.service.google.client.connect.api.GoogleAnalyticsProfileSummary; | |
| 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 imports with JUnit 5 + AssertJ. Added List import and static assertThat import. Removed spock.lang.Specification.</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 GoogleAnalyticsAccountSummaryFactorySpec extends Specification {</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>class GoogleAnalyticsAccountSummaryFactoryTest {</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Removed "extends Specification". Renamed Spec → Test. No mocks needed - factory class uses static methods only.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Test 1 - make list of GoogleAnalyticsAccountSummary --> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 make list of GoogleAnalyticsAccountSummary</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 'make list of GoogleAnalyticsAccountSummary'() { | |
| given: | |
| GoogleAnalyticsAdminApiResponse response = new GoogleAnalyticsAdminApiResponse(accountSummaries: [ | |
| new GoogleAnalyticsAdminApiResponse.Account( | |
| account: '123456789', | |
| displayName: 'Account 1', | |
| propertySummaries: [ | |
| new GoogleAnalyticsAdminApiResponse.Property( | |
| property: 'UA-123456789-1', | |
| displayName: 'Property 1' | |
| ), | |
| new GoogleAnalyticsAdminApiResponse.Property( | |
| property: 'UA-123456789-2', | |
| displayName: 'Property 2' | |
| ) | |
| ] | |
| ) | |
| ]) | |
| when: | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(response) | |
| then: | |
| result == [ | |
| new GoogleAnalyticsAccountSummary( | |
| id: '123456789', | |
| name: 'Account 1', | |
| ga4Properties: [ | |
| new GoogleAnalyticsProfileSummary('UA-123456789-1', 'Property 1', false), | |
| new GoogleAnalyticsProfileSummary('UA-123456789-2', 'Property 2', false) | |
| ] | |
| ) | |
| ] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@Test | |
| void make_list_of_GoogleAnalyticsAccountSummary() { | |
| // given | |
| GoogleAnalyticsAdminApiResponse.Property property1 = new GoogleAnalyticsAdminApiResponse.Property(); | |
| property1.setProperty("UA-123456789-1"); | |
| property1.setDisplayName("Property 1"); | |
| GoogleAnalyticsAdminApiResponse.Property property2 = new GoogleAnalyticsAdminApiResponse.Property(); | |
| property2.setProperty("UA-123456789-2"); | |
| property2.setDisplayName("Property 2"); | |
| GoogleAnalyticsAdminApiResponse.Account account = new GoogleAnalyticsAdminApiResponse.Account(); | |
| account.setAccount("123456789"); | |
| account.setDisplayName("Account 1"); | |
| account.setPropertySummaries(List.of(property1, property2)); | |
| GoogleAnalyticsAdminApiResponse response = new GoogleAnalyticsAdminApiResponse(); | |
| response.setAccountSummaries(List.of(account)); | |
| // when | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(response); | |
| // then | |
| assertThat(result).hasSize(1); | |
| GoogleAnalyticsAccountSummary accountSummary = result.get(0); | |
| assertThat(accountSummary.getId()).isEqualTo("123456789"); | |
| assertThat(accountSummary.getName()).isEqualTo("Account 1"); | |
| assertThat(accountSummary.getGa4Properties()).containsExactly( | |
| new GoogleAnalyticsProfileSummary("UA-123456789-1", "Property 1", false), | |
| new GoogleAnalyticsProfileSummary("UA-123456789-2", "Property 2", false) | |
| ); | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Added @Test annotation. Converted Groovy map constructor syntax to Java setters. Replaced Spock == assertion with AssertJ assertThat().hasSize(), isEqualTo(), containsExactly(). Converted given:/when:/then: blocks to // comments.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Test 2 - make list of GoogleAnalyticsAccountSummary - null --> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 make list of GoogleAnalyticsAccountSummary - null</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 'make list of GoogleAnalyticsAccountSummary - null'() { | |
| when: | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(null) | |
| then: | |
| result == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@Test | |
| void make_list_of_GoogleAnalyticsAccountSummary_null() { | |
| // when | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(null); | |
| // then | |
| assertThat(result).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Added @Test annotation. Converted Spock == [] to AssertJ assertThat().isEmpty(). Converted block labels to // comments.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Test 3 - make list of GoogleAnalyticsAccountSummary - response without summaries --> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 make list of GoogleAnalyticsAccountSummary - response without 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 'make list of GoogleAnalyticsAccountSummary - response without summaries'() { | |
| when: | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(new GoogleAnalyticsAdminApiResponse()) | |
| then: | |
| result == [] | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@Test | |
| void make_list_of_GoogleAnalyticsAccountSummary_response_without_summaries() { | |
| // when | |
| List<GoogleAnalyticsAccountSummary> result = GoogleAnalyticsAccountSummaryFactory.make(new GoogleAnalyticsAdminApiResponse()); | |
| // then | |
| assertThat(result).isEmpty(); | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Added @Test annotation. Converted Spock == [] to AssertJ assertThat().isEmpty(). Converted block labels to // comments.</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Section: Test 4 - getId --> | |
| <div class="section"> | |
| <div class="section-header" onclick="toggleSection(this)"> | |
| <h2>🧪 getId</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 'getId'() { | |
| when: | |
| String result = GoogleAnalyticsAccountSummaryFactory.getId('properties/123456789') | |
| then: | |
| result == '123456789' | |
| }</pre> | |
| </div> | |
| <div class="diff-panel right"> | |
| <h3>JUnit 5 (Java)</h3> | |
| <pre>@Test | |
| void getId() { | |
| // when | |
| String result = GoogleAnalyticsAccountSummaryFactory.getId("properties/123456789"); | |
| // then | |
| assertThat(result).isEqualTo("123456789"); | |
| }</pre> | |
| </div> | |
| </div> | |
| <div class="summary"> | |
| <p><strong>Changes:</strong> Added @Test annotation. Converted single quotes to double quotes. Replaced Spock == with AssertJ assertThat().isEqualTo(). Converted block labels to // comments.</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