Home » Java » Enterprise Java

Enterprise Java

Testing with Mockito

1) Register MockitoExtension @ExtendWith(MockitoExtension.class) class ObjectTest { static final Long ID = 1L; 2) Create the mock @Mock private ObjectRepo mockRepo; 3) Inject the mock @InjectMocks private ObjectService objectService; @Test void whenfindByIdThenReturnResult() { var objectDAO = new ObjectDAO(); objectDAO.setId(ID); 4) Define the behavior when(mockRepo.findById(any(Long.class))).thenReturn(Optional.of(objectDAO)); 5) Test var result = ObjectService.findById(ID); 6) Verify verify(mockRepo, times(1)).findById(any(Long.class)); 7) Validate assertAll( () -> assertNotNull(result), ...

Read More »

Spring Injection Types

spring-interview-questions-answers

Spring supports three types of dependency injections: Constructor injection @Component public class SecondBeanImpl implements SecondBean { private FirstBean firstBean; @Autowired public SecondBeanImpl(FirstBean firstBean) { this.firstBean = firstBean; } } That is similar to: FirstBean firstBean = new FirstBeanImpl(); SecondBean secondBean = new SecondBeanImpl(firstBean); This type of dependency injection instantiates and initializes the object. In this approach, beans are immutable and ...

Read More »

Apache Lucene performance on 128-core AMD Ryzen Threadripper 3990X

Almost a decade ago, I started running Lucene’s nightly benchmarks, and have been trying with mixed success to keep them running every night, through the numerous amazing changes relentlessly developed by the passionate Lucene community. The benchmarks run on the tip of Lucene’s mainline branch each night, which is understandably a volatile and high-velocity code base. Sure, Lucene’s wonderful randomized unit ...

Read More »

Content-Security-Policy Nonce with Spring Security

spring-interview-questions-answers

Content-Security-Policy is important for web security. Yet, it’s not mainstream yet, it’s syntax is hard, it’s rather prohibitive and tools rarely have flexible support for it. While Spring Security does have a built-in Content Security Policy (CSP) configuration, it allows you to specify the policy a a string, not build it dynamically. And in some cases you need more than that. ...

Read More »

Spring Cloud Sleuth 3.0.0 released

spring-interview-questions-answers

With the release of the Spring Cloud 2020.0.0 (aka Ilford) release train we’re more than happy to announce the general availability of Spring Cloud Sleuth 3.0.0. In this blog post I’ll describe the most notable released features (in order of their release dates). Removes Deprecated Modules Removes ribbon, zuul, hystrix and Spring Cloud Aws support. Check this PR for more ...

Read More »

OAuth2 Bearer Token Usage

java-interview-questions-answers

I have immersed myself in the digital identity space for the past few years. A good chunk of this work involves reading (and sometimes creating) specifications, as you can imagine. It is critical that they be written in such a way that two independent parties can build interoperable implementations without relying on each other’s code. With this in mind, let’s ...

Read More »

Jmix – the future of CUBA Platform

java-interview-questions-answers

Jmix is the new name and the new major release of CUBA Platform. It is now in Preview and we are aiming to release Stable version in Q2 2021. Key features: Spring Boot as a core technology Decomposition into separate pluggable modules (data, security, audit, etc.) A new approach to data model definition Database update process based on Liquibase Deployment ...

Read More »

Jenkins: Automating your delivery pipeline

In this post, we are going to create a Jenkins pipeline for a Java Spring project using Maven and Git: Accessing Jenkins dashboard and configuring Maven in Jenkins: Click on “Manage Jenkins” and then in “Global Tool Configuration” Add a Maven installation and provide a name for it. Click on Save. Creation of our first build job in Jenkins for ...

Read More »

Spring Cloud Contract 3.0.0 released

java-interview-questions-answers

With the release of the Spring Cloud 2020.0.0 (aka Ilford) release train we’re more than happy to announce the general availability of Spring Cloud Contract 3.0.0. In this blog post I’ll describe the most notable released features (in order of their release dates). Incremental Test Generation for Maven With the Incremental Test Generation for Maven we’re generating tests, stubs and ...

Read More »