Skip to content

Commit a3d68d6

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.jpa.proxy/ql/schemagen
Signed-off-by: Jan Schatteman <[email protected]>
1 parent c31cf7e commit a3d68d6

10 files changed

+321
-433
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/proxy/JPAProxyTest.java

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
import org.hibernate.orm.test.jpa.model.AbstractJPATest;
1010
import org.hibernate.orm.test.jpa.model.Item;
1111
import org.junit.jupiter.api.Test;
12-
import junit.framework.AssertionFailedError;
1312

1413
import jakarta.persistence.EntityNotFoundException;
1514

1615
import static org.junit.jupiter.api.Assertions.assertFalse;
1716
import static org.junit.jupiter.api.Assertions.assertNull;
18-
import static org.junit.jupiter.api.Assertions.fail;
19-
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
2018

2119
/**
2220
* Test relation between proxies and get()/load() processing
@@ -30,34 +28,24 @@ public class JPAProxyTest extends AbstractJPATest {
3028
public void testEjb3ProxyUsage() {
3129
inTransaction(
3230
s -> {
33-
Item item = s.getReference( Item.class, new Long( -1 ) );
31+
Item item = s.getReference( Item.class, -1L );
3432
assertFalse( Hibernate.isInitialized( item ) );
35-
try {
36-
Hibernate.initialize( item );
37-
fail( "proxy access did not fail on non-existent proxy" );
38-
}
39-
catch (EntityNotFoundException e) {
40-
// expected behavior
41-
}
42-
catch (Throwable t) {
43-
fail( "unexpected exception type on non-existent proxy access : " + t );
44-
}
33+
assertThrows(
34+
EntityNotFoundException.class,
35+
() -> Hibernate.initialize(item),
36+
"proxy access did not fail on non-existent proxy"
37+
);
4538

4639
s.clear();
4740

48-
Item item2 = s.getReference( Item.class, new Long( -1 ) );
41+
Item item2 = s.getReference( Item.class, -1L );
4942
assertFalse( Hibernate.isInitialized( item2 ) );
5043
assertFalse( item == item2 );
51-
try {
52-
item2.getName();
53-
fail( "proxy access did not fail on non-existent proxy" );
54-
}
55-
catch (EntityNotFoundException e) {
56-
// expected behavior
57-
}
58-
catch (Throwable t) {
59-
fail( "unexpected exception type on non-existent proxy access : " + t );
60-
}
44+
assertThrows(
45+
EntityNotFoundException.class,
46+
item2::getName,
47+
"proxy access did not fail on non-existent proxy"
48+
);
6149
}
6250
);
6351
}
@@ -67,7 +55,7 @@ public void testEjb3ProxyUsage() {
6755
*/
6856
@Test
6957
public void testGetSemantics() {
70-
Long nonExistentId = new Long( -1 );
58+
Long nonExistentId = -1L;
7159
inTransaction(
7260
session -> {
7361
Item item = session.get( Item.class, nonExistentId );
@@ -81,19 +69,11 @@ public void testGetSemantics() {
8169
Item item = s.getReference( Item.class, nonExistentId );
8270
assertFalse( Hibernate.isInitialized( item ) );
8371
// then try to get() it to make sure we get an exception
84-
try {
85-
s.get( Item.class, nonExistentId );
86-
fail( "force load did not fail on non-existent entity" );
87-
}
88-
catch (EntityNotFoundException e) {
89-
// expected behavior
90-
}
91-
catch (AssertionFailedError e) {
92-
throw e;
93-
}
94-
catch (Throwable t) {
95-
fail( "unexpected exception type on non-existent entity force load : " + t );
96-
}
72+
assertThrows(
73+
EntityNotFoundException.class,
74+
() -> s.get( Item.class, nonExistentId ),
75+
"force load did not fail on non-existent entity"
76+
);
9777
}
9878
);
9979
}

0 commit comments

Comments
 (0)