Posts

Spring Boot + Mockito simple application with 100% code coverage

Image
In this article, we will show you a simple  Spring Boot example to demonstrate test methods for Controllers, Service, and Repository, And code coverage analysis using the EclEmma plugin. Technologies used: Spring Boot 2.6.4 Mockito 3.11.2 Maven 3+ EclEmma plugin Junit 5 Java 17 A quick overview of  Spring Boot, Mockito, and EclEmma plugin Spring boot: Spring boot to develop REST web services and microservices. Spring Boot has taken the Spring framework to the next level. It has drastically reduced the configuration and setup time required for spring projects. We can set up a project with almost zero configuration and start building the things that actually matter to your application. Mockito: Mockito is a mocking framework, a JAVA-predicated library that is utilized for efficacious unit testing of JAVA applications. Mockito is utilized to mock interfaces so that a dummy functionality can be integrated into a mock interface that can be utilized in unit testing. EclEmma : E

Go Language - Validate Email Address Example

Image
Email validation is required in nearly every application that has user registration in place. An email has its own structure, and before using it, we need to validate it. In Go Language, email validation can be performed by using the standard library function mail.ParseAddress() or regular expression. Solution 1: Using the standard library function mail.ParseAddress() package main import ( "fmt" "net/mail" ) // Main function func main() { fmt.Println(ValidateEmail( "knowledgefactory-gmail.com" )) fmt.Println(ValidateEmail( "knowledgefactory4u@gmail.com" )) fmt.Println(ValidateEmail( "knowledge-factory4u@gmail.com" )) } func ValidateEmail(email string ) bool { _, err := mail.ParseAddress(email) return err == nil } Output: Solution 2: Using regular expression package main import ( "fmt" "regexp" ) // Main function func main() { fmt.Println(ValidateEmail( "knowledge

How to make the first letter of a string lowercase in Go Language?

Image
How to make the first letter of a string lowercase, but not change the case of any of the other letters? For example:   "Go language is awesome" → "go language is awesome" "Hello world" → "hello world" Solution 1: package main import ( "unicode" "unicode/utf8" ) // Main function func main() { str := "Go language is awesome" println(firstToLower(str)) } func firstToLower(s string ) string { if len(s) > 0 { r, size := utf8.DecodeRuneInString(s) if r != utf8.RuneError || size > 1 { lower := unicode.ToLower(r) if lower != r { s = string(lower) + s[size:] } } } return s } Output: Solution 2: Easy package main import "strings" // Main function func main() { str := "Go language is awesome" str = strings.ToLower(string(str[ 0 ])) + str[ 1 :] println(str) } Output: Solutio