Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save musketyr/09a6d871a0f9c03466030cc9e964156a to your computer and use it in GitHub Desktop.

Select an option

Save musketyr/09a6d871a0f9c03466030cc9e964156a to your computer and use it in GitHub Desktop.
Spock → JUnit 5 Migration Diff: RoiContentMetricsSpec (sc185901)
<!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: RoiContentMetricsSpec</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: RoiContentMetricsSpec</h1>
<p style="text-align: center; color: #666; margin-bottom: 20px;">Story: <a href="https://app.shortcut.com/agorapulse/story/185901">sc185901</a> | PR: <a href="https://github.com/agorapulse/platform/pull/73544">#73544</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.analytics.model
import agorapulse.roi.core.models.RoiKeyPerformanceMetrics
import spock.lang.Specification</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre>package agorapulse.roi.service.google.client.analytics.model;
import agorapulse.roi.core.models.RoiKeyPerformanceMetrics;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;</pre>
</div>
</div>
<div class="summary">
<p><strong>Changes:</strong> Replaced Spock Specification import with JUnit 5 @Test. Added AssertJ for assertions. Added BigDecimal import for explicit type usage in Java.</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 RoiContentMetricsSpec extends Specification {
// No fields - simple spec
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre>class RoiContentMetricsTest {
// No fields - simple test class
}</pre>
</div>
</div>
<div class="summary">
<p><strong>Changes:</strong> Renamed Spec → Test. Removed Specification inheritance (JUnit uses annotations instead).</p>
</div>
</div>
</div>
<!-- Section: Test 1 - should increase metrics -->
<div class="section">
<div class="section-header" onclick="toggleSection(this)">
<h2>🧪 should increase metrics</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 increase metrics'() {
given:
RoiKeyPerformanceMetrics metrics = RoiKeyPerformanceMetrics.builder()
.visitorCount(1)
.visitorRatio(1.0)
.conversionTransactionsCount(1)
.conversionTransactionsRatio(1.0)
.conversionGoalCount(1)
.conversionGoalRatio(1.0)
.generatedRevenueTransactionsCount(1.0)
.generatedRevenueTransactionsRatio(1.0)
.generatedRevenueGoalCount(1.0)
.generatedRevenueGoalRatio(1.0)
.build()
RoiContentMetrics contentMetrics = RoiContentMetrics.builder()
.visitorCount(1)
.visitorRatio(BigDecimal.ONE)
.conversionTransactionsCount(1)
.conversionTransactionsRatio(BigDecimal.ONE)
.conversionGoalCount(1)
.conversionGoalRatio(BigDecimal.ONE)
.generatedRevenueTransactionsCount(BigDecimal.ONE)
.generatedRevenueTransactionsRatio(BigDecimal.ONE)
.generatedRevenueGoalCount(BigDecimal.ONE)
.generatedRevenueGoalRatio(BigDecimal.ONE)
.build()
when:
contentMetrics.increaseMetrics(metrics)
then:
contentMetrics == RoiContentMetrics.builder()
.visitorCount(2)
.visitorRatio(2.0)
.conversionTransactionsCount(2)
.conversionTransactionsRatio(2.0)
.conversionGoalCount(2)
.conversionGoalRatio(2.0)
.generatedRevenueTransactionsCount(2.0)
.generatedRevenueTransactionsRatio(2.0)
.generatedRevenueGoalCount(2.0)
.generatedRevenueGoalRatio(2.0)
.build()
}</pre>
</div>
<div class="diff-panel right">
<h3>JUnit 5 (Java)</h3>
<pre>@Test
void shouldIncreaseMetrics() {
// given
RoiKeyPerformanceMetrics metrics = RoiKeyPerformanceMetrics.builder()
.visitorCount(1)
.visitorRatio(1.0)
.conversionTransactionsCount(1)
.conversionTransactionsRatio(1.0)
.conversionGoalCount(1)
.conversionGoalRatio(1.0)
.generatedRevenueTransactionsCount(1.0)
.generatedRevenueTransactionsRatio(1.0)
.generatedRevenueGoalCount(1.0)
.generatedRevenueGoalRatio(1.0)
.build();
RoiContentMetrics contentMetrics = RoiContentMetrics.builder()
.visitorCount(1)
.visitorRatio(BigDecimal.ONE)
.conversionTransactionsCount(1)
.conversionTransactionsRatio(BigDecimal.ONE)
.conversionGoalCount(1)
.conversionGoalRatio(BigDecimal.ONE)
.generatedRevenueTransactionsCount(BigDecimal.ONE)
.generatedRevenueTransactionsRatio(BigDecimal.ONE)
.generatedRevenueGoalCount(BigDecimal.ONE)
.generatedRevenueGoalRatio(BigDecimal.ONE)
.build();
// when
contentMetrics.increaseMetrics(metrics);
// then
RoiContentMetrics expected = RoiContentMetrics.builder()
.visitorCount(2)
.visitorRatio(BigDecimal.valueOf(2.0))
.conversionTransactionsCount(2)
.conversionTransactionsRatio(BigDecimal.valueOf(2.0))
.conversionGoalCount(2)
.conversionGoalRatio(BigDecimal.valueOf(2.0))
.generatedRevenueTransactionsCount(BigDecimal.valueOf(2.0))
.generatedRevenueTransactionsRatio(BigDecimal.valueOf(2.0))
.generatedRevenueGoalCount(BigDecimal.valueOf(2.0))
.generatedRevenueGoalRatio(BigDecimal.valueOf(2.0))
.build();
assertThat(contentMetrics).isEqualTo(expected);
}</pre>
</div>
</div>
<div class="summary">
<p><strong>Changes:</strong> Added @Test annotation. Method name changed to camelCase (shouldIncreaseMetrics). Spock given/when/then blocks → comments. Added semicolons. Used BigDecimal.valueOf() explicitly for expected values. Replaced Spock == assertion with AssertJ assertThat().isEqualTo(). Extracted expected object to a local variable for clarity.</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