Skip to content

Commit 84d08f0

Browse files
committed
added scope before class definition in Test classes & removed duplicate dependency from pom.xml & added required one
1 parent 5e3c951 commit 84d08f0

File tree

13 files changed

+93
-117
lines changed

13 files changed

+93
-117
lines changed

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import org.springframework.boot.autoconfigure.SpringBootApplication;
3030
import org.springframework.scheduling.annotation.EnableScheduling;
3131

32-
/**
33-
* Polling-Publisher pattern paradigm.
34-
*/
32+
/** Polling-Publisher pattern paradigm. */
3533
@SpringBootApplication
3634
@EnableScheduling
3735
public class App {

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java

+6-20
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,13 @@
3030
import javax.annotation.PostConstruct;
3131
import org.springframework.stereotype.Repository;
3232

33-
34-
/**
35-
* Data repository to keep or store data.
36-
*/
33+
/** Data repository to keep or store data. */
3734
@Repository
3835
public class DataRepository {
3936

4037
private final Map<Integer, String> dataStorage = new HashMap<>();
4138

42-
/**
43-
* init after map creation ... to put dummy data.
44-
*/
39+
/** init after map creation ... to put dummy data. */
4540
@PostConstruct
4641
public void init() {
4742
// Injecting dummy data at startup
@@ -50,31 +45,22 @@ public void init() {
5045
dataStorage.put(4, "Initial Dummy Data - four - 4");
5146
}
5247

53-
54-
/**
55-
* Save data to the repository.
56-
*/
48+
/** Save data to the repository. */
5749
public void save(int id, String value) {
5850
dataStorage.put(id, value);
5951
}
6052

61-
/**
62-
* Retrieve data by ID.
63-
*/
53+
/** Retrieve data by ID. */
6454
public String findById(int id) {
6555
return dataStorage.getOrDefault(id, "Data not found");
6656
}
6757

68-
/**
69-
* Delete data by ID.
70-
*/
58+
/** Delete data by ID. */
7159
public void delete(int id) {
7260
dataStorage.remove(id);
7361
}
7462

75-
/**
76-
* Get all data.
77-
*/
63+
/** Get all data. */
7864
public Map<Integer, String> findAll() {
7965
return dataStorage;
8066
}

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java

+19-23
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,38 @@
2525

2626
package com.iluwatar.polling;
2727

28-
import java.util.List;
2928
import java.util.Map;
3029
import java.util.Random;
3130
import org.springframework.stereotype.Service;
3231

33-
/**
34-
* This class is responsible for keep the events.
35-
*/
32+
/** This class is responsible for keep the events. */
3633
@Service
3734
public class DataSourceService {
3835

3936
private final DataRepository repository;
4037

41-
/**
42-
* Constructor & Scheduler to push random data.
43-
*/
38+
/** Constructor & Scheduler to push random data. */
4439
public DataSourceService(DataRepository repository) {
4540
this.repository = repository;
4641

4742
// Start a separate thread to add data every 3 seconds
48-
new Thread(() -> {
49-
Random random = new Random();
50-
while (true) {
51-
try {
52-
Thread.sleep(3000); // Add data every 3 seconds
53-
int id = random.nextInt(100); // Random ID
54-
String value = "Auto-Data-" + id;
55-
this.addData(id, value);
56-
System.out.println("🔵 Data Added: " + id + " -> " + value);
57-
} catch (InterruptedException e) {
58-
Thread.currentThread().interrupt();
59-
break;
60-
}
61-
}
62-
}).start();
63-
43+
new Thread(
44+
() -> {
45+
Random random = new Random();
46+
while (true) {
47+
try {
48+
Thread.sleep(3000); // Add data every 3 seconds
49+
int id = random.nextInt(100); // Random ID
50+
String value = "Auto-Data-" + id;
51+
this.addData(id, value);
52+
System.out.println("🔵 Data Added: " + id + " -> " + value);
53+
} catch (InterruptedException e) {
54+
Thread.currentThread().interrupt();
55+
break;
56+
}
57+
}
58+
})
59+
.start();
6460
}
6561

6662
public void addData(int id, String value) {

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@
2929
import org.springframework.kafka.core.KafkaTemplate;
3030
import org.springframework.stereotype.Component;
3131

32-
33-
/**
34-
* This class is responsible for sending messages to Kafka.
35-
*/
32+
/** This class is responsible for sending messages to Kafka. */
3633
@Component
3734
public class KafkaProducer {
3835

39-
@Autowired
40-
private final KafkaTemplate<String, String> kafkaTemplate;
36+
@Autowired private final KafkaTemplate<String, String> kafkaTemplate;
4137

4238
public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate) {
4339
this.kafkaTemplate = kafkaTemplate;
@@ -51,4 +47,4 @@ public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate) {
5147
public void sendMessage(String topic, String message) {
5248
kafkaTemplate.send(topic, message);
5349
}
54-
}
50+
}

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
import org.springframework.web.bind.annotation.RequestParam;
3232
import org.springframework.web.bind.annotation.RestController;
3333

34-
/**
35-
* This class is responsible for contolling polling tasks.
36-
*/
34+
/** This class is responsible for contolling polling tasks. */
3735
@RestController
3836
public class PollingController {
3937

@@ -42,13 +40,11 @@ public String healthCheck() {
4240
return "Polling Service is up and running!";
4341
}
4442

45-
46-
@Autowired
47-
private KafkaProducer kafkaProducer;
43+
@Autowired private KafkaProducer kafkaProducer;
4844

4945
@PostMapping("/send")
5046
public String sendMessage(@RequestParam("message") String message) {
5147
kafkaProducer.sendMessage("API", message);
5248
return "Message sent: " + message;
5349
}
54-
}
50+
}

Diff for: polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,15 @@
3030
import org.springframework.scheduling.annotation.Scheduled;
3131
import org.springframework.stereotype.Component;
3232

33-
/**
34-
* This class is responsible for scheduling polling tasks.
35-
*/
33+
/** This class is responsible for scheduling polling tasks. */
3634
@Component
3735
public class PollingScheduler {
3836

39-
@Autowired
40-
private DataSourceService dataSourceService;
37+
@Autowired private DataSourceService dataSourceService;
4138

42-
@Autowired
43-
private KafkaProducer kafkaProducer;
39+
@Autowired private KafkaProducer kafkaProducer;
4440

45-
/**
46-
* Scheduler for poll data on each 5 second.
47-
* */
41+
/** Scheduler for poll data on each 5 second. */
4842
@Scheduled(fixedRate = 5000) // Poll every 5 seconds
4943
public void pollDataSource() {
5044
int id = new Random().nextInt(100); // Pick a random ID
@@ -57,4 +51,4 @@ public void pollDataSource() {
5751
System.out.println("🔴 No Data Found for ID: " + id);
5852
}
5953
}
60-
}
54+
}

Diff for: polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@
2424
*/
2525
package com.iluwatar.polling;
2626

27-
import org.junit.jupiter.api.Disabled;
27+
import static org.junit.jupiter.api.Assertions.*;
28+
2829
import org.junit.jupiter.api.Test;
2930
import org.springframework.boot.test.context.SpringBootTest;
3031

31-
import static org.junit.jupiter.api.Assertions.*;
32-
3332
@SpringBootTest
3433
public class AppTest {
3534

3635
@Test
3736
void polling() {
38-
assertDoesNotThrow(() -> App.main(new String[]{}));
37+
assertDoesNotThrow(() -> App.main(new String[] {}));
3938
}
4039
}

Diff for: polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
*/
2525
package com.iluwatar.polling;
2626

27-
import org.junit.jupiter.api.BeforeEach;
28-
import org.junit.jupiter.api.Test;
29-
3027
import static org.junit.jupiter.api.Assertions.*;
3128

3229
import java.util.Map;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3332

34-
class DataRepositoryTest {
33+
public class DataRepositoryTest {
3534

3635
private DataRepository repository;
3736

Diff for: polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataSourceServiceTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
package com.iluwatar.polling;
2727

28-
import org.junit.jupiter.api.*;
29-
import java.util.Map;
30-
3128
import static org.junit.jupiter.api.Assertions.*;
3229

33-
class DataSourceServiceTest {
30+
import java.util.Map;
31+
import org.junit.jupiter.api.*;
32+
33+
public class DataSourceServiceTest {
3434

3535
private DataRepository repository;
3636
private DataSourceService service;
@@ -63,8 +63,8 @@ void testRemoveData() {
6363

6464
service.removeData(2);
6565

66-
assertEquals("Data not found", repository.findById(2), "Deleted data should not be retrievable.");
67-
66+
assertEquals(
67+
"Data not found", repository.findById(2), "Deleted data should not be retrievable.");
6868
}
6969

7070
@Test

Diff for: polling-publisher/pom.xml

+37-20
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,30 @@
4343

4444
<properties>
4545
<java.version>21</java.version>
46-
<spring.boot.version>3.2.2</spring.boot.version>
46+
<spring.boot.version>3.4.4</spring.boot.version>
4747
</properties>
4848

4949
<dependencies>
5050
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
51-
<dependency>
52-
<groupId>org.junit.jupiter</groupId>
53-
<artifactId>junit-jupiter-api</artifactId>
54-
<version>5.10.1</version>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.junit.jupiter</groupId>
59-
<artifactId>junit-jupiter-engine</artifactId>
60-
<version>5.9.2</version>
61-
<scope>test</scope>
62-
</dependency>
63-
<dependency>
64-
<groupId>org.springframework.boot</groupId>
65-
<artifactId>spring-boot-dependencies</artifactId>
66-
<version>${spring.boot.version}</version>
67-
<type>pom</type>
68-
<scope>import</scope>
69-
</dependency>
51+
<!-- <dependency>-->
52+
<!-- <groupId>org.junit.jupiter</groupId>-->
53+
<!-- <artifactId>junit-jupiter-api</artifactId>-->
54+
<!-- <version>5.10.1</version>-->
55+
<!-- <scope>test</scope>-->
56+
<!-- </dependency>-->
57+
<!-- <dependency>-->
58+
<!-- <groupId>org.junit.jupiter</groupId>-->
59+
<!-- <artifactId>junit-jupiter-engine</artifactId>-->
60+
<!-- <version>5.9.2</version>-->
61+
<!-- <scope>test</scope>-->
62+
<!-- </dependency>-->
63+
<!-- <dependency>-->
64+
<!-- <groupId>org.springframework.boot</groupId>-->
65+
<!-- <artifactId>spring-boot-dependencies</artifactId>-->
66+
<!-- <version>${spring.boot.version}</version>-->
67+
<!-- <type>pom</type>-->
68+
<!-- <scope>import</scope>-->
69+
<!-- </dependency>-->
7070
<dependency>
7171
<groupId>org.springframework.boot</groupId>
7272
<artifactId>spring-boot-starter-web</artifactId>
@@ -127,6 +127,18 @@
127127
<version>1.3.2</version>
128128
</dependency>
129129

130+
<dependency>
131+
<groupId>ch.qos.logback</groupId>
132+
<artifactId>logback-core</artifactId>
133+
<version>1.5.18</version>
134+
</dependency>
135+
<dependency>
136+
<groupId>ch.qos.logback</groupId>
137+
<artifactId>logback-classic</artifactId>
138+
<version>1.5.18</version>
139+
</dependency>
140+
141+
130142

131143
</dependencies>
132144

@@ -143,6 +155,11 @@
143155
<target>21</target>
144156
</configuration>
145157
</plugin>
158+
<plugin>
159+
<groupId>org.apache.maven.plugins</groupId>
160+
<artifactId>maven-surefire-plugin</artifactId>
161+
<version>2.22.2</version>
162+
</plugin>
146163
</plugins>
147164
</pluginManagement>
148165
</build>

Diff for: polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/App.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
import org.springframework.boot.SpringApplication;
2929
import org.springframework.boot.autoconfigure.SpringBootApplication;
3030

31-
/**
32-
* Polling-Publisher pattern paradigm.
33-
*/
31+
/** Polling-Publisher pattern paradigm. */
3432
@SpringBootApplication
3533
public class App {
3634
public static void main(String[] args) {
3735
SpringApplication.run(App.class, args);
3836
}
3937
}
40-

Diff for: polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/KafkaConsumer.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727

2828
import org.springframework.kafka.annotation.KafkaListener;
2929
import org.springframework.stereotype.Service;
30-
/**
31-
* Kafka consumer service to consume messages / updates.
32-
* */
30+
31+
/** Kafka consumer service to consume messages / updates. */
3332
@Service
3433
public class KafkaConsumer {
3534

@@ -42,4 +41,4 @@ public void listenUpdates(String message) {
4241
public void listenApi(String message) {
4342
System.out.println("[API]: Received message from /send : " + message);
4443
}
45-
}
44+
}

0 commit comments

Comments
 (0)