My Articles:
Eclipse has great tooling support for JUnit test cases. Having code templates for JUnit test cases configured in Eclipse is a great addition in faster test development. Learn to create and import JUnit 5 test templates in eclipse.
When writing unit tests, it makes sense to check whether certain methods throw the expected exceptions when we supply invalid inputs or pre-conditions that are not satisfied. Junit 5 provides the following assertion methods for handling test exceptions. These method names are self-explanatory enough to suggest their usage. Please continue …
JUnit @Disabled annotation can be used to disable the test methods from test suite. This annotation can be applied over a test class as well as over individual test methods.
JUnit 5 Assumptions class provides static methods to support conditional test execution based on assumptions. A failed assumption results in a test being aborted. Assumptions are typically used whenever it does not make sense to continue execution of a given test method. In test report, these test will be marked as passed.
JUnit 5 assertions help in validating the expected output with actual output of a testcase. To keep things simple, all JUnit Jupiter assertions are static methods in the org.junit.jupiter.Assertions class.
In JUnit 5, test lifecycle is driven by 4 primary annotations i.e. @BeforeAll, @BeforeEach, @AfterEach and @AfterAll. Along with it, each test method must be marked with @Test annotation. @Test annotation is virtually unchanged, although it no longer takes optional arguments.
Learn to configure junit 5 with gradle, its juniper and platform modules and how to use them to create and execute tests.
Learn to configure junit 5 with maven, its jupiter and platform different modules and how to use them to create and execute tests.
JUnit 5 @Tag can be used to filter testcases from test plans. It can help in create multiple different test plans for different environments, different use-cases or any specific requirement. You can execute set of tests by including only those tagged tests in test plan OR by excluding other tests from test plan.
JUnit 5 test suites are written with @Suite annotation. Suites help us run the tests spread into multiple classes and packages. We can use Include and Exclude annotations (discussed later in this tutorial) for filtering test packages, test classes, or even test methods. @RunWith(JUnitPlatform.class) has been deprecated in favor of …
JUnit 5 @RepeatedTest annotation enable to write repeatable test templates which could be run multiple times. The frequency can be configured as parameter to @RepeatedTest annotation.
JUnit 5 @AfterAll annotation is replacement of @AfterClass annotation in JUnit 4. The annotated method should be executed after all tests in test class.
JUnit 5 @AfterEach annotation is replacement of @After annotation in JUnit 4.The annotated method should be executed after each @Test method in test class.
JUnit 5 @BeforeEach annotation is replacement of @Before annotation in JUnit 4. Annotated method should be executed before each @Test method in test class.
JUnit 5 @BeforeAll annotation is replacement of @BeforeClass and is used to signal that annotated method should be executed before all tests in test class.
Learn to execute JUnit 5 tests in Eclipse IDE. Maven has been used to import dependencies in this JUnit 5 example. 1. Add JUnit 5 Maven Dependencies To run JUnit 5 tests in Eclipse, at minimum, we will need the latest versions of the following dependencies. 2. Use @Test Annotation …
Learn to convert XMLGregorianCalendar to Date class or string value. Also learn to apply timezone changes and daylight saving effects as well.
Learn to build JAX-RS 2.0 HATEOAS links in REST resources using it’s javax.ws.rs.core.Link, javax.ws.rs.core.UriBuilder and javax.ws.rs.core.UriInfo classes.
To triage SSL issues, enable SSL debug logging by passing javax.net.debug=ssl runtime argument to your server/program.
In Spring, custom PropertyEditor implementation converts a custom object’s value to and from its native type representation into a String.
Mostly for logging and security purposes, we need the IP address information for incoming requests. 1. HTTPServletRequest.getRemoteAddr() In a Java web application, we can get IP address using HTTPServletRequest.getRemoteAddr() method. String ipAddress = httpServletRequest.getRemoteAddr(); BUT, if our application is running behind a load balancer proxy and we would like to …
Spring boot @Scheduled example to schedule jobs at a fixed rate, fixed delay, using a cron expression and concurrent task executions.
Learn how to use Spring Boot CommandLineRunner interface with examples, and how it is different from the ApplicationRunner interface.
Spring boot loads lots of beans internally to run the application with minimal configuration. In this example, we will learn to find out all those loaded beans by Spring Boot and their class type information. Using ApplicationContext to get all loaded beans To execute a method automatically, when the application …
Learn the default spring boot logging and configuring custom log levels, file appenders and colored logs via application.yaml file.
Learn the default spring boot logging and configuring custom log levels, file appenders and colored logs via application.properties file.
Spring Boot bundles Tomcat and Jetty dependencies as separate starters to make easy switching them using configurations and properties.
By default, Spring boot embedded server starts at port 8080. Learn to change the default port using Java configuration, command line, and properties.
By default, Spring boot applications are accessed by context path “/”. We can customize it using server.contextPath or server.servlet.context-path.
In Spring Boot 3 JSP example, learn to configure the Spring MVC with JstlView.class and serve JSP pages with static content and triage some common issues.
In fizz buzz game, we say numbers such that if that number is a multiple of five, we say “fizz”, if multiple of seven, we say “buzz”, multiple of both, we say “fizzbuzz.”
Learn the difference between association, aggregation and composition in Java with source code, examples and real-life usecases.
Learn to use Java CORS filter. CORS is a mechanism that allows JavaScript on a web page to make AJAX requests to another domain.
Learn to format XMLGregorianCalendar instance to string in multiple patterns e.g. ‘MM/dd/yyyy hh:mm a z’ using DateTimeFormatter and SimpleDateFormat classes in Java.
To disable or bypass SSL Certificate checking is never a recommended solution for SSL issues, but at test environment – sometimes you may need this.
Learn what is a microservice? Architectures, principles and benefits of the microservices? Also learn the differences between microservices and SOA.
In this tutorial, we will learn to secure vaadin application behind basic authentication security provided by spring security module.
Using java 8 stream API, you can use stream.distinct() method to filter or collect all distinct elements from a collection. Let’s learn how to find distinct elements with java stream API.
In this tutorial, we will learn to work with Vaadin ComboBox UI component including setting values, filtering, adding new values and event handling.
Learn to setup, style and validate vaadin text field control with these simple to follow code examples.
In this example, we will learn to create vaadin hello world application using maven, and then we will run deploy the application in built-in jetty server.
The Spring AOP @AfterThrowing annotation enables developers to define advice that executes after a method throws an exception.
The @AfterReturning in Spring AOP AspectJ is an way method for executing custom logic for post-processing tasks after a method successfully returns.
The Spring AOP @Around annotation allows control of the method execution, providing the opportunity to modify the input, output, or skip the execution.
The @After annotation is applied to an aspect that should be executed after the advised method has been executed normally or with an exception.
In this spring aop example, we will learn to use @Before aspectj annotation. @Before annotated methods run exactly before the all methods matching with pointcut expression.
In this example, we will learn to use java 8 APIs along with Files.list() and DirectoryStream to list all files present in that directory.
Learn to register for changes in a directory, sub-directories and files using the Java WatchService API, handle the changes and cancel it.
Python httplib2 module provides methods for accessing Web resources via HTTP GET and POST requests, authentication, caching, redirects, and compression.
Learn about the FIRST principles for unit testing that can help make our unit tests shine and ensure they pay off more than they cost.