FontCharacteristicsUtils { static short parseFontWeight(String fw) { if (fw == null || fw.length() == 0) { return -1; } fw = fw.trim().toLowerCase(); switch (fw) { case "bold": return FontWeights.BOLD; case "normal": return FontWeights.NORMAL; default: try { return normalizeFontWeight((short) Integer.parseInt(fw)); } catch (NumberFormatException ignored) { return -1; } } }    }
@Test public void testParsingIncorrectFontWeight() { Assert.assertEquals((short) -1, FontCharacteristicsUtils.parseFontWeight("")); Assert.assertEquals((short) -1, FontCharacteristicsUtils.parseFontWeight(null)); Assert.assertEquals((short) -1, FontCharacteristicsUtils.parseFontWeight("dfgdgdfgdfgdf")); Assert.assertEquals((short) -1, FontCharacteristicsUtils.parseFontWeight("italic")); }
@Test public void testParsingNumberFontWeight() { Assert.assertEquals((short) 100, FontCharacteristicsUtils.parseFontWeight("-1")); Assert.assertEquals((short) 100, FontCharacteristicsUtils.parseFontWeight("50")); Assert.assertEquals((short) 300, FontCharacteristicsUtils.parseFontWeight("360")); Assert.assertEquals((short) 900, FontCharacteristicsUtils.parseFontWeight("25000")); }
@Test public void testParseAllowedFontWeight() { Assert.assertEquals((short) 400, FontCharacteristicsUtils.parseFontWeight("normal")); Assert.assertEquals((short) 700, FontCharacteristicsUtils.parseFontWeight("bold")); }