Search by labels

Friday, July 21, 2023

Spotless Code Formatter

Clean and formatted code is maintainable code.

Spotless is a popular tool that can format code in any programming language out there (Java, JavaScript, Python, C#, TypeScript, etc.) using any build tools. (Gradle, Maven, etc.)

In this tutorial we will look into integrating it in a Java project built with Gradle. In order to do this, we just need to add and configure Spotless in the build.gradle file in 3 easy steps:

1. Add the Spotless plugin:

plugins {

    id "com.diffplug.spotless" version "6.19.0"

}


2. Configure the formatting jobs:


spotless {

    java {

        googleJavaFormat() // format the code in Google Java format

        importOrder() // order the imports

        removeUnusedImports() // remove the unused imports

        formatAnnotations() // format the annotations

    }

}


3. Trigger Spotless automatically when the project is compiled:


tasks.withType(SourceTask) {

    finalizedBy 'spotlessApply'

}


Worth mentioning is that Spotless also offers additional features like automatic refactoring of the Java code using cleanthat().


Thursday, September 15, 2022

The Penny Game

Or why when embracing Agile, individual productivity decreases, but the team's productivity greatly increases.



Monday, June 27, 2022

Automating E-Mail Test Cases When Using Twilio SendGrid

   SendGrid is a customer communication platform for transactional and marketing email, which boasts an impressive client portfolio with big names like Uber, Spotify or Booking.com.

   Let's look into automating a simple test scenario that will check if new users that sign-up for a test application will also receive their welcome e-mails. 

   The presented small test suite only details the e-mail verification part, as the sign-up part can be done in multiple ways - UI action, API call, etc. and is application specific. 

   The test case uses the RestAssured Java library with a previously created API key to call the SendGrid API and check for the e-mail event of interest.

@Test

@Order(0)

void signUp(){

// perform user sign-up

}


@Test

@Order(1)

void verifySendGridEmailEvent() {

    sleep(asyncWaitingTime); //it is an async process so waiting time has to be allowed


    given().log().method().log().uri().header("Authorization", "Bearer " + sendgridApiKey)

            .when().get("https://api.sendgrid.com/v3/messages?limit=1&query=to_email=\"" + emailAddress + "\"")

            .then().statusCode(200)

            .body("messages[0].subject", equalTo("Welcome to Going T-Shaped!"),

                    "messages[0].from_email", equalTo("no-reply@goingtshaped.blogspot.com"),

                    "messages[0].to_email", equalTo(emailAddress), // the e-mail address from the previous sign-up test

                    "messages[0].status", equalTo("delivered")); // e-mail accepted at the receiving server


    System.out.println("Welcome E-mail event correctly retrieved from Sendgrid for user " + emailAddress);

}


   So a quick and simple way of making sure that users are not missing any important e-mail communications due to unforeseen bugs. The above test case can be easily adjusted for any types of e-mails just by switching the verified attributes, e.g. e-mail subject from "Welcome to Going T-Shaped!" to "Forgot Your Password".