"0 compilation error, no test was runned"

This commit is contained in:
JunkJumper 2020-09-12 15:56:21 +02:00
parent ff85fa4e79
commit 5b116787d1
7 changed files with 160 additions and 114 deletions

View File

@ -3,7 +3,7 @@
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="TD1.Forum" project="M315" file="/M315/src/TD1/Forum.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="490" y="149"/>
<position height="-1" width="-1" x="461" y="178"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
@ -12,7 +12,7 @@
</class>
<class id="2" language="java" name="TD1.Admin" project="M315" file="/M315/src/TD1/Admin.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="242" y="421"/>
<position height="-1" width="-1" x="122" y="173"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
@ -21,7 +21,7 @@
</class>
<class id="3" language="java" name="TD1.Member" project="M315" file="/M315/src/TD1/Member.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="801" y="403"/>
<position height="-1" width="-1" x="817" y="162"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
@ -30,7 +30,7 @@
</class>
<class id="4" language="java" name="TD1.Message" project="M315" file="/M315/src/TD1/Message.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="504" y="471"/>
<position height="-1" width="-1" x="805" y="503"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
@ -39,7 +39,7 @@
</class>
<class id="5" language="java" name="TD1.MessageManager" project="M315" file="/M315/src/TD1/MessageManager.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="791" y="122"/>
<position height="-1" width="-1" x="480" y="543"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
@ -47,33 +47,37 @@
</display>
</class>
<association id="6">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="7" name="msg"/>
<multiplicity id="8" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="9">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="10" name="admin"/>
<multiplicity id="11" minimum="0" maximum="1"/>
<attribute id="7" name="admin">
<position height="0" width="0" x="-120" y="-248"/>
</attribute>
<multiplicity id="8" minimum="0" maximum="1">
<position height="0" width="0" x="-120" y="-248"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="12">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="13" name="messageManager"/>
<multiplicity id="14" minimum="0" maximum="1"/>
<association id="9">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="10" name="msg">
<position height="0" width="0" x="301" y="32"/>
</attribute>
<multiplicity id="11" minimum="0" maximum="2147483647">
<position height="0" width="0" x="301" y="32"/>
</multiplicity>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="15">
<association id="12">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="16" name="member"/>
<multiplicity id="17" minimum="0" maximum="2147483647"/>
<attribute id="13" name="member">
<position height="0" width="0" x="16" y="-241"/>
</attribute>
<multiplicity id="14" minimum="0" maximum="2147483647">
<position height="0" width="0" x="16" y="-241"/>
</multiplicity>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>

View File

@ -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;
public Admin(String n, Forum f) {
this.setNom(n);
this.setForum(f);
}
// Operations
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 Forum getForum() {
return this.forum;
}
public void setForum(String n) {
this.nom = n;
public void setForum(Forum forum) {
this.forum = forum;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
}

View File

@ -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> member = new ArrayList<Member>();
private List<Message> lmsg = new ArrayList<Message>();
public Forum() {
this(null, null, null, null);
}
public Forum(String n) {
this(n, null, null, null);
}
public Forum(String n,Admin a, MessageManager mg, List<Member> m) {
public Forum(String n, MessageManager msgManager) {
this.setNom(n);
this.admin=a;
this.messageManager=mg;
this.member=m;
}
public void createMessage() {
// TODO
this.setMessageManager(msgManager);
}
public void createMessageManager() {
// TODO
this.mg = new MessageManager();
}
public void createUser() {
// TODO
public Message createMessage(String content, Member auth) {
return this.getMessageManager().createMessage(content, auth);
}
public void addMember(Member m) {
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;
}
// Operations
private void setMessageManager(MessageManager msgManager) {
this.mg = msgManager;
}
public String getNom() {
return nom;
@ -67,4 +66,19 @@ public class Forum {
this.nom = nom;
}
public List<Message> getLmsg() {
return this.lmsg;
}
public List<Message> getLatestmsg(Member m) {
List<Message> l = new ArrayList<Message>();
for (Message msg : this.getLmsg()) {
if(msg.getCreationDate().compareTo(Date.from(Instant.now() )) <= 10) {
l.add(msg);
}
}
m.lireMessage(l);
return l;
}
}

View File

@ -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<Message> l) {
System.out.println(l.toString());
}
public String getNom() {
@ -50,4 +50,9 @@ public class Member {
public void setMsg(List<Message> msg) {
this.msg = msg;
}
@Override
public String toString() {
return "Membre " + this.getNom() + "\n";
}
}

View File

@ -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,12 +17,18 @@ 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);
}
}

View File

@ -3,16 +3,21 @@ 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() {

View File

@ -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<Member> members = ogcn.getMembers();
stade.getForum().addMember(mario);
stade.getForum().addMember(walter);
stade.getForum().addMember(alban);
List<Member> 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<Message> messages = ogcn.getNewMessages(walter);
List<Message> 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));