44 */
55package org .hibernate .orm .test .annotations .lob ;
66
7- import org .hibernate .dialect .*;
8- import org .junit .Test ;
97
10- import org .hibernate .testing .SkipForDialect ;
11- import org .hibernate .testing .junit4 .BaseCoreFunctionalTestCase ;
8+ import org .hibernate .dialect .SybaseDialect ;
9+ import org .hibernate .testing .orm .junit .SessionFactory ;
10+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
11+ import org .hibernate .testing .orm .junit .SkipForDialect ;
12+ import org .junit .jupiter .api .Test ;
1213
13- import static org .hibernate .testing .transaction .TransactionUtil .doInHibernate ;
14- import static org .junit .Assert .assertEquals ;
15- import static org .junit .Assert .assertNotNull ;
16- import static org .junit .Assert .assertNull ;
14+ import static org .assertj .core .api .Assertions .assertThat ;
1715
1816/**
1917 * @author Gail Badner
2018 */
21- public abstract class AbstractLobTest < B extends AbstractBook , C extends AbstractCompiledCode >
22- extends BaseCoreFunctionalTestCase {
19+ @ SessionFactory
20+ public abstract class AbstractLobTest < B extends AbstractBook , C extends AbstractCompiledCode > {
2321
2422 protected abstract Class <B > getBookClass ();
2523
@@ -41,102 +39,103 @@ protected C createCompiledCode() {
4139 return getCompiledCodeClass ().newInstance ();
4240 }
4341 catch (Exception ex ) {
44- throw new RuntimeException ( "Could not create an instance of type " + getCompiledCodeClass ().getName (), ex );
42+ throw new RuntimeException ( "Could not create an instance of type " + getCompiledCodeClass ().getName (),
43+ ex );
4544 }
4645 }
4746
4847 protected abstract Integer getId (C compiledCode );
4948
5049 @ Test
51- public void testSerializableToBlob () throws Exception {
50+ public void testSerializableToBlob (SessionFactoryScope scope ) {
5251 B book = createBook ();
5352 Editor editor = new Editor ();
5453 editor .setName ( "O'Reilly" );
5554 book .setEditor ( editor );
56- book .setCode2 ( new char [] { 'r' } );
55+ book .setCode2 ( new char [] {'r' } );
5756
58- doInHibernate ( this :: sessionFactory , session -> {
59- session .persist ( book );
60- } );
57+ scope . inTransaction ( session ->
58+ session .persist ( book )
59+ );
6160
62- doInHibernate ( this :: sessionFactory , session -> {
61+ scope . inTransaction ( session -> {
6362 B loadedBook = getBookClass ().cast ( session .get ( getBookClass (), getId ( book ) ) );
64- assertNotNull ( loadedBook .getEditor () );
65- assertEquals ( book .getEditor ().getName (), loadedBook .getEditor ().getName () );
63+ assertThat ( loadedBook .getEditor () ). isNotNull ( );
64+ assertThat ( loadedBook .getEditor ().getName () ). isEqualTo ( book .getEditor ().getName () );
6665 loadedBook .setEditor ( null );
6766 } );
6867
69- doInHibernate ( this :: sessionFactory , session -> {
68+ scope . inTransaction ( session -> {
7069 B loadedBook = getBookClass ().cast ( session .get ( getBookClass (), getId ( book ) ) );
71- assertNull ( loadedBook .getEditor () );
70+ assertThat ( loadedBook .getEditor () ). isNull ( );
7271 } );
7372 }
7473
7574 @ Test
76- public void testClob () throws Exception {
75+ public void testClob (SessionFactoryScope scope ) {
7776
7877 B book = createBook ();
7978 book .setShortDescription ( "Hibernate Bible" );
8079 book .setFullText ( "Hibernate in Action aims to..." );
81- book .setCode ( new Character [] { 'a' , 'b' , 'c' } );
82- book .setCode2 ( new char [] { 'a' , 'b' , 'c' } );
80+ book .setCode ( new Character [] {'a' , 'b' , 'c' } );
81+ book .setCode2 ( new char [] {'a' , 'b' , 'c' } );
8382
84- doInHibernate ( this :: sessionFactory , session -> {
85- session .persist ( book );
86- } );
83+ scope . inTransaction ( session ->
84+ session .persist ( book )
85+ );
8786
88- doInHibernate ( this :: sessionFactory , session -> {
87+ scope . inTransaction ( session -> {
8988 B b2 = getBookClass ().cast ( session .get ( getBookClass (), getId ( book ) ) );
90- assertNotNull ( b2 );
91- assertEquals ( b2 .getFullText (), book .getFullText () );
92- assertEquals ( b2 .getCode ()[1 ].charValue (), book .getCode ()[1 ].charValue () );
93- assertEquals ( b2 .getCode2 ()[2 ], book .getCode2 ()[2 ] );
89+ assertThat ( b2 ). isNotNull ( );
90+ assertThat ( b2 .getFullText () ). isEqualTo ( book .getFullText () );
91+ assertThat ( b2 .getCode ()[1 ].charValue () ). isEqualTo ( book .getCode ()[1 ].charValue () );
92+ assertThat ( b2 .getCode2 ()[2 ] ). isEqualTo ( book .getCode2 ()[2 ] );
9493 } );
9594 }
9695
9796 @ Test
98- public void testBlob () throws Exception {
97+ public void testBlob (SessionFactoryScope scope ) {
9998
10099 C cc = createCompiledCode ();
101100 Byte [] header = new Byte [2 ];
102- header [0 ] = new Byte ( ( byte ) 3 ) ;
103- header [1 ] = new Byte ( ( byte ) 0 ) ;
101+ header [0 ] = 3 ;
102+ header [1 ] = 0 ;
104103 cc .setHeader ( header );
105104 int codeSize = 5 ;
106105 byte [] full = new byte [codeSize ];
107106 for ( int i = 0 ; i < codeSize ; i ++ ) {
108- full [i ] = ( byte ) ( 1 + i );
107+ full [i ] = (byte ) (1 + i );
109108 }
110109 cc .setFullCode ( full );
111110
112- doInHibernate ( this :: sessionFactory , session -> {
113- session .persist ( cc );
114- } );
111+ scope . inTransaction ( session ->
112+ session .persist ( cc )
113+ );
115114
116- doInHibernate ( this :: sessionFactory , session -> {
115+ scope . inTransaction ( session -> {
117116 C recompiled = getCompiledCodeClass ().cast ( session .get ( getCompiledCodeClass (), getId ( cc ) ) );
118- assertEquals ( recompiled .getHeader ()[1 ], cc .getHeader ()[1 ] );
119- assertEquals ( recompiled .getFullCode ()[codeSize - 1 ], cc .getFullCode ()[codeSize - 1 ] );
117+ assertThat ( recompiled .getHeader ()[1 ] ). isEqualTo ( cc .getHeader ()[1 ] );
118+ assertThat ( recompiled .getFullCode ()[codeSize - 1 ] ). isEqualTo ( cc .getFullCode ()[codeSize - 1 ] );
120119 } );
121120 }
122121
123122 @ Test
124- @ SkipForDialect ( SybaseDialect .class )
125- public void testBinary () throws Exception {
123+ @ SkipForDialect (dialectClass = SybaseDialect .class )
124+ public void testBinary (SessionFactoryScope scope ) {
126125
127126 C cc = createCompiledCode ();
128127 byte [] metadata = new byte [2 ];
129- metadata [0 ] = ( byte ) 3 ;
130- metadata [1 ] = ( byte ) 0 ;
128+ metadata [0 ] = 3 ;
129+ metadata [1 ] = 0 ;
131130 cc .setMetadata ( metadata );
132131
133- doInHibernate ( this :: sessionFactory , session -> {
134- session .persist ( cc );
135- } );
132+ scope . inTransaction ( session ->
133+ session .persist ( cc )
134+ );
136135
137- doInHibernate ( this :: sessionFactory , session -> {
136+ scope . inTransaction ( session -> {
138137 C recompiled = getCompiledCodeClass ().cast ( session .get ( getCompiledCodeClass (), getId ( cc ) ) );
139- assertEquals ( recompiled .getMetadata ()[1 ], cc .getMetadata ()[1 ] );
138+ assertThat ( recompiled .getMetadata ()[1 ] ). isEqualTo ( cc .getMetadata ()[1 ] );
140139 } );
141140 }
142141}
0 commit comments