Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Service Stub Pattern using Sentiment Analysis example #3215

Merged
merged 3 commits into from
Mar 23, 2025

Conversation

johnklint81
Copy link
Contributor

This PR introduces the Service Stub Pattern, demonstrated through a Sentiment Analysis example.

  • Adds SentimentAnalysisServer interface.
  • Implements RealSentimentAnalysisServer, simulating random sentiment results with delay.
  • Implements StubSentimentAnalysisServer, providing predictable, input-based outputs.
  • Includes unit tests and full documentation.

Fixes #381.

Copy link

github-actions bot commented Mar 22, 2025

PR Summary

This PR introduces the Service Stub pattern, implemented with a Sentiment Analysis example. It includes a SentimentAnalysisServer interface, RealSentimentAnalysisServer (simulating random results with delay), and StubSentimentAnalysisServer (providing predictable outputs). Unit tests and documentation are also added.

Changes

File Summary
pom.xml The service-stub module was added to the project's modules.
service-stub/README.md This file contains a comprehensive guide to the Service Stub pattern, including its intent, real-world examples, implementation details, and usage scenarios. It also includes a detailed explanation of the Sentiment Analysis example used in this PR.
service-stub/pom.xml This file defines the dependencies and configurations for the service-stub module, including JUnit Jupiter for testing.
service-stub/src/main/java/com/iluwatar/servicestub/App.java This is the main application class that demonstrates the usage of both the real and stub implementations of the SentimentAnalysisServer.
service-stub/src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java Implements the SentimentAnalysisServer interface, simulating a real sentiment analysis service with a 5-second delay and random results. Uses a Supplier<Integer> for dependency injection in testing.
service-stub/src/main/java/com/iluwatar/servicestub/SentimentAnalysisServer.java Defines the interface SentimentAnalysisServer with a single method analyzeSentiment to analyze the sentiment of a given text.
service-stub/src/main/java/com/iluwatar/servicestub/StubSentimentAnalysisServer.java Implements the SentimentAnalysisServer interface, providing a stub implementation that returns a deterministic sentiment based on keywords in the input text.
service-stub/src/test/java/com/iluwatar/servicestub/AppTest.java This test class checks if the main application runs without throwing any exceptions.
service-stub/src/test/java/com/iluwatar/servicestub/RealSentimentAnalysisServerTest.java This test class contains unit tests for the RealSentimentAnalysisServer class, covering positive, negative, and neutral sentiment scenarios.
service-stub/src/test/java/com/iluwatar/servicestub/StubSentimentAnalysisServerTest.java This test class contains unit tests for the StubSentimentAnalysisServer class, covering positive, negative, and neutral sentiment scenarios.

autogenerated by presubmit.ai

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • 7c11cba: Add Service Stub Pattern using Sentiment Analysis example
Files Processed (10)
  • pom.xml (1 hunk)
  • service-stub/README.md (1 hunk)
  • service-stub/pom.xml (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/App.java (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/SentimentAnalysisServer.java (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/StubSentimentAnalysisServer.java (1 hunk)
  • service-stub/src/test/java/com/iluwatar/servicestub/AppTest.java (1 hunk)
  • service-stub/src/test/java/com/iluwatar/servicestub/RealSentimentAnalysisServerTest.java (1 hunk)
  • service-stub/src/test/java/com/iluwatar/servicestub/StubSentimentAnalysisServerTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
Files Processed (5)
  • service-stub/src/main/java/com/iluwatar/servicestub/App.java (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java (1 hunk)
  • service-stub/src/main/java/com/iluwatar/servicestub/StubSentimentAnalysisServer.java (1 hunk)
  • service-stub/src/test/java/com/iluwatar/servicestub/AppTest.java (1 hunk)
  • service-stub/src/test/java/com/iluwatar/servicestub/RealSentimentAnalysisServerTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
  • 9a1cccc: Suppress Sonar warning for Random usage in RealSentimentAnalysisServer
Files Processed (1)
  • service-stub/src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • service-stub/src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java [37-41]

    performance: "Improve latency simulation in RealSentimentAnalysisServer."

@iluwatar iluwatar merged commit adf5b62 into iluwatar:master Mar 23, 2025
2 checks passed
@iluwatar
Copy link
Owner

Looks good! Thank you for the contribution 🎉

@all-contributors please add @johnklint81 for code

Copy link
Contributor

@iluwatar

I've put up a pull request to add @johnklint81! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Service Stub pattern
2 participants