1 package liquibase.serializer; 2 3 import liquibase.serializer.core.string.StringChangeLogSerializer; 4 import liquibase.serializer.core.xml.XMLChangeLogSerializer; 5 import static org.junit.Assert.*; 6 import org.junit.Before; 7 import org.junit.Test; 8 9 import java.util.Map; 10 11 public class ChangeLogSerializerFactoryTest { 12 13 @Before 14 public void setup() { 15 ChangeLogSerializerFactory.reset(); 16 17 } 18 19 @Test 20 public void getInstance() { 21 assertNotNull(ChangeLogSerializerFactory.getInstance()); 22 23 assertTrue(ChangeLogSerializerFactory.getInstance() == ChangeLogSerializerFactory.getInstance()); 24 } 25 26 @Test 27 public void register() { 28 ChangeLogSerializerFactory.getInstance().getSerializers().clear(); 29 30 assertEquals(0, ChangeLogSerializerFactory.getInstance().getSerializers().size()); 31 32 ChangeLogSerializerFactory.getInstance().register(new MockChangeLogSerializer("mock")); 33 34 assertEquals(1, ChangeLogSerializerFactory.getInstance().getSerializers().size()); 35 } 36 37 @Test 38 public void unregister_instance() { 39 ChangeLogSerializerFactory factory = ChangeLogSerializerFactory.getInstance(); 40 41 factory.getSerializers().clear(); 42 43 assertEquals(0, factory.getSerializers().size()); 44 45 XMLChangeLogSerializer changeLogSerializer = new XMLChangeLogSerializer(); 46 47 factory.register(new StringChangeLogSerializer()); 48 factory.register(changeLogSerializer); 49 50 assertEquals(2, factory.getSerializers().size()); 51 52 factory.unregister(changeLogSerializer); 53 assertEquals(1, factory.getSerializers().size()); 54 } 55 56 @Test 57 public void reset() { 58 ChangeLogSerializerFactory instance1 = ChangeLogSerializerFactory.getInstance(); 59 ChangeLogSerializerFactory.reset(); 60 assertFalse(instance1 == ChangeLogSerializerFactory.getInstance()); 61 } 62 63 @SuppressWarnings("unchecked") 64 @Test 65 public void builtInGeneratorsAreFound() { 66 Map<String, ChangeLogSerializer> generators = ChangeLogSerializerFactory.getInstance().getSerializers(); 67 assertEquals(2, generators.size()); 68 } 69 70 @Test 71 public void getSerializers() { 72 ChangeLogSerializer serializer = ChangeLogSerializerFactory.getInstance().getSerializer("xml"); 73 74 assertNotNull(serializer); 75 assertTrue(serializer instanceof XMLChangeLogSerializer); 76 } 77 78 79 }