SequenceFileExporterMapper extends Mapper<AvroKey<? extends SpecificRecordBase>, NullWritable, Text, Text> { @SuppressWarnings("unchecked") @Override protected void setup(Context context) throws IOException, InterruptedException { String moduleClassName = context.getConfiguration().get(EXPORT_ACTION_BUILDER_FACTORY_CLASSNAME); if (StringUtils.isNotBlank(moduleClassName)) { try { Class<?> clazz = Class.forName(moduleClassName); Constructor<?> constructor = clazz.getConstructor(); ActionBuilderFactory<SpecificRecordBase, Oaf> actionBuilderFactory = (ActionBuilderFactory<SpecificRecordBase, Oaf>) constructor.newInstance(); actionBuilder = actionBuilderFactory.instantiate(context.getConfiguration()); } catch (Exception e) { throw new RuntimeException("unexpected exception ocurred when instantiating " + "builder module: " + moduleClassName, e); } } else { throw new InvalidParameterException("unknown action builder module instance, " + "no " + EXPORT_ACTION_BUILDER_FACTORY_CLASSNAME + " parameter provided!"); } }    }
@Test(expected=InvalidParameterException.class) public void testSetupWitoutActionBuilderClassName() throws Exception { Configuration conf = new Configuration(); doReturn(conf).when(context).getConfiguration(); mapper.setup(context); }
@Test(expected=RuntimeException.class) public void testSetupWithInvalidActionBuilderClassName() throws Exception { Configuration conf = new Configuration(); conf.set(EXPORT_ACTION_BUILDER_FACTORY_CLASSNAME, "invalid.class.name"); doReturn(conf).when(context).getConfiguration(); mapper.setup(context); }