From fa8c6e14b3f87407ea5805e35697acc4d93a8007 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 27 Jun 2021 12:43:28 +0200 Subject: PlayList class covered at 84%. --- .../jacoco/musichub.business/PlayList.java.html | 92 +++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'target/site/jacoco/musichub.business/PlayList.java.html') diff --git a/target/site/jacoco/musichub.business/PlayList.java.html b/target/site/jacoco/musichub.business/PlayList.java.html index 6a45004..3c1eb72 100644 --- a/target/site/jacoco/musichub.business/PlayList.java.html +++ b/target/site/jacoco/musichub.business/PlayList.java.html @@ -13,89 +13,89 @@ public class PlayList { private final UUID uuid; private ArrayList<UUID> elementUUIDs; - public PlayList(String title, String id, ArrayList<UUID> elementUUIDs) { - this.title = title; - this.uuid = UUID.fromString(id); - this.elementUUIDs = elementUUIDs; - } - - public PlayList(String title) { - this.title = title; - this.uuid = UUID.randomUUID(); - this.elementUUIDs = new ArrayList<>(); - } - - public PlayList(Element xmlElement) { + public PlayList(String title, String id, ArrayList<UUID> elementUUIDs) { + this.title = title; + this.uuid = UUID.fromString(id); + this.elementUUIDs = elementUUIDs; + } + + public PlayList(String title) { + this.title = title; + this.uuid = UUID.randomUUID(); + this.elementUUIDs = new ArrayList<>(); + } + + public PlayList(Element xmlElement) { { - this.title = xmlElement.getElementsByTagName("title").item(0).getTextContent(); + this.title = xmlElement.getElementsByTagName("title").item(0).getTextContent(); - String uuid = null; + String uuid = null; try { - uuid = xmlElement.getElementsByTagName("UUID").item(0).getTextContent(); + uuid = xmlElement.getElementsByTagName("UUID").item(0).getTextContent(); } catch (Exception ex) { System.out.println("Empty playlist UUID, will create a new one"); - } - if ((uuid == null) || (uuid.isEmpty())) + } + if ((uuid == null) || (uuid.isEmpty())) this.uuid = UUID.randomUUID(); - else this.uuid = UUID.fromString(uuid); + else this.uuid = UUID.fromString(uuid); //parse list of elements: - Node elementsElement = xmlElement.getElementsByTagName("elements").item(0); - NodeList elementUUIDNodes = elementsElement.getChildNodes(); - if (elementUUIDNodes == null) return; + Node elementsElement = xmlElement.getElementsByTagName("elements").item(0); + NodeList elementUUIDNodes = elementsElement.getChildNodes(); + if (elementUUIDNodes == null) return; - this.elementUUIDs = new ArrayList<>(); + this.elementUUIDs = new ArrayList<>(); - for (int i = 0; i < elementUUIDNodes.getLength(); i++) { - if (elementUUIDNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { - Element elementElement = (Element) elementUUIDNodes.item(i); - if (elementElement.getNodeName().equals("UUID")) { + for (int i = 0; i < elementUUIDNodes.getLength(); i++) { + if (elementUUIDNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { + Element elementElement = (Element) elementUUIDNodes.item(i); + if (elementElement.getNodeName().equals("UUID")) { try { - this.addElement(UUID.fromString(elementElement.getTextContent())); + this.addElement(UUID.fromString(elementElement.getTextContent())); } catch (Exception ex) { ex.printStackTrace(); - } + } } } } } - } + } public void addElement(UUID element) { - elementUUIDs.add(element); - } + elementUUIDs.add(element); + } public ArrayList<UUID> getElements() { - return elementUUIDs; + return elementUUIDs; } public String getTitle() { - return title; + return title; } public void createXMLElement(Document document, Element parentElement) { - Element playlistElement = document.createElement("playlist"); - parentElement.appendChild(playlistElement); + Element playlistElement = document.createElement("playlist"); + parentElement.appendChild(playlistElement); - Element nameElement = document.createElement("title"); - nameElement.appendChild(document.createTextNode(title)); - playlistElement.appendChild(nameElement); + Element nameElement = document.createElement("title"); + nameElement.appendChild(document.createTextNode(title)); + playlistElement.appendChild(nameElement); - Element UUIDElement = document.createElement("UUID"); - UUIDElement.appendChild(document.createTextNode(uuid.toString())); - playlistElement.appendChild(UUIDElement); + Element UUIDElement = document.createElement("UUID"); + UUIDElement.appendChild(document.createTextNode(uuid.toString())); + playlistElement.appendChild(UUIDElement); - Element elementsElement = document.createElement("elements"); - for (UUID currentUUID : this.elementUUIDs) { + Element elementsElement = document.createElement("elements"); + for (UUID currentUUID : this.elementUUIDs) { Element elementUUIDElement = document.createElement("UUID"); elementUUIDElement.appendChild(document.createTextNode(currentUUID.toString())); elementsElement.appendChild(elementUUIDElement); } - playlistElement.appendChild(elementsElement); - } + playlistElement.appendChild(elementsElement); + } } \ No newline at end of file -- cgit v1.2.3