package com.peterphi.std.guice.hibernate.usertype;

import com.peterphi.std.types.Timebase;
import com.peterphi.std.types.Timecode;
import org.junit.Test;

import java.sql.Types;

import static org.junit.Assert.assertEquals;

public class TimecodeUserTypeTest
{
	private final Timecode TC = Timecode.getInstance("01:02:03:04", Timebase.HZ_25);

	private final TimecodeUserType svc = TimecodeUserType.INSTANCE;


	@Test
	public void testSqlTypes() throws Exception
	{
		assertEquals(Types.VARCHAR, svc.sqlTypes()[0]);
	}


	@Test
	public void testReturnedClass() throws Exception
	{
		assertEquals(Timecode.class, svc.returnedClass());
	}


	@Test
	public void testIsMutable() throws Exception
	{
		assertEquals(false, svc.isMutable());
	}


	@Test
	public void testDisassemble() throws Exception
	{
		assertEquals("01:02:03:04@25", svc.disassemble(TC));
	}


	@Test
	public void testAssemble() throws Exception
	{
		assertEquals(TC, svc.assemble("01:02:03:04@25", null));
	}
}

@@ -336,16 +336,106 @@
 .HZ_25);
+%0A%09private final Timecode TC_DAYS = Timecode.getInstance(%2201:02:03:04:05%22, Timebase.HZ_25);
 %0A%0A%09priva
@@ -1058,10 +1058,286 @@
 l));%0A%09%7D%0A
+%0A%0A%09@Test%0A%09public void testDisassembleWithDaysPart() throws Exception%0A%09%7B%0A%09%09assertEquals(%2201:02:03:04:05@25%22, svc.disassemble(TC_DAYS));%0A%09%7D%0A%0A%0A%09@Test%0A%09public void testAssembleWithDaysPart() throws Exception%0A%09%7B%0A%09%09assertEquals(TC_DAYS, svc.assemble(%2201:02:03:04:05@25%22, null));%0A%09%7D%0A
 %7D%0A

Add unit test to make sure that days component of a Timecode is included when encoding to a database string in hibernate