diff --git a/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/AnnotationUtils.java b/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/AnnotationUtils.java index 3284705..946d028 100644 --- a/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/AnnotationUtils.java +++ b/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/AnnotationUtils.java @@ -7,12 +7,7 @@ public final class AnnotationUtils { private AnnotationUtils() { } public static final Annotation toAnnotation(Class annotationType) { - return new Annotation() { - @Override - public Class annotationType() { - return annotationType; - } - }; + return () -> annotationType; } } diff --git a/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/primitive/NumberProducer.java b/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/primitive/NumberProducer.java index 91f5131..314ccc3 100644 --- a/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/primitive/NumberProducer.java +++ b/md-jee-cdi/src/main/java/com/github/matschieu/jakartaee/cdi/primitive/NumberProducer.java @@ -4,12 +4,14 @@ public class NumberProducer { + private static final java.util.Random RANDOM = new java.util.Random(); + // A producer can be a field // It must be a default-access, public, protected or private, field of a managed bean class. // A producer field may be either static or non-static. @Produces @Null - private Integer nullInteger = null; + private final Integer nullInteger = null; // A producer method must be a default-access, public, protected or private, non-abstract method of a managed bean class // A producer method may be either static or non-static @@ -17,14 +19,14 @@ public class NumberProducer { @Produces @Random public Integer getRandomInteger() { - return Integer.valueOf((new java.util.Random()).nextInt()); + return Integer.valueOf(RANDOM.nextInt()); } // A producer can also return a primitive type @Produces @Random public static double getRandomInt() { - return 1.0 * (new java.util.Random()).nextInt(); + return 1.0 * RANDOM.nextInt(); } } diff --git a/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/dummy/IntIncrementInterceptor.java b/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/dummy/IntIncrementInterceptor.java index 02aaf46..d93b69b 100644 --- a/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/dummy/IntIncrementInterceptor.java +++ b/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/dummy/IntIncrementInterceptor.java @@ -11,8 +11,8 @@ public class IntIncrementInterceptor { public Object interceptOrder(final InvocationContext ctx) throws Exception { System.out.println(this.getClass().getSimpleName() + ": Intercept " + ctx.getMethod().getName()); final Object output = ctx.proceed(); - if (output instanceof Integer) { - return ((Integer) output).intValue() + 1; + if (output instanceof final Integer integer) { + return integer.intValue() + 1; } return output; } diff --git a/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/validation/ValidationInterceptor.java b/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/validation/ValidationInterceptor.java index 47bcd13..e6f091e 100644 --- a/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/validation/ValidationInterceptor.java +++ b/md-jee-interceptor/src/main/java/com/github/matschieu/jee/interceptor/validation/ValidationInterceptor.java @@ -11,7 +11,7 @@ @Interceptor public class ValidationInterceptor { - private void checkObject(final Object obj) throws Exception { + private void checkObject(final Object obj) throws IllegalArgumentException, IllegalAccessException, NullElementException { if ((obj == null) || (obj instanceof String)) { return; } @@ -27,7 +27,7 @@ private void checkObject(final Object obj) throws Exception { } } - private void checkFieldAnnotation(final String fieldName, final Annotation[] annotations, final Object value) throws Exception { + private void checkFieldAnnotation(final String fieldName, final Annotation[] annotations, final Object value) throws NullElementException { for (final Annotation annotation : annotations) { if (annotation.annotationType() == NotNullElement.class && value == null) { throw new NullElementException(fieldName + " is null"); diff --git a/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/dummy/MyServiceTest.java b/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/dummy/MyServiceTest.java index af88fb7..a8e4051 100644 --- a/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/dummy/MyServiceTest.java +++ b/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/dummy/MyServiceTest.java @@ -9,7 +9,7 @@ import jakarta.inject.Inject; @EnableWeld -public class MyServiceTest { +class MyServiceTest { @WeldSetup public WeldInitiator weld = WeldInitiator.from(MyService.class, MyServiceImpl.class).build(); @@ -18,7 +18,7 @@ public class MyServiceTest { private MyService myService; @Test - public void testMyService() { + void testMyService() { Assertions.assertEquals(2, this.myService.getInt()); Assertions.assertEquals(Integer.valueOf(2), this.myService.getInteger()); Assertions.assertEquals("{[MyString]}", this.myService.getString()); diff --git a/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/validation/ResourceServiceTest.java b/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/validation/ResourceServiceTest.java index 08953ac..deb01bf 100644 --- a/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/validation/ResourceServiceTest.java +++ b/md-jee-interceptor/src/test/java/com/github/matschieu/jee/interceptor/validation/ResourceServiceTest.java @@ -11,7 +11,7 @@ import jakarta.inject.Inject; @EnableWeld -public class ResourceServiceTest { +class ResourceServiceTest { @WeldSetup public WeldInitiator weld = WeldInitiator.from(ResourceService.class, ResourceServiceImpl.class).build(); @@ -20,7 +20,7 @@ public class ResourceServiceTest { private ResourceService resourceService; @Test - public void testMyServiceCreateResource1() { + void testMyServiceCreateResource1() { try { this.resourceService.createResource(null, "", ""); fail(); @@ -41,7 +41,7 @@ public void testMyServiceCreateResource1() { } @Test - public void testMyServiceCreateResource2() { + void testMyServiceCreateResource2() { try { this.resourceService.createResource(new Resource(null, "", "")); fail(); @@ -62,7 +62,7 @@ public void testMyServiceCreateResource2() { } @Test - public void testMyServiceGetResource() { + void testMyServiceGetResource() { Resource resource; try { @@ -82,7 +82,7 @@ public void testMyServiceGetResource() { } @Test - public void testMyServiceDeleteResource() { + void testMyServiceDeleteResource() { try { this.resourceService.deleteResource(null); fail();