Skip to content

Commit

Permalink
[master] Hamcrest dependency removal (#1689)
Browse files Browse the repository at this point in the history
Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Sep 6, 2022
1 parent b4090a9 commit e5f86dc
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 245 deletions.
5 changes: 0 additions & 5 deletions jpa/eclipselink.jpa.nosql.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!--Required for JPA server test server-test-jpa21-sessionbean.-->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</dependency>
<!--Other modules-->
<dependency>
<groupId>org.eclipse.persistence</groupId>
Expand Down
6 changes: 0 additions & 6 deletions jpa/eclipselink.jpa.test.jse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -15,9 +15,6 @@
// - #539822: JPA Canonical metamodel not processing metamodelMappedSuperclasses
package org.eclipse.persistence.jpa.test.canonical;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;
import java.util.Properties;

Expand All @@ -30,6 +27,7 @@
import org.eclipse.persistence.jpa.PersistenceProvider;
import org.eclipse.persistence.sessions.Session;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;

public class TestCanonicalMetaModel {

Expand Down Expand Up @@ -61,7 +59,7 @@ public void testUseCanonicalModelFieldName() {

try (AutoCloseableEntityManagerFactory acemf = new AutoCloseableEntityManagerFactory(persistenceProvider,
persistenceUnitInfo, properties)) {
assertThat("The \"name\" field is properly initialized", DomainInterface_.name, notNullValue());
assertNotNull("The \"name\" field is properly initialized", DomainInterface_.name);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import jakarta.enterprise.inject.Typed;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
Expand All @@ -45,12 +42,12 @@
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.sessions.Session;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test {@code LocalTime}/{@code LocalDate}/{@code LocalDateTime} functions in CriteriaBuilder.
Expand Down Expand Up @@ -191,10 +188,10 @@ public void testCriteriaUpdateLocalTime() {
long diffMilis = Duration.between(data.getTimeValue(), LocalTime.now().plusSeconds(dbOffset + 1)).toMillis();
// Positive value means that test did not pass midnight.
if (diffMilis > 0) {
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
assertTrue(diffMilis < 30000L);
// Midnight pass correction.
} else {
MatcherAssert.assertThat(86400000L + diffMilis, Matchers.lessThan(30000L));
assertTrue(86400000L + diffMilis < 30000L);
}
} finally {
if (em.getTransaction().isActive()) {
Expand Down Expand Up @@ -226,9 +223,9 @@ public void testCriteriaUpdateLocalDate() {
// Verify updated entity
DateTimeEntity data = em.find(DateTimeEntity.class, 2);
Period diff = Period.between(data.getDateValue(), LocalDate.now());
MatcherAssert.assertThat(diff.getYears(), Matchers.equalTo(0));
MatcherAssert.assertThat(diff.getMonths(), Matchers.equalTo(0));
MatcherAssert.assertThat(diff.getDays(), Matchers.lessThan(2));
assertEquals(0, diff.getYears());
assertEquals(0, diff.getMonths());
assertTrue(diff.getDays() < 2);
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand Down Expand Up @@ -258,7 +255,7 @@ public void testCriteriaUpdateLocalDateTime() {
// Verify updated entity
DateTimeEntity data = em.find(DateTimeEntity.class, 3);
long diffMilis = Duration.between(data.getDatetimeValue(), LocalDateTime.now().plusSeconds(dbOffset + 1)).toMillis();
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
assertTrue(diffMilis < 30000L);
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand Down Expand Up @@ -306,7 +303,7 @@ public void testCriteriaQueryWhereLocalTimeReturnsEmpty() {
cq.where(cb.and(cb.greaterThan(entity.get("timeValue"), cb.localTime()), cb.equal(entity.get("id"), 4)));
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
em.getTransaction().commit();
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
assertEquals(0, data.size());
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand Down Expand Up @@ -354,7 +351,7 @@ public void testCriteriaQueryWhereLocalDateReturnsEmpty() {
cq.where(cb.and(cb.greaterThan(entity.get("dateValue"), cb.localDate()), cb.equal(entity.get("id"), 4)));
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
em.getTransaction().commit();
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
assertEquals(0, data.size());
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand Down Expand Up @@ -402,7 +399,7 @@ public void testCriteriaQueryWhereLocalDateTimeReturnsEmpty() {
cq.where(cb.and(cb.greaterThan(entity.get("datetimeValue"), cb.localDateTime()), cb.equal(entity.get("id"), 4)));
List<DateTimeEntity> data = em.createQuery(cq).getResultList();
em.getTransaction().commit();
MatcherAssert.assertThat(data.size(), Matchers.equalTo(0));
assertEquals(0, data.size());
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand All @@ -427,10 +424,10 @@ public void testCriteriaQuerySelectLocalTime() {
long diffMilis = Duration.between(time, LocalTime.now().plusSeconds(1 + dbOffset)).toMillis();
// Positive value means that test did not pass midnight.
if (diffMilis > 0) {
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
assertTrue(diffMilis < 30000L);
// Midnight pass correction.
} else {
MatcherAssert.assertThat(86400000L + diffMilis, Matchers.lessThan(30000L));
assertTrue(86400000L + diffMilis < 30000L);
}
} finally {
if (em.getTransaction().isActive()) {
Expand All @@ -454,9 +451,9 @@ public void testCriteriaQuerySelectLocalDate() {
LocalDate date = em.createQuery(cq).getSingleResult();
em.getTransaction().commit();
Period diff = Period.between(date, LocalDate.now());
MatcherAssert.assertThat(diff.getYears(), Matchers.equalTo(0));
MatcherAssert.assertThat(diff.getMonths(), Matchers.equalTo(0));
MatcherAssert.assertThat(diff.getDays(), Matchers.lessThan(2));
assertEquals(0, diff.getYears());
assertEquals(0, diff.getMonths());
assertTrue(diff.getDays() < 2);
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
Expand All @@ -479,7 +476,7 @@ public void testCriteriaQuerySelectLocalDateTime() {
LocalDateTime datetime = em.createQuery(cq).getSingleResult();
em.getTransaction().commit();
long diffMilis = Duration.between(datetime, LocalDateTime.now().plusSeconds(dbOffset + 1)).toMillis();
MatcherAssert.assertThat(diffMilis, Matchers.lessThan(30000L));
assertTrue(diffMilis < 30000L);
} catch (Throwable t) {
t.printStackTrace();
throw t;
Expand All @@ -490,5 +487,4 @@ public void testCriteriaQuerySelectLocalDateTime() {
em.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
import org.eclipse.persistence.jpa.test.framework.Property;
import org.eclipse.persistence.sessions.Session;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test math functions in CriteriaBuilder.
Expand Down Expand Up @@ -469,12 +469,10 @@ public void testPower2MethodWithPositiveDoubleBase() {
try (final EntityManager em = emf.createEntityManager()) {
Double result = callPower(em, 2, 3, "doubleValue");
if (emf.unwrap(Session.class).getPlatform().isDerby()) {
MatcherAssert.assertThat(
Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result), Matchers.lessThan(0.0000001D));
assertTrue(Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result) < 0.0000001D);
// Oracle DB result is less accurate
} else if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result), Matchers.lessThan(0.0001D));
assertTrue(Math.abs(Math.pow(NUMBER[3].getDoubleValue(), 2) - result) < 0.0001D);
} else {
Assert.assertEquals(
Double.valueOf(Math.pow(NUMBER[3].getDoubleValue(), 2)), result);
Expand Down Expand Up @@ -503,11 +501,9 @@ public void testPower2MethodWithNegativeDoubleBase() {
Double result = callPower(em, 2, 4, "doubleValue");
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 2) - result), Matchers.lessThan(0.0001D));
assertTrue(Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 2) - result) < 0.0001D);
} else {
Assert.assertEquals(
Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 2)), result);
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 2)), result);
}
}
}
Expand All @@ -519,8 +515,7 @@ public void testPower3MethodWithNegativeLongBase() {
Assume.assumeFalse(emf.unwrap(Session.class).getPlatform().isDerby());
try (final EntityManager em = emf.createEntityManager()) {
Double result = callPower(em, 3, 4, "longValue");
Assert.assertEquals(
Double.valueOf(Math.pow(NUMBER[4].getLongValue(), 3)), result);
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getLongValue(), 3)), result);
}
}

Expand All @@ -533,11 +528,9 @@ public void testPower3MethodWithNegativeDoubleBase() {
Double result = callPower(em, 3, 4, "doubleValue");
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 3) - result), Matchers.lessThan(0.0000001D));
assertTrue(Math.abs(Math.pow(NUMBER[4].getDoubleValue(), 3) - result) < 0.0000001D);
} else {
Assert.assertEquals(
Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 3)), result);
assertEquals(Double.valueOf(Math.pow(NUMBER[4].getDoubleValue(), 3)), result);
}
}
}
Expand All @@ -560,12 +553,9 @@ public void testPowerMethodWithPositiveArgs() {
try (final EntityManager em = emf.createEntityManager()) {
Double result = callExprPower(em, 7);
if (emf.unwrap(Session.class).getPlatform().isDerby() || emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue()) - result),
Matchers.lessThan(0.0000001d));
assertTrue(Math.abs(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue()) - result) < 0.0000001d);
} else {
Assert.assertEquals(
Double.valueOf(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue())), result);
assertEquals(Double.valueOf(Math.pow(NUMBER[7].getDoubleValue(), NUMBER[7].getLongValue())), result);
}
}
}
Expand Down Expand Up @@ -611,10 +601,9 @@ public void testRoundDoubleMethodWithPositive() {
Double result = callDoubleRound(em, 6,8);
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Double.valueOf(44.754238D) - result), Matchers.lessThan(0.0001D));
assertTrue(Math.abs(Double.valueOf(44.754238D) - result) < 0.0001D);
} else {
Assert.assertEquals(Double.valueOf(44.754238D), result);
assertEquals(Double.valueOf(44.754238D), result);
}
}
}
Expand All @@ -626,10 +615,9 @@ public void testRoundFloatMethodWithPositive() {
Float result = callFloatRound(em, 6,8);
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Float.valueOf(44.754238F) - result), Matchers.lessThan(0.0001F));
assertTrue(Math.abs(Float.valueOf(44.754238F) - result) < 0.0001F);
} else {
Assert.assertEquals(Float.valueOf(44.754238F), result);
assertEquals(Float.valueOf(44.754238F), result);
}
}
}
Expand All @@ -641,10 +629,9 @@ public void testRoundDoubleMethodWithNegative() {
Double result = callDoubleRound(em, 6, 9);
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Double.valueOf(-214.245732D) - result), Matchers.lessThan(0.0001D));
assertTrue(Math.abs(Double.valueOf(-214.245732D) - result) < 0.0001D);
} else {
Assert.assertEquals(Double.valueOf(-214.245732D), result);
assertEquals(Double.valueOf(-214.245732D), result);
}
}
}
Expand All @@ -656,10 +643,9 @@ public void testRoundFloatMethodWithNegative() {
Float result = callFloatRound(em, 6, 9);
// Oracle DB result is less accurate
if (emf.unwrap(Session.class).getPlatform().isOracle()) {
MatcherAssert.assertThat(
Math.abs(Float.valueOf(-214.245732F) - result), Matchers.lessThan(0.0001F));
assertTrue(Math.abs(Float.valueOf(-214.245732F) - result) < 0.0001F);
} else {
Assert.assertEquals(Float.valueOf(-214.245732F), result);
assertEquals(Float.valueOf(-214.245732F), result);
}
}
}
Expand All @@ -674,8 +660,8 @@ public void testCeilingKeepBigDecimalParamType() {
cq.select(cb.ceiling(number.get("bdValue")));
cq.where(cb.equal(number.get("id"), 8));
Number result = em.createQuery(cq).getSingleResult();
MatcherAssert.assertThat(result, Matchers.is(Matchers.instanceOf(BigDecimal.class)));
MatcherAssert.assertThat(result.doubleValue(), Matchers.equalTo(Math.ceil(NUMBER[8].getBdValue().doubleValue())));
assertTrue(result instanceof BigDecimal);
assertEquals(Math.ceil(NUMBER[8].getBdValue().doubleValue()), result.doubleValue(), 0);
}
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import org.eclipse.persistence.jpa.test.framework.Emf;
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
import org.eclipse.persistence.jpa.test.framework.Property;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;

/**
* Test new API 3.1.0 when methods of SimpleCase subclass of CriteriaBuilder.
Expand Down Expand Up @@ -114,7 +113,7 @@ public void testWhenExpressionValue() {
.otherwise(0);
cq.where(cb.equal(entity.get("doubleValue"), selectCase));
List<NumberEntity> result = em.createQuery(cq).getResultList();
MatcherAssert.assertThat(result.size(), Matchers.equalTo(3));
assertEquals(3, result.size());
} catch (Throwable t) {
t.printStackTrace();
throw t;
Expand All @@ -136,11 +135,10 @@ public void testWhenExpressionExpression() {
.otherwise(0);
cq.where(cb.equal(entity.get("doubleValue"), selectCase));
List<NumberEntity> result = em.createQuery(cq).getResultList();
MatcherAssert.assertThat(result.size(), Matchers.equalTo(3));
assertEquals(3, result.size());
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}

}

0 comments on commit e5f86dc

Please sign in to comment.