### Question:
UnitCategoryParser { public static Unit checkUnit(String value, UnitCategory unitCategory) { if (unitCategory != null) { Quantity quantity = checkQuantity(value); if (quantity != null) { try { value = transformQuantity(value, quantity); } catch (ParseException e) { logger.trace("Could not transform " + value + "!"); return null; } } for (Unit unit : unitCategory.getUnits()) { String nonNumberPart = value.replaceAll("^[0-9\\,\\.\\-Ee\\+]*", ""); nonNumberPart = nonNumberPart.trim(); if (nonNumberPart.toLowerCase().equals(unit.getName()) || unit.getAbbreviations().contains(nonNumberPart.toLowerCase())) { return unit; } } } return null; }  static List<UnitCategory> getUnitCategories(); static Quantity getQuantity(String name); static UnitCategory getUnitCategory(String name); static Double transform(String value, Unit unit, Quantity quantity); static Unit checkUnit(String value, UnitCategory unitCategory); static String transformQuantity(String value, Quantity quantity); static Quantity checkQuantity(String value); static UnitCategory checkUnitCategory(String value); static Double normalizeNumeric(String value); static Unit parseUnitFromHeader(String header); static List<UnitCategory> categories; static List<Quantity> quantities; }### Answer:
@Test public void testCheckUnit() { assertNull(UnitCategoryParser.checkUnit("100 km", null)); assertNotNull(UnitCategoryParser.checkUnit("100 km", UnitCategoryParser.getUnitCategory("All"))); assertNull(UnitCategoryParser.checkUnit("100 km", UnitCategoryParser.getUnitCategory("Area"))); assertNotNull(UnitCategoryParser.checkUnit("100 km", UnitCategoryParser.getUnitCategory("Distance"))); assertNull(UnitCategoryParser.checkQuantity("100 km")); assertNull(UnitCategoryParser.checkUnit("100 million", null)); assertNotNull(UnitCategoryParser.checkQuantity("100 million")); assertEquals(UnitCategoryParser.getQuantity("million"),UnitCategoryParser.checkQuantity("100 million km")); assertEquals("kilometre",UnitCategoryParser.checkUnit("100 million km", UnitCategoryParser.getUnitCategory("Distance")).getName()); assertEquals(UnitCategoryParser.checkQuantity("million"), UnitCategoryParser.checkQuantity("100 million km")); assertNull(UnitCategoryParser.checkUnit("$ 50", null)); assertNull(UnitCategoryParser.checkUnit("$ 50 million", null)); }