Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / Spring Boot + TestNG - BaseIT.java
Last active May 7, 2018 22:19
BaseIT class for Spring Booot and TestNG tests
package io.lenar.examples.spring.start;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class BaseIT extends AbstractTestNGSpringContextTests {
// Common methods, variables and constants
@LenarBad
LenarBad / JUnitWithSpringBootExampleIT.java
Last active May 14, 2018 20:31
Spring Boot + JUnit minimal required code
package io.lenar.examples.junitspringboot.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@LenarBad
LenarBad / Choose Source for Default Value.groovy
Last active May 18, 2018 14:15
Jenkins dynamic Extended Choice Parameter with service call (Groovy Script)
// host will be passed in the groovy bindings for extended choice plugin.
def getVersion = { host, path ->
try {
def version = new groovy.json.JsonSlurper().parse(new URL("https://${host}${path}")).version
return version
} catch(Exception e) {
return null
}
}
@LenarBad
LenarBad / Jenkins build periodically examples.md
Last active June 1, 2018 19:22
Jenkins build periodically

Build every hour:
H * * * *

Build every 20 minutes:
H/20 * * * *

Build every 20 minutes 2am to 11pm:
H/20 5-23 * * *

Build every 20 minutes, work time/days (8am-6pm, MON-FRI) only:
H/20 8-18 * * 1-5

Build every hour MON-WED and FRI only:
H * * * 1-3,5

@LenarBad
LenarBad / SpringDataProviderRunner.java
Created June 14, 2018 19:09
JUnit data providers for Spring
import static java.lang.Character.toUpperCase;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
@LenarBad
LenarBad / isWiderPrimitive.java
Created July 24, 2018 17:43
Checks if object is auto-boxed primitive + String and Void
public boolean isWiderPrimitive(Object object) {
if (object == null) {
return false;
}
Class clazz = object.getClass();
if (clazz == Boolean.class || clazz == Character.class ||
clazz == Byte.class || clazz == Short.class ||
clazz == Integer.class || clazz == Long.class ||
clazz == Float.class || clazz == Double.class ||
clazz == String.class || clazz == Void.class) {
@LenarBad
LenarBad / Spring Boot + TestNG test class TestNGTestsWithSpringBootIT.java
Last active December 15, 2018 02:05
Spring Boot and TestNG example - test class
package io.lenar.examples.spring.start;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.boot.test.context.SpringBootTest;
import org.testng.Assert;
import org.testng.annotations.Test;
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class TestNGTestsWithSpringBootIT extends AbstractTestNGSpringContextTests {
@LenarBad
LenarBad / PhoneLetters.java
Last active February 27, 2019 16:34
Interview Question. Generate and print all possible strings that could be created by a phone number, using the letters assigned on the phone Print all possibles strings that could be created by a phone number, using the letters assigned on the phone. Don’t have to store them, just print them
private Map<String, List<String>> static final digitToLetterMap = new HashMap() {{
map.put("0", Arrays.asList(" "));
map.put("1", Arrays.asList(""));
map.put("2", Arrays.asList("a", "b", "c"));
map.put("3", Arrays.asList("d", "e", "f"));
map.put("4", Arrays.asList("g", "h", "i"));
map.put("5", Arrays.asList("j", "k", "l"));
map.put("6", Arrays.asList("m", "m", "o"));
map.put("7", Arrays.asList("p", "q", "r", "s"));
map.put("8", Arrays.asList("t", "u", "v"));
@LenarBad
LenarBad / RomanNumeral.java
Created March 8, 2019 03:49
Arabic to roman numerals
public class RomanNumeral {
private final HashMap<Integer, String> map = new HashMap<Integer, String>() {
{
put(1, "I");
put(5, "V");
put(10, "X");
put(50, "L");
put(100, "C");
put(500, "D");
put(1000, "M");
@LenarBad
LenarBad / mapToQuery.java
Created April 8, 2019 21:39
Parameter map to url query
private String mapToQuery(Map<String, String> parameters) {
String query = "";
if (parameters != null && !parameters.isEmpty()){
query = "?" +
parameters.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(Collectors.joining("&"));
}
return query;
}