Skip to content

Instantly share code, notes, and snippets.

View chbaranowski's full-sized avatar

Christian Baranowski chbaranowski

View GitHub Profile
@chbaranowski
chbaranowski / lazybones.groovy
Created February 16, 2014 10:24
Simple lazybones file
def props = [:]
props.helloWorld = ask("Define the hello world message:", "Hello World!")
processTemplates('src/main/groovy/HelloWorld.groovy', props)
import org.mapstruct.*;
@Mapper(uses = {PowerMapper.class})
public interface CarMapper {
@Mappings({
@Mapping(source = "engine", target = "engineDto")
})
CarDto map(Car car);
public class PowerMapper {
public Power asPower(PowerDto dto) {
if(dto == null) return null;
Power power = new Power();
power.value = String.valueOf(dto.value);
return power;
}
public PowerDto asPowerDto(Power power) {
import static org.junit.Assert.*;
import org.junit.*;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
public class CarMappingTest {
@Test
public void mapCarToCarDto() {
CarMapper carMapper = Mappers.getMapper(CarMapper.class);
Car car = new Car();
@chbaranowski
chbaranowski / beans-context.groovy
Last active August 29, 2015 13:57
Spring groovy beans context
package beans
import org.springframework.core.io.ClassPathResource
// load configuration from the classpath
def url = new ClassPathResource('beans/simple.config').URL;
def config = new ConfigSlurper().parse(url);
beans {
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
locations={"classpath:/beans/groovy-context.groovy"},
loader = GroovyContextLoader.class)
public class GroovyBeanTest {
@Autowired
SmartBean smartBean;
@Test
public class Calc {
private int result = 0;
public void add(int a) {
if(a < 0) {
throw new IllegalStateException();
}
result += a;
}
import junit.framework.TestCase;
public class CalcTest extends TestCase {
Calc calc;
protected void setUp() throws Exception {
System.out.println("1. Setup");
calc = new Calc();
}
import static org.junit.Assert.*;
import org.junit.*;
public class CalcTest {
Calc calc;
@Before
public void setup() {
@chbaranowski
chbaranowski / HotReloadConfiguration.java
Last active August 29, 2015 14:02
HotReloadConfiguration Spring Boot
@Configuration
@Conditional(HotReloadConfiguration.HotReloadCondition.class)
public class HotReloadConfiguration {
public static class HotReloadCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String hotReloadEnabledProperty = context.getEnvironment().getProperty("hotReload.enabled");
return StringUtils.equals(hotReloadEnabledProperty, "true");
}