Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lapr.project.model;
- import lapr.project.utils.StringUtil;
- import org.junit.Test;
- //import org.w3c.dom.Document;
- //import org.w3c.dom.Element;
- //import org.w3c.dom.Node;
- //
- //import javax.xml.parsers.DocumentBuilder;
- //import javax.xml.parsers.DocumentBuilderFactory;
- import java.util.ArrayList;
- import java.util.List;
- import org.junit.After;
- import org.junit.AfterClass;
- import static org.junit.Assert.*;
- import org.junit.Before;
- import org.junit.BeforeClass;
- public class ApplicationTest {
- private int boothArea = 10;
- private int invitesQuantity = 5;
- private EventCenter ec;
- User u1 = new User ("Rui", "Default", "rui@gmail.com", "Ab-12");
- User u2 = new User ("David", "Default", "dabide@gmail.com", "Ab-12");
- ParticipantRepresentant userMaker1 = new ParticipantRepresentant(u1);
- ParticipantRepresentant userMaker2 = new ParticipantRepresentant(u2);
- /**
- * StringUtil variable to access utils for Strings.
- */
- private StringUtil stringUtil = new StringUtil();
- @BeforeClass
- public static void setUpClass() throws Exception {
- }
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
- @Before
- public void setUp() throws Exception {
- }
- @After
- public void tearDown() throws Exception {
- }
- /**
- * Get OS independent line break.
- *
- * @return OS independent line break "%n".
- */
- private String getLineBreak() {
- if (stringUtil == null) {
- stringUtil = new StringUtil();
- }
- return stringUtil.getLineBreak();
- }
- @Test
- public void ensureAddKeywordIsWorking() throws Exception {
- List<Keyword> expectedKeywordList = new ArrayList<>();
- expectedKeywordList.add(new Keyword("Doors"));
- Application candidatura = new Application("MyCandidatura", new ArrayList<>());
- candidatura.addKeyword(new Keyword("Doors"));
- List<Keyword> resultList = candidatura.getKeywordList();
- assertArrayEquals(expectedKeywordList.toArray(), resultList.toArray());
- }
- // @Test
- // public void ensureXMLElementExportToStringIsValid() throws Exception
- // {
- // String expected = "<application>" + getLineBreak()
- // + "<description>MyApplication</description>" + getLineBreak()
- // + "<keywords>" + getLineBreak()
- // + "<keyword>" + getLineBreak()
- // + "<value>Doors</value>" + getLineBreak()
- // + "</keyword>" + getLineBreak()
- // + "<keyword>" + getLineBreak()
- // + "<value>Windows</value>" + getLineBreak()
- // + "</keyword>" + getLineBreak()
- // + "</keywords>" + getLineBreak()
- // + "</application>" + getLineBreak();
- //
- // List<Keyword> keywordList = new ArrayList<>();
- // keywordList.add(new Keyword("Doors"));
- // keywordList.add(new Keyword("Windows"));
- // Application application = new Application("MyApplication", keywordList);
- // String result = application.exportContentToString();
- // assertEquals(expected, result);
- // }
- //
- // @Test
- // public void ensureImportFromXMLElementNodeIsValid() throws Exception
- // {
- // List<Keyword> keywordList = new ArrayList<>();
- // keywordList.add(new Keyword("Doors"));
- // keywordList.add(new Keyword("Windows"));
- //
- // Application expected = new Application("MyApplication", keywordList);
- //
- // DocumentBuilderFactory factory
- // = DocumentBuilderFactory.newInstance();
- //
- // //Create document builder
- // DocumentBuilder builder = factory.newDocumentBuilder();
- //
- // //Obtain a new document
- // Document document = builder.newDocument();
- //
- // //Create root element
- // Element elementCandidatura = document.createElement("application");
- //
- // //Create a sub-element
- // Element elementDescription = document.createElement("description");
- //
- // //Set the sub-element value
- // elementDescription.setTextContent("MyApplication");
- //
- // //Add sub-element to root element
- // elementCandidatura.appendChild(elementDescription);
- //
- // //Create a sub-element
- // Element elementKeywords = document.createElement("keywords");
- //
- // //iterate over keywords
- // for (Keyword keyword : keywordList)
- // {
- // Node keywordNode = keyword.exportContentToXMLNode();
- // elementKeywords.appendChild(document.importNode(keywordNode, true));
- // }
- //
- // elementCandidatura.appendChild(elementKeywords);
- //
- // //Add root element to document
- // document.appendChild(elementCandidatura);
- //
- // Application result = new Application();
- // result = result.importContentFromXMLNode(elementCandidatura);
- //
- // assertEquals(expected, result);
- // }
- /**
- *
- */
- @Test
- public void ensureSameContentObjectsAreEqual() {
- String description = "MyCandidatura";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- keywords.add(new Keyword("Windows"));
- Application expected = new Application(description, keywords);
- Application result = new Application(description, keywords);
- assertEquals(expected, result);
- }
- /**
- *
- */
- @Test
- public void ensureSameObjectIsEqual() {
- String description = "MyCandidatura";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- keywords.add(new Keyword("Windows"));
- Application expected = new Application(description, keywords);
- assertEquals(expected, expected);
- }
- /**
- *
- */
- @Test
- public void ensureDifferentObjectsAreNotEqual() {
- String description = "MyCandidatura";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- keywords.add(new Keyword("Windows"));
- Application expected = new Application(description, keywords);
- Object result = new Object();
- assertNotEquals(expected, result);
- }
- /**
- *
- */
- @Test
- public void ensureDifferentDescriptionMakeObjectsNotEqual() {
- String description1 = "MyCandidatura1";
- String description2 = "MyCandidatura2";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- keywords.add(new Keyword("Windows"));
- Application expected = new Application(description1, keywords);
- Application result = new Application(description2, keywords);
- assertNotEquals(expected, result);
- }
- /**
- *
- */
- @Test
- public void ensureHashCodeIsCorrect() {
- String description = "MyCandidatura";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- keywords.add(new Keyword("Windows"));
- Application application = new Application(description, keywords);
- int expected = 461375881;
- int result = application.hashCode();
- assertEquals(expected, result);
- }
- /**
- *
- */
- @Test
- public void testGetApplicationInfo() {
- String description = "MyCandidatura";
- List<Keyword> keywords = new ArrayList<>();
- keywords.add(new Keyword("Doors"));
- Application application = new Application(description, keywords);
- String expected = "Description: MyCandidatura" + "\n" + "Γrea do Stand: 0" + "\n" + "Quantidade de convites: 0" + "\n" + "Keywords: " + keywords;
- String result = application.getApplicationInfo();
- assertEquals(expected, result);
- }
- /**
- * Test of getKeywordList method, of class Application.
- */
- @Test
- public void testGetKeywordList() {
- System.out.println("getKeywordList");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- List<Keyword> expResult = new ArrayList<>();
- List<Keyword> result = a.getKeywordList();
- assertEquals(expResult, result);
- }
- /**
- * Test of getAccepted method, of class Application.
- */
- @Test
- public void testGetAccepted() {
- System.out.println("getAccepted");
- Application instance = new Application();
- Boolean expResult = null;
- Boolean result = instance.getAccepted();
- assertEquals(expResult, result);
- }
- /**
- * Test of getBoothArea method, of class Application.
- */
- @Test
- public void testGetBoothArea() {
- System.out.println("getBoothArea");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- Integer expResult = 20;
- Integer result = a.getBoothArea();
- assertEquals(expResult, result);
- }
- /**
- * Test of getInvitesQuantity method, of class Application.
- */
- @Test
- public void testGetInvitesQuantity() {
- System.out.println("getInvitesQuantity");
- Application instance = new Application();
- Integer expResult = null;
- Integer result = instance.getInvitesQuantity();
- assertEquals(expResult, result);
- }
- /**
- * Test of equals method, of class Application.
- */
- @Test
- public void testAddAssignment() {
- User u = new User("Default User", "Default", "default@gmail.com", "Ab-12");
- FuncionarioApoioEvento f = new FuncionarioApoioEvento(u);
- Assignment assign = new Assignment(f);
- AssignmentList assignmentList = new AssignmentList();
- boolean result1 = assignmentList.addAssignment(assign);
- boolean expResult1 = true;
- assertEquals(expResult1, result1);
- boolean result2 = assignmentList.addAssignment(assign);
- boolean expResult2 =false;
- assertEquals(expResult2, result2);
- }
- /**
- * Test of equals method, of class Application.
- */
- @Test
- public void testGetAssignList() {
- System.out.println("getAssignList");
- Application a = new Application();
- AssignmentList expResult = new AssignmentList();
- AssignmentList result = a.getAssignList();
- assertEquals(expResult, result);
- }
- /**
- * Test of getDescription method, of class Application.
- */
- @Test
- public void testGetDescription() {
- System.out.println("getDescription");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- String expResult = "ensureWorks";
- String result = a.getDescription();
- assertEquals(expResult, result);
- }
- /**
- * Test of getCompanyName method, of class Application.
- */
- @Test
- public void testGetCompanyName() {
- System.out.println("getCompanyName");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- String expResult = "Company";
- String result = a.getCompanyName();
- assertEquals(expResult, result);
- }
- /**
- * Test of getDescription method, of class Application.
- */
- @Test
- public void testSetCompanyName() {
- System.out.println("getCompanyName");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("...", "ensureWorks", keywordList, 20, 30,userMaker1);
- String expResult = "Company";
- a.setCompanyName(expResult);
- String result = a.getCompanyName();
- assertEquals(expResult, result);
- }
- /**
- *
- */
- @Test
- public void testSetAccepted() {
- System.out.println("setAccepted");
- List<Keyword> keywordList = new ArrayList<>();
- Application a = new Application("testeSetAccepted", "testeSetAccepted", keywordList, 20, 30,userMaker1);
- a.setAccepted(true);
- assertEquals(true, a.getAccepted());
- }
- /**
- * Test of compareTo method, of class Application.
- */
- @Test
- public void testCompareTo() {
- System.out.println("compareTo");
- List<Keyword> keywordList = new ArrayList<>();
- List<Keyword> keywordList1 = new ArrayList<>();
- Keyword k = new Keyword("test");
- keywordList1.add(k);
- Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- Application app = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
- Application app1 = new Application("Company1", "ensureWorks", keywordList, 20, 30,userMaker1);
- Application app2 = new Application("Company", "ensureWorks2", keywordList, 20, 30,userMaker1);
- Application app3 = new Application("Company", "ensureWorks", keywordList1, 20, 30,userMaker1);
- Application app4 = new Application("Company", "ensureWorks", keywordList, 30, 30,userMaker1);
- Application app5 = new Application("Company", "ensureWorks", keywordList, 20, 20,userMaker1);
- Application app6 = new Application("Company", "ensureWorks", keywordList, 20, 20,userMaker2);
- int expResult = 0;
- int result = a.compareTo(app);
- assertEquals(expResult, result);
- int expResult1 = 1;
- int result1 = a.compareTo(app1);
- assertEquals(expResult1, result1);
- int expResult2 = 1;
- int result2 = a.compareTo(app2);
- assertEquals(expResult2, result2);
- int expResult3 = 1;
- int result3 = a.compareTo(app3);
- assertEquals(expResult3, result3);
- int expResult4 = 1;
- int result4 = a.compareTo(app4);
- assertEquals(expResult4, result4);
- int expResult5 = 1;
- int result5 = a.compareTo(app5);
- assertEquals(expResult5, result5);
- int expResult6 = 1;
- int result6 = a.compareTo(app6);
- assertEquals(expResult6, result6);
- }
- /**
- * Test of hashCode method, of class Application.
- */
- @Test
- public void testHashCode() {
- System.out.println("hashCode");
- List<Keyword> k = new ArrayList<>();
- Application a1 = new Application("Company", "description", k, 34, 3 ,userMaker1);
- Application a2 = new Application("Company", "description", k, 34, 3,userMaker1);
- int expResult = a1.hashCode();
- int result = a2.hashCode();
- assertEquals(expResult, result);
- }
- /**
- * Test of getApplicationMaker method, of class Application.
- */
- @Test
- public void testGetApplicationMaker()
- {
- System.out.println("getApplicationMaker");
- Application instance = new Application();
- ParticipantRepresentant expResult = null;
- ParticipantRepresentant result = instance.getApplicationMaker();
- assertEquals(expResult, result);
- }
- /**
- * Test of setApplicationMaker method, of class Application.
- */
- @Test
- public void testSetApplicationMaker()
- {
- System.out.println("setApplicationMaker");
- ParticipantRepresentant applicationMaker = null;
- Application instance = new Application();
- instance.setApplicationMaker(applicationMaker);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement