Arquillian Example for CDI Dependency Injection

Arquillian is a platform which provides integration tests by deploying, running containers so that we can easily use cdi beans in tests. In this tutorial we will see how to inject and use cdi beans in test classes by running Arquillian.

As a first step we have to add Arquillian core library in our pom.xml in the dependencyManagement block. Well it is completely optional, and you can add it in dependencies section.

Java CDI Dependency Injection Example

CDI (Context and Dependency Injection) is a specification defined in JSR-299. Major aim is loose coupling by dependency injection.In this tutorial we will see how to use CDI Dependency Injection in java with three different ways;

• Field injection
• Constructor injection
• Setter method injection

Graphs

Graphs are data structures to represent road networks, the web, social networks etc. Moreover, hundreds of computational problems are related to graphs.They have two main ingredient which are;

• $$Vertices (V)$$ as known as nodes.
• $$Edges (E)$$ : pair of vertices
• can be undirected.
• or directed.

Quicksort

Quicksort is a sorting algorithm which applies divide and conquer paradigm. Quicksort has a worst case running time of $$O(n^{2})$$ , however, it has running time of $$O(n​ logn)$$ on average which makes quicksort very efficient. Moreover, it works in-place but not stable. The performance of quicksort depends on selecting the pivot, and starting to partition around it. During the partition procedure subarrays divided into four regions; $$\leq x$$, $$> x$$, $$unrestricted$$ ,and finally the $$pivot$$.

Selection Sort

Selection sort is an in-place comparison sort algorithm which has $$O(n^2)$$ running time complexity in both best and worst case. Even though its logic is similar to insertion sort, it's a very inefficient sorting algorithm. List is both divided into two parts as sorted and unsorted where initially sorted part is empty. Every turn, algorithm finds the minimum (or maximum) key in unsorted sublist then swaps it with the leftmost element of unsorted part. Due to the reason which elements in any place could get swapped selection sort is not stable.