Skip to content

Commit

Permalink
Merge pull request #18 from ZenoxTek/feature/build_main
Browse files Browse the repository at this point in the history
feat: Create main. Build Jar
  • Loading branch information
imerzi authored Nov 30, 2019
2 parents 3d72855 + f0e0cf9 commit 3d89eb2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jacocoTestReport {
}
}

jar {
manifest {
attributes 'Main-Class': 'Main'
}
}

group 'org.example'
version '1.0-SNAPSHOT'
version '1.0'

mainClassName = 'Main'
archivesBaseName = 'chatbot'

sourceCompatibility = 1.8

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ private boolean parseMessage(String message) {
if (message.equals("@hello")) {
this.botName = "hello";
this.formatResponse();
return true;
System.out.println(getResponse());
return false;
}
return false;
return message.equals("++");
}
}
8 changes: 4 additions & 4 deletions src/main/java/ChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ 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();
}

private boolean logic(BufferedReader reader) throws IOException {
user.displayUserName();
String command = reader.readLine();
user.getUserMessage(command);
if (bot.receiveMessage(command)) {
System.out.println(bot.getResponse());
user.sayByeToBot();
return false;
}
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ public class Main {

public static void main(String[] args) throws IOException {
// TODO: Parse string
Parser parser = new Parser(args);
if (!parser.parse()) {
return;
}
ChatRoom chatRoom = new ChatRoom();
chatRoom.setUserName("Toto");
chatRoom.setUserName(parser.getArgumentsAtIndex(0));
chatRoom.initialize();
}
}
15 changes: 8 additions & 7 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,18 +16,7 @@ public String getUserName() {
return this.username;
}

public void getUserMessage(String msg) {
System.out.println(msg);
}

public void displayUserName() {
System.out.print("[" + this.username + "] ");
}

public void sayByeToBot() {
displayUserName();
System.out.println(SAY_FOO);
displayUserName();
System.out.println(EXIT);
}
}
4 changes: 2 additions & 2 deletions src/test/java/BotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public void receiveMessage() {
Bot bot = new Bot();
bot.setUserName("Toto");

assertTrue(bot.receiveMessage("@hello"));
assertTrue(bot.receiveMessage("++"));
}

@Test
public void receiveWrongMessage() {
Bot bot = new Bot();
bot.setUserName("Toto");

assertFalse(bot.receiveMessage("@bonjour"));
assertFalse(bot.receiveMessage("@hello"));
}

@Test
Expand Down

0 comments on commit 3d89eb2

Please sign in to comment.