ModisUtils { public static String extractValueForKey(String metaDataString, String key) { Guardian.assertNotNull("metaDataString", metaDataString); Guardian.assertNotNull("key", key); int pos = metaDataString.indexOf(key); if (pos >= 0) { pos = metaDataString.indexOf("VALUE", pos); if (pos >= 0) { pos = metaDataString.indexOf('=', pos); if (pos >= 0) { int endPos = metaDataString.indexOf('\n', pos + 1); if (endPos >= 0) { String value = metaDataString.substring(pos + 1, endPos); value = value.replace('"', ' '); return value.trim(); } } } } return null; }  static String decodeBandName(String names, int layerIdx); static float[] decodeSpectralInformation(String bandExt, float[] recycle); static String extractValueForKey(String metaDataString, String key); static Date createDateFromStrings(final String date, final String time); static IncrementOffset getIncrementOffset(String attribute); static Range getRangeFromString(String rangeString); static String extractBandName(String variableName);  }
@Test public void testExtractValueForKey() { assertEquals("Night", ModisUtils.extractValueForKey(TestCoreString, "DAYNIGHTFLAG")); assertEquals("2005-10-26T10:07:21.000Z", ModisUtils.extractValueForKey(TestCoreString, "PRODUCTIONDATETIME")); assertNull(ModisUtils.extractValueForKey(TestCoreString, "huppepup")); }
@Test public void testExtractIntegerValueFromObject() { assertEquals("18490", ModisUtils.extractValueForKey(TestCoreString, "ORBITNUMBER")); }
@Test public void testExtractValueForKeyHandlesStupidInput() { try { ModisUtils.extractValueForKey(null, "DAYNIGHTFLAG"); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ignored) { } try { ModisUtils.extractValueForKey(TestCoreString, null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ignored) { } }