mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-05 02:19:47 +00:00
feat: Add Service Stub Pattern using Sentiment Analysis example (#3215)
* Add Service Stub Pattern using Sentiment Analysis example * Fix Checkstyle issues * Suppress Sonar warning for Random usage in RealSentimentAnalysisServer
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.iluwatar.servicestub;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
public class AppTest {
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.iluwatar.servicestub;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class RealSentimentAnalysisServerTest {
|
||||
|
||||
@Test
|
||||
void testPositiveSentiment() {
|
||||
RealSentimentAnalysisServer server = new RealSentimentAnalysisServer(() -> 0);
|
||||
assertEquals("Positive", server.analyzeSentiment("Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeSentiment() {
|
||||
RealSentimentAnalysisServer server = new RealSentimentAnalysisServer(() -> 1);
|
||||
assertEquals("Negative", server.analyzeSentiment("Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNeutralSentiment() {
|
||||
RealSentimentAnalysisServer server = new RealSentimentAnalysisServer(() -> 2);
|
||||
assertEquals("Neutral", server.analyzeSentiment("Test"));
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.iluwatar.servicestub;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class StubSentimentAnalysisServerTest {
|
||||
|
||||
private final StubSentimentAnalysisServer stub = new StubSentimentAnalysisServer();
|
||||
|
||||
@Test
|
||||
void testPositiveSentiment() {
|
||||
String result = stub.analyzeSentiment("This is a good product");
|
||||
assertEquals("Positive", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegativeSentiment() {
|
||||
String result = stub.analyzeSentiment("This is a bad product");
|
||||
assertEquals("Negative", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNeutralSentiment() {
|
||||
String result = stub.analyzeSentiment("This product is average");
|
||||
assertEquals("Neutral", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user