Skip to content

Instantly share code, notes, and snippets.

@rhamedy
rhamedy / Dockerfile
Created April 18, 2021 21:56
Sample Flask App - Ping Service
FROM python:3.8-slim-buster
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
@rhamedy
rhamedy / Dockerfile
Created April 18, 2021 21:45
Sample Flask App - Ping Service
FROM python:3.8-slim-buster
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
@rhamedy
rhamedy / StudentValidator.java
Created September 27, 2020 01:58
A Generic validator for getById type of methods from Spring Data
package com.sampleservice.demo.validator;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;
import java.util.Optional;
@Component
public class StudentValidator {
@rhamedy
rhamedy / StudentControllerTest.java
Created September 26, 2020 02:43
Unit tests generated by AI-powered Diffblue Cover plugin
package com.sampleservice.demo.controller;
import static org.mockito.AdditionalMatchers.or;
import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.when;
import com.sampleservice.demo.dto.inbound.StudentInDTO;
import com.sampleservice.demo.model.Student;
import com.sampleservice.demo.service.StudentServiceImpl;
@rhamedy
rhamedy / StudentServiceImpl.java
Created September 26, 2020 02:19
A sample spring boot service layer with a bunch of methods
package com.sampleservice.demo.service;
import com.sampleservice.demo.validator.StudentValidator;
import com.sampleservice.demo.dao.StudentDAO;
import com.sampleservice.demo.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
@rhamedy
rhamedy / StudentController.java
Created September 26, 2020 02:17
A sample spring boot controller with a bunch of endpoints
/**
* A Sample Controller that exposes a bunch of endpoints that allow operations
* such as CREATE, READ, DELETE and LIST users.
*
* @author Rafiullah Hamedy
*/
package com.sampleservice.demo.controller;
import java.util.*;
@rhamedy
rhamedy / UtilityTest.java
Created September 24, 2020 01:29
Generated unit tests by Diffblue Cover plugin
package com.diffblue.demo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class UtilityTest {
@rhamedy
rhamedy / Utility.java
Created September 24, 2020 01:05
A sample utility class with a few methods for testing
package com.diffblue.demo;
import org.springframework.util.Assert;
/**
* The following methods are used to automatically generate unit test for.
*/
public class Utility {
enum Color {
RED,
@rhamedy
rhamedy / build.gradle
Created July 6, 2020 00:35
Java Spring Boot with JaCoCo Code Coverage with Gradle
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'eclipse'
id 'jacoco'
}
group = 'codecov.article'
version = '0.0.1-SNAPSHOT'
@rhamedy
rhamedy / pom.xml
Last active July 5, 2020 19:37
Java Spring Boot with JaCoCo test coverage pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>