SerialisationFactory { public Serialiser getSerialiser(final Class<?> objClass) { return getSerialiser(objClass, false, false); } SerialisationFactory();  SerialisationFactory(final Serialiser... serialisers); List<Serialiser> getSerialisers(); void addSerialisers(final Serialiser... newSerialisers); Serialiser getSerialiser(final Class<?> objClass); Serialiser getSerialiser(final Class<?> objClass, final boolean preserveOrder, final boolean consistentSerialiser);  }
@Test public void shouldReturnSerialiserForAString() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = String.class; final Serialiser serialiser = factory.getSerialiser(clazz); assertTrue(serialiser.canHandle(clazz)); assertEquals(StringSerialiser.class, serialiser.getClass()); }
@Test public void shouldReturnOrderedSerialiserForAString() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = String.class; final boolean ordered = true; final Serialiser serialiser = factory.getSerialiser(clazz, ordered, true); assertTrue(serialiser.canHandle(clazz)); assertEquals(StringSerialiser.class, serialiser.getClass()); }
@Test public void shouldReturnSerialiserForAnInteger() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = Integer.class; final Serialiser serialiser = factory.getSerialiser(clazz); assertTrue(serialiser.canHandle(clazz)); assertEquals(OrderedIntegerSerialiser.class, serialiser.getClass()); }
@Test public void shouldReturnOrderedSerialiserForAnInteger() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = Integer.class; final boolean ordered = true; final Serialiser serialiser = factory.getSerialiser(clazz, ordered, true); assertTrue(serialiser.canHandle(clazz)); assertEquals(OrderedIntegerSerialiser.class, serialiser.getClass()); }
@Test public void shouldThrowExceptionIfClassIsNull() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = null; try { factory.getSerialiser(clazz); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldThrowExceptionIfNoSerialiserFound() throws SerialisationException { final SerialisationFactory factory = new SerialisationFactory(); final Class<?> clazz = Object.class; try { factory.getSerialiser(clazz); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldReturnCustomSerialiserIfCustomSerialiserFound() throws SerialisationException { final Serialiser[] serialisers = new Serialiser[]{ new RawDateSerialiser(), new RawDoubleSerialiser(), new RawFloatSerialiser() }; final SerialisationFactory factory = new SerialisationFactory(serialisers); final Class<?> clazz = Double.class; final Serialiser serialiser = factory.getSerialiser(clazz); assertTrue(serialiser.canHandle(clazz)); assertEquals(RawDoubleSerialiser.class, serialiser.getClass()); }
@Test public void shouldReturnJavaSerialiserIfNoCustomSerialiserFound() throws SerialisationException { final Serialiser[] serialisers = new Serialiser[]{ new RawDateSerialiser(), new RawDoubleSerialiser(), new RawFloatSerialiser() }; final SerialisationFactory factory = new SerialisationFactory(serialisers); final Class<?> clazz = String.class; final Serialiser serialiser = factory.getSerialiser(clazz); assertTrue(serialiser.canHandle(clazz)); assertEquals(JavaSerialiser.class, serialiser.getClass()); }