minor codacy requested fixes

This commit is contained in:
Jeremy Long
2017-05-30 06:44:00 -04:00
parent 72aec26ede
commit d355cab2f9
3 changed files with 29 additions and 35 deletions

View File

@@ -13,37 +13,12 @@ import java.util.Map;
* @author https://stackoverflow.com/users/823393/oldcurmudgeon
*/
public class XmlEntity {
/**
* Private constructor for a utility class.
*/
private XmlEntity() {
}
/**
* Converts a named XML entity into its HTML encoded Unicode code point.
*
* @param s the named entity (note, this should not include the leading '&'
* or trailing ';'
* @return the HTML encoded Unicode code point representation of the named
* entity
*/
public static String fromNamedReference(CharSequence s) {
if (s == null) {
return null;
}
final Integer code = SPECIALS.get(s.toString());
if (code != null) {
return "&#" + code + ";";
}
return null;
}
/**
* The map of HTML entities.
*/
private static final Map<String, Integer> SPECIALS;
//<editor-fold defaultstate="collapsed" desc="Initialize SPECIALS">
/**
* Create a map HTML Named Entities to their numeric equivalent. Derived
* from Wikipedia
@@ -306,4 +281,30 @@ public class XmlEntity {
map.put("diams", 9830);
SPECIALS = Collections.unmodifiableMap(map);
}
//</editor-fold>
/**
* Private constructor for a utility class.
*/
private XmlEntity() {
}
/**
* Converts a named XML entity into its HTML encoded Unicode code point.
*
* @param s the named entity (note, this should not include the leading '&amp;'
* or trailing ';'
* @return the HTML encoded Unicode code point representation of the named
* entity
*/
public static String fromNamedReference(CharSequence s) {
if (s == null) {
return null;
}
final Integer code = SPECIALS.get(s.toString());
if (code != null) {
return "&#" + code + ";";
}
return null;
}
}

View File

@@ -17,10 +17,6 @@
*/
package org.owasp.dependencycheck.xml;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

View File

@@ -21,11 +21,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -126,10 +121,12 @@ public class XmlInputStreamTest {
InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
XmlInputStream instance = new XmlInputStream(stream);
int r = instance.read();
assertEquals('t', r);
String expResult = "[1]-\"t\" ( 74)";
String result = instance.toString();
assertEquals(expResult, result);
r = instance.read();
assertEquals('e', r);
expResult = "[2]-\"te\" ( 74 65)";
result = instance.toString();
assertEquals(expResult, result);