Skip to content

Commit e5f86dc

Browse files
authored
[master] Hamcrest dependency removal (#1689)
Signed-off-by: Radek Felcman <[email protected]>
1 parent b4090a9 commit e5f86dc

File tree

13 files changed

+118
-245
lines changed

13 files changed

+118
-245
lines changed

jpa/eclipselink.jpa.nosql.test/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@
7777
<artifactId>junit</artifactId>
7878
<scope>test</scope>
7979
</dependency>
80-
<!--Required for JPA server test server-test-jpa21-sessionbean.-->
81-
<dependency>
82-
<groupId>org.hamcrest</groupId>
83-
<artifactId>hamcrest-core</artifactId>
84-
</dependency>
8580
<!--Other modules-->
8681
<dependency>
8782
<groupId>org.eclipse.persistence</groupId>

jpa/eclipselink.jpa.test.jse/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@
4141
<artifactId>junit</artifactId>
4242
<scope>test</scope>
4343
</dependency>
44-
<dependency>
45-
<groupId>org.hamcrest</groupId>
46-
<artifactId>hamcrest-all</artifactId>
47-
<version>1.3</version>
48-
<scope>test</scope>
49-
</dependency>
5044
<dependency>
5145
<groupId>jakarta.enterprise</groupId>
5246
<artifactId>jakarta.enterprise.cdi-api</artifactId>

jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/canonical/TestCanonicalMetaModel.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -15,9 +15,6 @@
1515
// - #539822: JPA Canonical metamodel not processing metamodelMappedSuperclasses
1616
package org.eclipse.persistence.jpa.test.canonical;
1717

18-
import static org.hamcrest.CoreMatchers.notNullValue;
19-
import static org.hamcrest.MatcherAssert.assertThat;
20-
2118
import java.util.Arrays;
2219
import java.util.Properties;
2320

@@ -30,6 +27,7 @@
3027
import org.eclipse.persistence.jpa.PersistenceProvider;
3128
import org.eclipse.persistence.sessions.Session;
3229
import org.junit.Test;
30+
import static org.junit.Assert.assertNotNull;
3331

3432
public class TestCanonicalMetaModel {
3533

@@ -61,7 +59,7 @@ public void testUseCanonicalModelFieldName() {
6159

6260
try (AutoCloseableEntityManagerFactory acemf = new AutoCloseableEntityManagerFactory(persistenceProvider,
6361
persistenceUnitInfo, properties)) {
64-
assertThat("The \"name\" field is properly initialized", DomainInterface_.name, notNullValue());
62+
assertNotNull("The \"name\" field is properly initialized", DomainInterface_.name);
6563
}
6664

6765
}

jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/criteria/TestDateTimeFunctions.java

+17-21
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
import java.time.ZoneOffset;
2525
import java.time.temporal.ChronoUnit;
2626
import java.util.List;
27-
import java.util.Locale;
2827
import java.util.TimeZone;
2928

30-
import jakarta.enterprise.inject.Typed;
3129
import jakarta.persistence.EntityManager;
3230
import jakarta.persistence.EntityManagerFactory;
3331
import jakarta.persistence.Query;
34-
import jakarta.persistence.TypedQuery;
3532
import jakarta.persistence.criteria.CriteriaBuilder;
3633
import jakarta.persistence.criteria.CriteriaQuery;
3734
import jakarta.persistence.criteria.CriteriaUpdate;
@@ -45,12 +42,12 @@
4542
import org.eclipse.persistence.logging.AbstractSessionLog;
4643
import org.eclipse.persistence.logging.SessionLog;
4744
import org.eclipse.persistence.sessions.Session;
48-
import org.hamcrest.MatcherAssert;
49-
import org.hamcrest.Matchers;
5045
import org.junit.After;
5146
import org.junit.Before;
5247
import org.junit.Test;
5348
import org.junit.runner.RunWith;
49+
import static org.junit.Assert.assertEquals;
50+
import static org.junit.Assert.assertTrue;
5451

5552
/**
5653
* Test {@code LocalTime}/{@code LocalDate}/{@code LocalDateTime} functions in CriteriaBuilder.
@@ -191,10 +188,10 @@ public void testCriteriaUpdateLocalTime() {
191188
long diffMilis = Duration.between(data.getTimeValue(), LocalTime.now().plusSeconds(dbOffset + 1)).toMillis();
192189
// Positive value means that test did not pass midnight.
193190
if (diffMilis > 0) {
194-
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
191+
assertTrue(diffMilis < 30000L);
195192
// Midnight pass correction.
196193
} else {
197-
MatcherAssert.assertThat(86400000L + diffMilis, Matchers.lessThan(30000L));
194+
assertTrue(86400000L + diffMilis < 30000L);
198195
}
199196
} finally {
200197
if (em.getTransaction().isActive()) {
@@ -226,9 +223,9 @@ public void testCriteriaUpdateLocalDate() {
226223
// Verify updated entity
227224
DateTimeEntity data = em.find(DateTimeEntity.class, 2);
228225
Period diff = Period.between(data.getDateValue(), LocalDate.now());
229-
MatcherAssert.assertThat(diff.getYears(), Matchers.equalTo(0));
230-
MatcherAssert.assertThat(diff.getMonths(), Matchers.equalTo(0));
231-
MatcherAssert.assertThat(diff.getDays(), Matchers.lessThan(2));
226+
assertEquals(0, diff.getYears());
227+
assertEquals(0, diff.getMonths());
228+
assertTrue(diff.getDays() < 2);
232229
} finally {
233230
if (em.getTransaction().isActive()) {
234231
em.getTransaction().rollback();
@@ -258,7 +255,7 @@ public void testCriteriaUpdateLocalDateTime() {
258255
// Verify updated entity
259256
DateTimeEntity data = em.find(DateTimeEntity.class, 3);
260257
long diffMilis = Duration.between(data.getDatetimeValue(), LocalDateTime.now().plusSeconds(dbOffset + 1)).toMillis();
261-
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
258+
assertTrue(diffMilis < 30000L);
262259
} finally {
263260
if (em.getTransaction().isActive()) {
264261
em.getTransaction().rollback();
@@ -306,7 +303,7 @@ public void testCriteriaQueryWhereLocalTimeReturnsEmpty() {
306303
cq.where(cb.and(cb.greaterThan(entity.get("timeValue"), cb.localTime()), cb.equal(entity.get("id"), 4)));
307304
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
308305
em.getTransaction().commit();
309-
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
306+
assertEquals(0, data.size());
310307
} finally {
311308
if (em.getTransaction().isActive()) {
312309
em.getTransaction().rollback();
@@ -354,7 +351,7 @@ public void testCriteriaQueryWhereLocalDateReturnsEmpty() {
354351
cq.where(cb.and(cb.greaterThan(entity.get("dateValue"), cb.localDate()), cb.equal(entity.get("id"), 4)));
355352
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
356353
em.getTransaction().commit();
357-
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
354+
assertEquals(0, data.size());
358355
} finally {
359356
if (em.getTransaction().isActive()) {
360357
em.getTransaction().rollback();
@@ -402,7 +399,7 @@ public void testCriteriaQueryWhereLocalDateTimeReturnsEmpty() {
402399
cq.where(cb.and(cb.greaterThan(entity.get("datetimeValue"), cb.localDateTime()), cb.equal(entity.get("id"), 4)));
403400
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
404401
em.getTransaction().commit();
405-
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
402+
assertEquals(0, data.size());
406403
} finally {
407404
if (em.getTransaction().isActive()) {
408405
em.getTransaction().rollback();
@@ -427,10 +424,10 @@ public void testCriteriaQuerySelectLocalTime() {
427424
long diffMilis = Duration.between(time, LocalTime.now().plusSeconds(1 + dbOffset)).toMillis();
428425
// Positive value means that test did not pass midnight.
429426
if (diffMilis > 0) {
430-
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
427+
assertTrue(diffMilis < 30000L);
431428
// Midnight pass correction.
432429
} else {
433-
MatcherAssert.assertThat(86400000L + diffMilis, Matchers.lessThan(30000L));
430+
assertTrue(86400000L + diffMilis < 30000L);
434431
}
435432
} finally {
436433
if (em.getTransaction().isActive()) {
@@ -454,9 +451,9 @@ public void testCriteriaQuerySelectLocalDate() {
454451
LocalDate date = em.createQuery(cq).getSingleResult();
455452
em.getTransaction().commit();
456453
Period diff = Period.between(date, LocalDate.now());
457-
MatcherAssert.assertThat(diff.getYears(), Matchers.equalTo(0));
458-
MatcherAssert.assertThat(diff.getMonths(), Matchers.equalTo(0));
459-
MatcherAssert.assertThat(diff.getDays(), Matchers.lessThan(2));
454+
assertEquals(0, diff.getYears());
455+
assertEquals(0, diff.getMonths());
456+
assertTrue(diff.getDays() < 2);
460457
} finally {
461458
if (em.getTransaction().isActive()) {
462459
em.getTransaction().rollback();
@@ -479,7 +476,7 @@ public void testCriteriaQuerySelectLocalDateTime() {
479476
LocalDateTime datetime = em.createQuery(cq).getSingleResult();
480477
em.getTransaction().commit();
481478
long diffMilis = Duration.between(datetime, LocalDateTime.now().plusSeconds(dbOffset + 1)).toMillis();
482-
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
479+
assertTrue(diffMilis < 30000L);
483480
} catch (Throwable t) {
484481
t.printStackTrace();
485482
throw t;
@@ -490,5 +487,4 @@ public void testCriteriaQuerySelectLocalDateTime() {
490487
em.close();
491488
}
492489
}
493-
494490
}

jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/criteria/TestMathFunctions.java

+25-40
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
3333
import org.eclipse.persistence.jpa.test.framework.Property;
3434
import org.eclipse.persistence.sessions.Session;
35-
import org.hamcrest.MatcherAssert;
36-
import org.hamcrest.Matchers;
3735
import org.junit.After;
3836
import org.junit.Assert;
3937
import org.junit.Assume;
4038
import org.junit.Before;
4139
import org.junit.Test;
4240
import org.junit.runner.RunWith;
41+
import static org.junit.Assert.assertEquals;
42+
import static org.junit.Assert.assertTrue;
4343

4444
/**
4545
* Test math functions in CriteriaBuilder.
@@ -469,12 +469,10 @@ public void testPower2MethodWithPositiveDoubleBase() {
469469
try (final EntityManager em = emf.createEntityManager()) {
470470
Double result = callPower(em, 2, 3, "doubleValue");
471471
if (emf.unwrap(Session.class).getPlatform().isDerby()) {
472-
MatcherAssert.assertThat(
473-
Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result), Matchers.lessThan(0.0000001D));
472+
assertTrue(Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result) < 0.0000001D);
474473
// Oracle DB result is less accurate
475474
} else if (emf.unwrap(Session.class).getPlatform().isOracle()) {
476-
MatcherAssert.assertThat(
477-
Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result), Matchers.lessThan(0.0001D));
475+
assertTrue(Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result) < 0.0001D);
478476
} else {
479477
Assert.assertEquals(
480478
Double.valueOf(Math.pow(NUMBER[3].getDoubleValue(), 2)), result);
@@ -503,11 +501,9 @@ public void testPower2MethodWithNegativeDoubleBase() {
503501
Double result = callPower(em, 2, 4, "doubleValue");
504502
// Oracle DB result is less accurate
505503
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
506-
MatcherAssert.assertThat(
507-
Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 2) - result), Matchers.lessThan(0.0001D));
504+
assertTrue(Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 2) - result) < 0.0001D);
508505
} else {
509-
Assert.assertEquals(
510-
Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 2)), result);
506+
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 2)), result);
511507
}
512508
}
513509
}
@@ -519,8 +515,7 @@ public void testPower3MethodWithNegativeLongBase() {
519515
Assume.assumeFalse(emf.unwrap(Session.class).getPlatform().isDerby());
520516
try (final EntityManager em = emf.createEntityManager()) {
521517
Double result = callPower(em, 3, 4, "longValue");
522-
Assert.assertEquals(
523-
Double.valueOf(Math.pow(NUMBER[4].getLongValue(), 3)), result);
518+
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getLongValue(), 3)), result);
524519
}
525520
}
526521

@@ -533,11 +528,9 @@ public void testPower3MethodWithNegativeDoubleBase() {
533528
Double result = callPower(em, 3, 4, "doubleValue");
534529
// Oracle DB result is less accurate
535530
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
536-
MatcherAssert.assertThat(
537-
Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 3) - result), Matchers.lessThan(0.0000001D));
531+
assertTrue(Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 3) - result) < 0.0000001D);
538532
} else {
539-
Assert.assertEquals(
540-
Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 3)), result);
533+
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 3)), result);
541534
}
542535
}
543536
}
@@ -560,12 +553,9 @@ public void testPowerMethodWithPositiveArgs() {
560553
try (final EntityManager em = emf.createEntityManager()) {
561554
Double result = callExprPower(em, 7);
562555
if (emf.unwrap(Session.class).getPlatform().isDerby() || emf.unwrap(Session.class).getPlatform().isOracle()) {
563-
MatcherAssert.assertThat(
564-
Math.abs(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue()) - result),
565-
Matchers.lessThan(0.0000001d));
556+
assertTrue(Math.abs(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue()) - result) < 0.0000001d);
566557
} else {
567-
Assert.assertEquals(
568-
Double.valueOf(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue())), result);
558+
assertEquals(Double.valueOf(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue())), result);
569559
}
570560
}
571561
}
@@ -611,10 +601,9 @@ public void testRoundDoubleMethodWithPositive() {
611601
Double result = callDoubleRound(em, 6,8);
612602
// Oracle DB result is less accurate
613603
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
614-
MatcherAssert.assertThat(
615-
Math.abs(Double.valueOf(44.754238D) - result), Matchers.lessThan(0.0001D));
604+
assertTrue(Math.abs(Double.valueOf(44.754238D) - result) < 0.0001D);
616605
} else {
617-
Assert.assertEquals(Double.valueOf(44.754238D), result);
606+
assertEquals(Double.valueOf(44.754238D), result);
618607
}
619608
}
620609
}
@@ -626,10 +615,9 @@ public void testRoundFloatMethodWithPositive() {
626615
Float result = callFloatRound(em, 6,8);
627616
// Oracle DB result is less accurate
628617
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
629-
MatcherAssert.assertThat(
630-
Math.abs(Float.valueOf(44.754238F) - result), Matchers.lessThan(0.0001F));
618+
assertTrue(Math.abs(Float.valueOf(44.754238F) - result) < 0.0001F);
631619
} else {
632-
Assert.assertEquals(Float.valueOf(44.754238F), result);
620+
assertEquals(Float.valueOf(44.754238F), result);
633621
}
634622
}
635623
}
@@ -641,10 +629,9 @@ public void testRoundDoubleMethodWithNegative() {
641629
Double result = callDoubleRound(em, 6, 9);
642630
// Oracle DB result is less accurate
643631
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
644-
MatcherAssert.assertThat(
645-
Math.abs(Double.valueOf(-214.245732D) - result), Matchers.lessThan(0.0001D));
632+
assertTrue(Math.abs(Double.valueOf(-214.245732D) - result) < 0.0001D);
646633
} else {
647-
Assert.assertEquals(Double.valueOf(-214.245732D), result);
634+
assertEquals(Double.valueOf(-214.245732D), result);
648635
}
649636
}
650637
}
@@ -656,10 +643,9 @@ public void testRoundFloatMethodWithNegative() {
656643
Float result = callFloatRound(em, 6, 9);
657644
// Oracle DB result is less accurate
658645
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
659-
MatcherAssert.assertThat(
660-
Math.abs(Float.valueOf(-214.245732F) - result), Matchers.lessThan(0.0001F));
646+
assertTrue(Math.abs(Float.valueOf(-214.245732F) - result) < 0.0001F);
661647
} else {
662-
Assert.assertEquals(Float.valueOf(-214.245732F), result);
648+
assertEquals(Float.valueOf(-214.245732F), result);
663649
}
664650
}
665651
}
@@ -674,8 +660,8 @@ public void testCeilingKeepBigDecimalParamType() {
674660
cq.select(cb.ceiling(number.get("bdValue")));
675661
cq.where(cb.equal(number.get("id"), 8));
676662
Number result = em.createQuery(cq).getSingleResult();
677-
MatcherAssert.assertThat(result, Matchers.is(Matchers.instanceOf(BigDecimal.class)));
678-
MatcherAssert.assertThat(result.doubleValue(), Matchers.equalTo(Math.ceil(NUMBER[8].getBdValue().doubleValue())));
663+
assertTrue(result instanceof BigDecimal);
664+
assertEquals(Math.ceil(NUMBER[8].getBdValue().doubleValue()), result.doubleValue(), 0);
679665
}
680666
}
681667

@@ -689,8 +675,8 @@ public void testFloorKeepBigDecimalParamType() {
689675
cq.select(cb.floor(number.get("bdValue")));
690676
cq.where(cb.equal(number.get("id"), 8));
691677
Number result = em.createQuery(cq).getSingleResult();
692-
MatcherAssert.assertThat(result, Matchers.is(Matchers.instanceOf(BigDecimal.class)));
693-
MatcherAssert.assertThat(result.doubleValue(), Matchers.equalTo(Math.floor(NUMBER[8].getBdValue().doubleValue())));
678+
assertTrue(result instanceof BigDecimal);
679+
assertEquals(result.doubleValue(), Math.floor(NUMBER[8].getBdValue().doubleValue()), 0);
694680
}
695681
}
696682

@@ -704,9 +690,8 @@ public void testRoundKeepBigDecimalParamType() {
704690
cq.select(cb.round(number.get("bdValue"), 1));
705691
cq.where(cb.equal(number.get("id"), 8));
706692
Number result = em.createQuery(cq).getSingleResult();
707-
MatcherAssert.assertThat(result, Matchers.is(Matchers.instanceOf(BigDecimal.class)));
708-
MatcherAssert.assertThat(result.doubleValue(), Matchers.equalTo(Double.valueOf(Math.round(NUMBER[8].getBdValue().doubleValue()*10))/10));
693+
assertTrue(result instanceof BigDecimal);
694+
assertEquals(result.doubleValue(), Double.valueOf(Math.round(NUMBER[8].getBdValue().doubleValue()*10))/10, 0);
709695
}
710696
}
711-
712697
}

jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/criteria/TestSimpleCase.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
import org.eclipse.persistence.jpa.test.framework.Emf;
3131
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
3232
import org.eclipse.persistence.jpa.test.framework.Property;
33-
import org.hamcrest.MatcherAssert;
34-
import org.hamcrest.Matchers;
3533
import org.junit.After;
3634
import org.junit.Before;
3735
import org.junit.Test;
3836
import org.junit.runner.RunWith;
37+
import static org.junit.Assert.assertEquals;
3938

4039
/**
4140
* Test new API 3.1.0 when methods of SimpleCase subclass of CriteriaBuilder.
@@ -114,7 +113,7 @@ public void testWhenExpressionValue() {
114113
.otherwise(0);
115114
cq.where(cb.equal(entity.get("doubleValue"), selectCase));
116115
List<NumberEntity> result = em.createQuery(cq).getResultList();
117-
MatcherAssert.assertThat(result.size(), Matchers.equalTo(3));
116+
assertEquals(3, result.size());
118117
} catch (Throwable t) {
119118
t.printStackTrace();
120119
throw t;
@@ -136,11 +135,10 @@ public void testWhenExpressionExpression() {
136135
.otherwise(0);
137136
cq.where(cb.equal(entity.get("doubleValue"), selectCase));
138137
List<NumberEntity> result = em.createQuery(cq).getResultList();
139-
MatcherAssert.assertThat(result.size(), Matchers.equalTo(3));
138+
assertEquals(3, result.size());
140139
} catch (Throwable t) {
141140
t.printStackTrace();
142141
throw t;
143142
}
144143
}
145-
146144
}

0 commit comments

Comments
 (0)