Repository: iluwatar/java-design-patterns
Issue: SonarQube reports code smells
Labels: type: bug
info: good first issue

Java Design Patterns is analyzed with SonarQube.com static analysis. The analysis shows some blocker level code smells that should be fixed:

https://sonarqube.com/component_issues/index?id=com.iluwatar%3Ajava-design-patterns#resolved=false|severities=BLOCKER|types=CODE_SMELL


Issue comments:
I will take care of this.

Thank you @sangupta you're good to go!

@sangupta are you still working on this?
@iluwatar Am sorry - have been pressed for time lately. Will have sometime in March - when I should be able to lend a helping hand.

@iluwatar I can pick this if no one else is looking at it, to start with I could begin with dao. Is it okay?
@Praveer-grover this is ok, please go ahead.
Updated sonarqube url
https://sonarcloud.io/project/issues?id=com.iluwatar%3Ajava-design-patterns&resolved=false&severities=BLOCKER&types=CODE_SMELL

@Praveer-grover Are you still working on these issues? Let me know if you want me to share some modules?

Ping @Praveer-grover 
@mookkiah Are you planning to completely work on this ticket or you need a helping hand? ;)
Either way is fine for me. As @Praveer-grover is not responding, I will look at sonarqube reported issues in prototype module (maybe this weekend). @dosdebug, you are welcome to help another module. Please just comment so we don't step on each other.
@mookkiah I will be working on `dao` and `naked-objects-dom` then.
Hey @mookkiah and @dosdebug are you guys still working on this?
I will work on prototype module. 
@iluwatar No Sir, not working on this.
Ok @mookkiah I will keep the issue `under construction`
Note : 
The problem with the `dao` seems to be cause by the fact that SonarQube does not support `@Nested` : SQ currently ignores any `@Nested` classes, in other words it does not verify if there is a test within or not. 
There are still 4 blockers and 37 criticals. See https://sonarcloud.io/project/issues?id=com.iluwatar%3Ajava-design-patterns&resolved=false&severities=BLOCKER%2CCRITICAL&types=CODE_SMELL. This issue is free for taking, if someone would like to help.
Hm.... there is something strange here. I just opened one of the `Blockers` : https://sonarcloud.io/project/issues?id=com.iluwatar%3Ajava-design-patterns&open=AVfejjZoPl_GJI-SB0qL&resolved=false&severities=BLOCKER and although the analysis is run on `October 24, 2018, 10:43 PM Version 1.21.0-SNAPSHOT` SonarCloud is displaying outdated source code : from 2 years ago instead of the one fixed in #810....

Oh, actually #810 has been merged on `October 25` : a day later. I guess the analysis does not contain the changes done in #810 ( if I am to trust the timestamps of GitHub and SonarCloud ). I would guess the blockers will be fixed in the next analysis.

Just my 2c ;)

PS : This may explain the 4 blockers but the criticals still need to be fixed.
@iluwatar I will start working on this and raise a PR shortly.
Ok @IAmPramod 
@iluwatar  Is this available ?
@IAmPramod  Are you still working on this ?
Hi @iluwatar  : Pull request raised for this 

Pull request review comments:

Patch that resolved the issue:
diff --git a/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java b/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java
index 6e9138d3c518..820279bc058a 100644
--- a/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java
+++ b/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/App.java
@@ -60,7 +60,8 @@ public class App {
   /**
    * Program entry point.
    *
-   * @param args command line args
+   * @param args
+   *          command line args
    */
   public static void main(String[] args) {
     App app = new App();
@@ -150,56 +151,11 @@ public void runInteractiveMode() {
       option = s.nextInt();
 
       if (option == 1) {
-        s.nextLine();
-        LOGGER.info("Boil multiple eggs at once (A) or boil them one-by-one (S)?: ");
-        String eventType = s.nextLine();
-        LOGGER.info("How long should this egg be boiled for (in seconds)?: ");
-        int eventTime = s.nextInt();
-        if (eventType.equalsIgnoreCase("A")) {
-          try {
-            int eventId = eventManager.createAsync(eventTime);
-            eventManager.start(eventId);
-            LOGGER.info("Egg [{}] is being boiled.", eventId);
-          } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
-            LOGGER.error(e.getMessage());
-          }
-        } else if (eventType.equalsIgnoreCase("S")) {
-          try {
-            int eventId = eventManager.create(eventTime);
-            eventManager.start(eventId);
-            LOGGER.info("Egg [{}] is being boiled.", eventId);
-          } catch (MaxNumOfEventsAllowedException | InvalidOperationException | LongRunningEventException
-              | EventDoesNotExistException e) {
-            LOGGER.error(e.getMessage());
-          }
-        } else {
-          LOGGER.info("Unknown event type.");
-        }
+        processOption1(eventManager, s);
       } else if (option == 2) {
-        LOGGER.info("Which egg?: ");
-        int eventId = s.nextInt();
-        try {
-          eventManager.cancel(eventId);
-          LOGGER.info("Egg [{}] is removed from boiler.", eventId);
-        } catch (EventDoesNotExistException e) {
-          LOGGER.error(e.getMessage());
-        }
+        processOption2(eventManager, s);
       } else if (option == 3) {
-        s.nextLine();
-        LOGGER.info("Just one egg (O) OR all of them (A) ?: ");
-        String eggChoice = s.nextLine();
-
-        if (eggChoice.equalsIgnoreCase("O")) {
-          LOGGER.info("Which egg?: ");
-          int eventId = s.nextInt();
-          try {
-            eventManager.status(eventId);
-          } catch (EventDoesNotExistException e) {
-            LOGGER.error(e.getMessage());
-          }
-        } else if (eggChoice.equalsIgnoreCase("A")) {
-          eventManager.statusOfAllEvents();
-        }
+        processOption3(eventManager, s);
       } else if (option == 4) {
         eventManager.shutdown();
       }
@@ -208,4 +164,61 @@ public void runInteractiveMode() {
     s.close();
   }
 
+  private void processOption3(EventManager eventManager, Scanner s) {
+    s.nextLine();
+    LOGGER.info("Just one egg (O) OR all of them (A) ?: ");
+    String eggChoice = s.nextLine();
+
+    if (eggChoice.equalsIgnoreCase("O")) {
+      LOGGER.info("Which egg?: ");
+      int eventId = s.nextInt();
+      try {
+        eventManager.status(eventId);
+      } catch (EventDoesNotExistException e) {
+        LOGGER.error(e.getMessage());
+      }
+    } else if (eggChoice.equalsIgnoreCase("A")) {
+      eventManager.statusOfAllEvents();
+    }
+  }
+
+  private void processOption2(EventManager eventManager, Scanner s) {
+    LOGGER.info("Which egg?: ");
+    int eventId = s.nextInt();
+    try {
+      eventManager.cancel(eventId);
+      LOGGER.info("Egg [{}] is removed from boiler.", eventId);
+    } catch (EventDoesNotExistException e) {
+      LOGGER.error(e.getMessage());
+    }
+  }
+
+  private void processOption1(EventManager eventManager, Scanner s) {
+    s.nextLine();
+    LOGGER.info("Boil multiple eggs at once (A) or boil them one-by-one (S)?: ");
+    String eventType = s.nextLine();
+    LOGGER.info("How long should this egg be boiled for (in seconds)?: ");
+    int eventTime = s.nextInt();
+    if (eventType.equalsIgnoreCase("A")) {
+      try {
+        int eventId = eventManager.createAsync(eventTime);
+        eventManager.start(eventId);
+        LOGGER.info("Egg [{}] is being boiled.", eventId);
+      } catch (MaxNumOfEventsAllowedException | LongRunningEventException | EventDoesNotExistException e) {
+        LOGGER.error(e.getMessage());
+      }
+    } else if (eventType.equalsIgnoreCase("S")) {
+      try {
+        int eventId = eventManager.create(eventTime);
+        eventManager.start(eventId);
+        LOGGER.info("Egg [{}] is being boiled.", eventId);
+      } catch (MaxNumOfEventsAllowedException | InvalidOperationException | LongRunningEventException
+          | EventDoesNotExistException e) {
+        LOGGER.error(e.getMessage());
+      }
+    } else {
+      LOGGER.info("Unknown event type.");
+    }
+  }
+
 }
diff --git a/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java b/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java
index 729900620aa0..d54665bb21f5 100644
--- a/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java
+++ b/event-asynchronous/src/main/java/com/iluwatar/event/asynchronous/EventManager.java
@@ -39,6 +39,8 @@ public class EventManager implements ThreadCompleteListener {
   private int currentlyRunningSyncEvent = -1;
   private Random rand;
   private Map<Integer, Event> eventPool;
+  
+  private static final String DOES_NOT_EXIST = " does not exist.";
 
   /**
    * EventManager constructor.
@@ -112,7 +114,7 @@ private int createEvent(int eventTime, boolean isSynchronous)
    */
   public void start(int eventId) throws EventDoesNotExistException {
     if (!eventPool.containsKey(eventId)) {
-      throw new EventDoesNotExistException(eventId + " does not exist.");
+      throw new EventDoesNotExistException(eventId + DOES_NOT_EXIST);
     }
 
     eventPool.get(eventId).start();
@@ -126,7 +128,7 @@ public void start(int eventId) throws EventDoesNotExistException {
    */
   public void cancel(int eventId) throws EventDoesNotExistException {
     if (!eventPool.containsKey(eventId)) {
-      throw new EventDoesNotExistException(eventId + " does not exist.");
+      throw new EventDoesNotExistException(eventId + DOES_NOT_EXIST);
     }
 
     if (eventId == currentlyRunningSyncEvent) {
@@ -145,7 +147,7 @@ public void cancel(int eventId) throws EventDoesNotExistException {
    */
   public void status(int eventId) throws EventDoesNotExistException {
     if (!eventPool.containsKey(eventId)) {
-      throw new EventDoesNotExistException(eventId + " does not exist.");
+      throw new EventDoesNotExistException(eventId + DOES_NOT_EXIST);
     }
 
     eventPool.get(eventId).status();
diff --git a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Account.java b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Account.java
index d2e5f429b5d4..a8ba649eb602 100644
--- a/event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Account.java
+++ b/event-sourcing/src/main/java/com/iluwatar/event/sourcing/domain/Account.java
@@ -44,6 +44,8 @@ public class Account {
   private final int accountNo;
   private final String owner;
   private BigDecimal money;
+  
+  private static final String MSG = "Some external api for only realtime execution could be called here.";
 
   /**
    * Instantiates a new Account.
@@ -126,7 +128,7 @@ private void handleDeposit(BigDecimal money, boolean realTime) {
     depositMoney(money);
     AccountAggregate.putAccount(this);
     if (realTime) {
-      LOGGER.info("Some external api for only realtime execution could be called here.");
+      LOGGER.info(MSG);
     }
   }
 
@@ -138,7 +140,7 @@ private void handleWithdrawal(BigDecimal money, boolean realTime) {
     withdrawMoney(money);
     AccountAggregate.putAccount(this);
     if (realTime) {
-      LOGGER.info("Some external api for only realtime execution could be called here.");
+      LOGGER.info(MSG);
     }
   }
 
@@ -160,7 +162,7 @@ public void handleEvent(MoneyDepositEvent moneyDepositEvent) {
   public void handleEvent(AccountCreateEvent accountCreateEvent) {
     AccountAggregate.putAccount(this);
     if (accountCreateEvent.isRealTime()) {
-      LOGGER.info("Some external api for only realtime execution could be called here.");
+      LOGGER.info(MSG);
     }
   }
 


Test patch: