SequenceFileSerializerFactory { @SuppressWarnings({"squid:MethodCyclomaticComplexity","squid:S1166"}) static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { LOGGER.debug("Not in enum, loading builder class: {}" + formatType); type = SequenceFileSerializerType.OTHER; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { LOGGER.error("Unable to instantiate AvroEventSerializerBuilder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { LOGGER.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { LOGGER.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { LOGGER.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { LOGGER.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); } private  SequenceFileSerializerFactory();   }
@Test @Ignore public void getTextFormatter() { SequenceFileSerializer formatter = SequenceFileSerializerFactory.getSerializer("TEXT", new Context()); assertTrue(formatter != null); assertTrue(formatter.getClass().getName(), formatter instanceof HDFSTextSerializer); }
@Test @Ignore public void getWritableFormatter() { SequenceFileSerializer formatter = SequenceFileSerializerFactory.getSerializer("WRITABLE", new Context()); assertTrue(formatter != null); assertTrue(formatter.getClass().getName(), formatter instanceof HDFSWritableSerializer); }
@Test @Ignore public void getCustomFormatter() { SequenceFileSerializer formatter = SequenceFileSerializerFactory .getSerializer( "MyCustomSerializer$AvroEventSerializerBuilder", new Context()); assertTrue(formatter != null); assertTrue(formatter.getClass().getName(), formatter instanceof MyCustomSerializer); }