From f0e0cf97a96ebf42ef8851a425ca0519c1483d1e Mon Sep 17 00:00:00 2001 From: DUHIEU Benjamin Date: Sat, 30 Nov 2019 16:34:40 +0100 Subject: [PATCH] feat: Clean repo. Rename jar file. Refactor following checkstyle --- build.gradle | 1 + src/main/java/ChatRoom.java | 4 +++- src/main/java/Main.java | 5 +++-- src/main/java/Parser.java | 15 ++++++++------- src/main/java/User.java | 4 +++- src/test/java/BotTest.java | 4 ++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index c8ca6a3..776aa57 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ group 'org.example' version '1.0' mainClassName = 'Main' +archivesBaseName = 'chatbot' sourceCompatibility = 1.8 diff --git a/src/main/java/ChatRoom.java b/src/main/java/ChatRoom.java index 2244ba8..fc2cf75 100644 --- a/src/main/java/ChatRoom.java +++ b/src/main/java/ChatRoom.java @@ -21,7 +21,9 @@ public void setUserName(String name) { public void initialize() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - while (logic(reader)); + while (logic(reader)) { + + } reader.close(); } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 378b3c9..d7b69b8 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,8 +5,9 @@ public class Main { public static void main(String[] args) throws IOException { // TODO: Parse string Parser parser = new Parser(args); - if (!parser.parse()) - return ; + if (!parser.parse()) { + return; + } ChatRoom chatRoom = new ChatRoom(); chatRoom.setUserName(parser.getArgumentsAtIndex(0)); chatRoom.initialize(); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index ad9eea6..9205f7e 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -10,19 +10,20 @@ public class Parser { this.argumentsReceived = args; } - public String getArgumentsAtIndex(int index){ - if (this.argumentsToReturn != null){ - if (index < this.argumentsToReturn.size() && index >= 0){ + public String getArgumentsAtIndex(int index) { + if (this.argumentsToReturn != null) { + if (index < this.argumentsToReturn.size() && index >= 0) { return this.argumentsToReturn.get(index); } } return null; } - public boolean parse(){ - if (this.argumentsReceived != null){ - for (int i = 0 ; i < this.argumentsReceived.length ; i++){ - if (this.argumentsReceived[i].equals("-p") && i + 1 < this.argumentsReceived.length){ + public boolean parse() { + if (this.argumentsReceived != null) { + for (int i = 0; i < this.argumentsReceived.length; i++) { + if (this.argumentsReceived[i].equals("-p") + && i + 1 < this.argumentsReceived.length) { this.argumentsToReturn.add(this.argumentsReceived[i + 1]); return true; } diff --git a/src/main/java/User.java b/src/main/java/User.java index 7db89f7..503aa19 100644 --- a/src/main/java/User.java +++ b/src/main/java/User.java @@ -4,7 +4,9 @@ public class User { private static final String SAY_FOO = "foo"; private static final String EXIT = "++"; - public User() { } + public User() { + + } public void setUserName(String username) { this.username = username; diff --git a/src/test/java/BotTest.java b/src/test/java/BotTest.java index a7bb36f..0608147 100644 --- a/src/test/java/BotTest.java +++ b/src/test/java/BotTest.java @@ -33,7 +33,7 @@ public void receiveMessage() { Bot bot = new Bot(); bot.setUserName("Toto"); - assertTrue(bot.receiveMessage("@hello")); + assertTrue(bot.receiveMessage("++")); } @Test @@ -41,7 +41,7 @@ public void receiveWrongMessage() { Bot bot = new Bot(); bot.setUserName("Toto"); - assertFalse(bot.receiveMessage("@bonjour")); + assertFalse(bot.receiveMessage("@hello")); } @Test