From 5b116787d1fd0741ecbb8e0cab369bc692ee9100 Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Sat, 12 Sep 2020 15:56:21 +0200 Subject: [PATCH] "0 compilation error, no test was runned" --- 2020-2021/TD1.ucls | 50 ++++++++++---------- 2020-2021/src/TD1/Admin.java | 38 +++++++++------ 2020-2021/src/TD1/Forum.java | 66 ++++++++++++++++----------- 2020-2021/src/TD1/Member.java | 17 ++++--- 2020-2021/src/TD1/Message.java | 26 +++++++---- 2020-2021/src/TD1/MessageManager.java | 19 +++++--- 2020-2021/tests/TD1/ForumTest.java | 58 +++++++++++------------ 7 files changed, 160 insertions(+), 114 deletions(-) diff --git a/2020-2021/TD1.ucls b/2020-2021/TD1.ucls index ccb3c6e..1000fe7 100644 --- a/2020-2021/TD1.ucls +++ b/2020-2021/TD1.ucls @@ -3,7 +3,7 @@ associations="true" dependencies="false" nesting-relationships="true" router="FAN"> - + @@ -12,7 +12,7 @@ - + @@ -21,7 +21,7 @@ - + @@ -30,7 +30,7 @@ - + @@ -39,7 +39,7 @@ - + @@ -47,33 +47,37 @@ - - - - - - - - - - + + + + + + - - - - + + + + + + + + - + - + - - + + + + + + diff --git a/2020-2021/src/TD1/Admin.java b/2020-2021/src/TD1/Admin.java index ac203db..1946195 100644 --- a/2020-2021/src/TD1/Admin.java +++ b/2020-2021/src/TD1/Admin.java @@ -3,27 +3,39 @@ package TD1; public class Admin { private String nom; + private Forum forum; public Admin() { - this(null); + this(null, null); } - public Admin(String n) { - this.nom = n; - } - - // Operations + public Admin(String n, Forum f) { + this.setNom(n); + this.setForum(f); + } public void knowMembers() { - //TODO + System.out.println(this.forum.getMembers().toString()); + } + + public int knowMembersCount() { + return this.forum.getMembers().size(); } - public String getForum() { - return this.nom; - } - - public void setForum(String n) { - this.nom = n; + public Forum getForum() { + return this.forum; } + + public void setForum(Forum forum) { + this.forum = forum; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } } diff --git a/2020-2021/src/TD1/Forum.java b/2020-2021/src/TD1/Forum.java index d6523f0..3420967 100644 --- a/2020-2021/src/TD1/Forum.java +++ b/2020-2021/src/TD1/Forum.java @@ -1,42 +1,39 @@ package TD1; +import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class Forum { private String nom; private Admin admin; - private MessageManager messageManager; + private MessageManager mg; private List member = new ArrayList(); - - public Forum() { - this(null, null, null, null); - } + private List lmsg = new ArrayList(); - public Forum(String n) { - this(n, null, null, null); - } - - public Forum(String n,Admin a, MessageManager mg, List m) { + public Forum(String n, MessageManager msgManager) { this.setNom(n); - this.admin=a; - this.messageManager=mg; - this.member=m; + this.setMessageManager(msgManager); } - public void createMessage() { - // TODO - } - public void createMessageManager() { - // TODO - } - - public void createUser() { - // TODO + this.mg = new MessageManager(); } - public void addMember(Member m) { + public Message createMessage(String content, Member auth) { + return this.getMessageManager().createMessage(content, auth); + } + + public void addMessage(Message msg) { + this.getLmsg().add(msg); + } + + public void createUser(String name) { + this.addMember(new Member(name)); + } + + protected void addMember(Member m) { this.getMembers().add(m); } @@ -54,10 +51,12 @@ public class Forum { } public MessageManager getMessageManager() { - return this.messageManager; + return this.mg; + } + + private void setMessageManager(MessageManager msgManager) { + this.mg = msgManager; } - - // Operations public String getNom() { return nom; @@ -67,4 +66,19 @@ public class Forum { this.nom = nom; } + public List getLmsg() { + return this.lmsg; + } + + public List getLatestmsg(Member m) { + List l = new ArrayList(); + for (Message msg : this.getLmsg()) { + if(msg.getCreationDate().compareTo(Date.from(Instant.now() )) <= 10) { + l.add(msg); + } + } + m.lireMessage(l); + return l; + } + } diff --git a/2020-2021/src/TD1/Member.java b/2020-2021/src/TD1/Member.java index c411010..3116da2 100644 --- a/2020-2021/src/TD1/Member.java +++ b/2020-2021/src/TD1/Member.java @@ -23,16 +23,16 @@ public class Member { // Operations - public void envoyerMessage() { - // TODO + public void envoyerMessage(Message m) { + this.getMsg().add(m); } - public void effacerMessage() { - // TODO + public boolean effacerMessage(Message m) { + return this.nom.equalsIgnoreCase(m.getAuthor().getNom()); } - public void lireMessage() { - // TODO + public void lireMessage(List l) { + System.out.println(l.toString()); } public String getNom() { @@ -50,4 +50,9 @@ public class Member { public void setMsg(List msg) { this.msg = msg; } + + @Override + public String toString() { + return "Membre " + this.getNom() + "\n"; + } } diff --git a/2020-2021/src/TD1/Message.java b/2020-2021/src/TD1/Message.java index 23d249d..14a44e2 100644 --- a/2020-2021/src/TD1/Message.java +++ b/2020-2021/src/TD1/Message.java @@ -6,7 +6,7 @@ import java.util.Date; public class Message { private String content; - private Member destinator; + private Member author; private Date creationDate; public Message() { @@ -17,11 +17,17 @@ public class Message { this(c, null); } - public Message(String c, Member d) { + public Message(String c, Member a) { + //Un message a un contenu et un'e aut'eur'rice this.content = c; - this.setDestinator(d); + this.setAuthor(a); this.creationDate = Date.from(Instant.now()); } + + @Override + public String toString() { + return "Message de <<" + this.getAuthor() + ">> : " + this.getContent() + "\n"; + } public String getContent() { return this.content; @@ -39,11 +45,15 @@ public class Message { this.creationDate = creationDate; } - public Member getDestinator() { - return destinator; + public Member getAuthor() { + return this.author; } - public void setDestinator(Member destinator) { - this.destinator = destinator; - } + public void setAuthor(Member author) { + this.author = author; + } + + public boolean isOutOfDate(int t) { + return(this.getCreationDate().compareTo(Date.from(Instant.now())) <= t); + } } diff --git a/2020-2021/src/TD1/MessageManager.java b/2020-2021/src/TD1/MessageManager.java index 5b5b02a..36cc5e4 100644 --- a/2020-2021/src/TD1/MessageManager.java +++ b/2020-2021/src/TD1/MessageManager.java @@ -1,18 +1,23 @@ package TD1; public class MessageManager { - + public MessageManager() { - } - // Operations - public void createMessage() { - //TODO + public Message createMessage(String msg, Member auth) { + Message m = new Message(msg, auth); + auth.envoyerMessage(m); + return m; } - public void deleteMessage() { - //TODO + public boolean deleteMessage(Message msg, Member m) { + if(m.effacerMessage(msg)) { + msg = null; + return true; + } else { + return false; + } } public void posterMessage() { diff --git a/2020-2021/tests/TD1/ForumTest.java b/2020-2021/tests/TD1/ForumTest.java index e5c05c5..cb05338 100644 --- a/2020-2021/tests/TD1/ForumTest.java +++ b/2020-2021/tests/TD1/ForumTest.java @@ -2,82 +2,78 @@ package TD1; import static org.junit.jupiter.api.Assertions.*; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Test; -import fr.uca.iut.info.coo.td1.Forum; -import fr.uca.iut.info.coo.td1.Member; -import fr.uca.iut.info.coo.td1.Message; - class ForumTest { @Test void testMainScenario() throws InterruptedException { //L'agence “oogle-stade” (Administrateur) crée un forum “OGCN”. - Forum ogcn = new Forum("OGCN"); + Admin stade = new Admin("oogle-stade", new Forum("OGCN", new MessageManager())); + stade.getForum().setAdmin(stade); //Initialisation du Forum avec les membres Member mario = new Member("Mario"); Member walter = new Member("Walter"); Member alban = new Member("Alban"); - ogcn.addMember(mario); - ogcn.addMember(walter); - ogcn.addMember(alban); - List members = ogcn.getMembers(); + stade.getForum().addMember(mario); + stade.getForum().addMember(walter); + stade.getForum().addMember(alban); + List members = stade.getForum().getMembers(); assertEquals(3, members.size()); //Mario (Membre) poste un message WaitAndSee: “a quoi cela sert de courir?” sur le forum “OGCN”. - Message wait = new Message("a quoi cela sert de courir?", mario); - ogcn.addMessage(wait); - assertEquals(1, ogcn.getAllMessages().size()); + Message wait = stade.getForum().createMessage("a quoi cela sert de courir?", mario); + stade.getForum().addMessage(wait); + assertEquals(1, stade.getForum().getLmsg().size()); //Walter (Membre) demande s'il y a de nouvelles informations sur le forum et obtient le message WaitAndSee. //Il pose la même question un peu plus tard, et le système lui répond qu'il n'y a pas de nouveaux messages. //Walter demande à lire tous les messages. //Walter poste un message Yes : “Tout à fait d'accord!”. - List messages = ogcn.getNewMessages(walter); + List messages = stade.getForum().getLatestmsg(walter); assertTrue(messages.contains(wait)); - messages = ogcn.getNewMessages(walter); - assertEquals(0,messages.size()); - assertEquals(1, ogcn.getAllMessages().size()); - Message yes = new Message( "Tout à fait d'accord!", walter); - ogcn.addMessage(yes); + messages = stade.getForum().getLatestmsg(walter); + assertEquals(0, messages.size()); + assertEquals(1, stade.getForum().getLmsg().size()); + Message yes = stade.getForum().createMessage("Tout à fait d'accord!", walter); + stade.getForum().addMessage(yes); //Alban (Membre) demande s'il y a de nouveaux messages et obtient les messages WaitAndSee and Yes. - messages = ogcn.getNewMessages(alban); + messages = stade.getForum().getLatestmsg(alban); assertTrue(messages.contains(wait)); assertTrue(messages.contains(yes)); //Youcef s'inscrit sur le forum puis poste un message PFFF : “Vous rigolez?”. Member youcef = new Member("Youcef"); - ogcn.addMember(youcef); - Message pfff = new Message( "Vous rigolez?", youcef); - ogcn.addMessage(pfff); - messages = ogcn.getNewMessages(youcef); + stade.getForum().addMember(youcef); + Message pfff = stade.getForum().createMessage("Vous rigolez?", youcef); + stade.getForum().addMessage(pfff); + messages = stade.getForum().getLatestmsg(youcef); assertEquals(3, messages.size()); - messages = ogcn.getNewMessages(youcef); + messages = stade.getForum().getLatestmsg(youcef); assertEquals(0, messages.size()); //Walter demande à lire les nouveaux messages. - messages = ogcn.getNewMessages(walter); + messages = stade.getForum().getLatestmsg(walter); assertEquals(2, messages.size()); //Walter demande à effacer le message réalisé par Youcef, il n'a pas le droit, cela ne fait rien. - messages = ogcn.getAllMessages(); + messages = stade.getForum().getLmsg(); int numberOfMessages = messages.size(); - boolean removed = ogcn.remove(pfff, walter); + boolean removed = stade.getForum().getMessageManager().deleteMessage(pfff, walter); assertFalse(removed); - messages = ogcn.getAllMessages(); + messages = stade.getForum().getLmsg(); assertEquals(numberOfMessages,messages.size()); //Youcef efface son message - removed = ogcn.remove(pfff, youcef); + removed = stade.getForum().getMessageManager().deleteMessage(pfff, youcef); assertTrue(removed); - messages = ogcn.getAllMessages(); + messages = stade.getForum().getLmsg(); assertEquals(numberOfMessages-1,messages.size(),"le message a bien été effacé"); assertFalse(pfff.isOutOfDate(2));