### Question:
MmdTool extends BasicTool { static long getPattern(Configuration config) { final String[] sensorNames = getSensorNames(config); long pattern = 0; for (final String sensorName : sensorNames) { pattern |= config.getPattern(sensorName, 0); } final String referenceSensor = config.getStringValue(Configuration.KEY_MMS_SAMPLING_REFERENCE_SENSOR, null); if (Constants.SENSOR_NAME_HISTORY.equalsIgnoreCase(referenceSensor)) { pattern |= config.getPattern(Constants.SENSOR_NAME_HISTORY); } return pattern; } MmdTool(); static void main(String[] args); @Override void initialize();  }### Answer:
@Test public void testGetPattern() { final Configuration config = new Configuration(); config.put("mms.pattern.atsr.3", "10000"); config.put(Configuration.KEY_MMS_MMD_SENSORS, "atsr.3"); final long pattern = MmdTool.getPattern(config); assertEquals(0x10000L, pattern); }
@Test public void testGetPattern_forSensorPair() { final Configuration config = new Configuration(); config.put("mms.pattern.atsr.2", "08000"); config.put("mms.pattern.atsr.3", "10000"); config.put(Configuration.KEY_MMS_MMD_SENSORS, "atsr.3,atsr.2"); final long pattern = MmdTool.getPattern(config); assertEquals(0x18000L, pattern); }
@Test public void testGetPattern_withHistoryWhenSamplingReferenceSensorIsSet() { final Configuration config = new Configuration(); config.put("mms.pattern.atsr.3", "10000"); config.put(Configuration.KEY_MMS_MMD_SENSORS, "atsr.3"); config.put(Configuration.KEY_MMS_SAMPLING_REFERENCE_SENSOR, Constants.SENSOR_NAME_HISTORY); config.put("mms.pattern.history", "4000000000000000"); final long pattern = MmdTool.getPattern(config); assertEquals(0x10000L | 0x4000000000000000L, pattern); }
@Test public void testGetPattern_usesDefaultWhenValueInConfigNotSet() { final Configuration config = new Configuration(); config.put(Configuration.KEY_MMS_MMD_SENSORS, "atsr.3"); final long pattern = MmdTool.getPattern(config); assertEquals(0, pattern); }
@Test public void testGetPattern_throwsWhenValueCannotBeParsed() { final Configuration config = new Configuration(); config.put("mms.pattern.atsr.3", "oooopsi"); config.put(Configuration.KEY_MMS_MMD_SENSORS, "atsr.3"); try { MmdTool.getPattern(config); fail("ToolException expected"); } catch (ToolException expected) { } }