32
32
import org .eclipse .persistence .jpa .test .framework .EmfRunner ;
33
33
import org .eclipse .persistence .jpa .test .framework .Property ;
34
34
import org .eclipse .persistence .sessions .Session ;
35
- import org .hamcrest .MatcherAssert ;
36
- import org .hamcrest .Matchers ;
37
35
import org .junit .After ;
38
36
import org .junit .Assert ;
39
37
import org .junit .Assume ;
40
38
import org .junit .Before ;
41
39
import org .junit .Test ;
42
40
import org .junit .runner .RunWith ;
41
+ import static org .junit .Assert .assertEquals ;
42
+ import static org .junit .Assert .assertTrue ;
43
43
44
44
/**
45
45
* Test math functions in CriteriaBuilder.
@@ -469,12 +469,10 @@ public void testPower2MethodWithPositiveDoubleBase() {
469
469
try (final EntityManager em = emf .createEntityManager ()) {
470
470
Double result = callPower (em , 2 , 3 , "doubleValue" );
471
471
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 );
474
473
// Oracle DB result is less accurate
475
474
} 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 );
478
476
} else {
479
477
Assert .assertEquals (
480
478
Double .valueOf (Math .pow (NUMBER [3 ].getDoubleValue (), 2 )), result );
@@ -503,11 +501,9 @@ public void testPower2MethodWithNegativeDoubleBase() {
503
501
Double result = callPower (em , 2 , 4 , "doubleValue" );
504
502
// Oracle DB result is less accurate
505
503
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 );
508
505
} 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 );
511
507
}
512
508
}
513
509
}
@@ -519,8 +515,7 @@ public void testPower3MethodWithNegativeLongBase() {
519
515
Assume .assumeFalse (emf .unwrap (Session .class ).getPlatform ().isDerby ());
520
516
try (final EntityManager em = emf .createEntityManager ()) {
521
517
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 );
524
519
}
525
520
}
526
521
@@ -533,11 +528,9 @@ public void testPower3MethodWithNegativeDoubleBase() {
533
528
Double result = callPower (em , 3 , 4 , "doubleValue" );
534
529
// Oracle DB result is less accurate
535
530
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 );
538
532
} 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 );
541
534
}
542
535
}
543
536
}
@@ -560,12 +553,9 @@ public void testPowerMethodWithPositiveArgs() {
560
553
try (final EntityManager em = emf .createEntityManager ()) {
561
554
Double result = callExprPower (em , 7 );
562
555
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 );
566
557
} 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 );
569
559
}
570
560
}
571
561
}
@@ -611,10 +601,9 @@ public void testRoundDoubleMethodWithPositive() {
611
601
Double result = callDoubleRound (em , 6 ,8 );
612
602
// Oracle DB result is less accurate
613
603
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 );
616
605
} else {
617
- Assert . assertEquals (Double .valueOf (44.754238D ), result );
606
+ assertEquals (Double .valueOf (44.754238D ), result );
618
607
}
619
608
}
620
609
}
@@ -626,10 +615,9 @@ public void testRoundFloatMethodWithPositive() {
626
615
Float result = callFloatRound (em , 6 ,8 );
627
616
// Oracle DB result is less accurate
628
617
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 );
631
619
} else {
632
- Assert . assertEquals (Float .valueOf (44.754238F ), result );
620
+ assertEquals (Float .valueOf (44.754238F ), result );
633
621
}
634
622
}
635
623
}
@@ -641,10 +629,9 @@ public void testRoundDoubleMethodWithNegative() {
641
629
Double result = callDoubleRound (em , 6 , 9 );
642
630
// Oracle DB result is less accurate
643
631
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 );
646
633
} else {
647
- Assert . assertEquals (Double .valueOf (-214.245732D ), result );
634
+ assertEquals (Double .valueOf (-214.245732D ), result );
648
635
}
649
636
}
650
637
}
@@ -656,10 +643,9 @@ public void testRoundFloatMethodWithNegative() {
656
643
Float result = callFloatRound (em , 6 , 9 );
657
644
// Oracle DB result is less accurate
658
645
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 );
661
647
} else {
662
- Assert . assertEquals (Float .valueOf (-214.245732F ), result );
648
+ assertEquals (Float .valueOf (-214.245732F ), result );
663
649
}
664
650
}
665
651
}
@@ -674,8 +660,8 @@ public void testCeilingKeepBigDecimalParamType() {
674
660
cq .select (cb .ceiling (number .get ("bdValue" )));
675
661
cq .where (cb .equal (number .get ("id" ), 8 ));
676
662
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 );
679
665
}
680
666
}
681
667
@@ -689,8 +675,8 @@ public void testFloorKeepBigDecimalParamType() {
689
675
cq .select (cb .floor (number .get ("bdValue" )));
690
676
cq .where (cb .equal (number .get ("id" ), 8 ));
691
677
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 );
694
680
}
695
681
}
696
682
@@ -704,9 +690,8 @@ public void testRoundKeepBigDecimalParamType() {
704
690
cq .select (cb .round (number .get ("bdValue" ), 1 ));
705
691
cq .where (cb .equal (number .get ("id" ), 8 ));
706
692
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 );
709
695
}
710
696
}
711
-
712
697
}
0 commit comments