Skip to content

Instantly share code, notes, and snippets.

View chbaranowski's full-sized avatar

Christian Baranowski chbaranowski

View GitHub Profile
import junit.framework.TestCase;
public class CalcTest extends TestCase {
Calc calc;
protected void setUp() throws Exception {
System.out.println("1. Setup");
calc = new Calc();
}
public class Calc {
private int result = 0;
public void add(int a) {
if(a < 0) {
throw new IllegalStateException();
}
result += a;
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
locations={"classpath:/beans/groovy-context.groovy"},
loader = GroovyContextLoader.class)
public class GroovyBeanTest {
@Autowired
SmartBean smartBean;
@Test
@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 {
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();
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 org.mapstruct.*;
@Mapper(uses = {PowerMapper.class})
public interface CarMapper {
@Mappings({
@Mapping(source = "engine", target = "engineDto")
})
CarDto map(Car car);
@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)
@chbaranowski
chbaranowski / promise.js
Last active December 28, 2015 03:59
Use $promise in AngularJS REST resource
var myApp = angular.module('myApp', ['ngResource'])
myApp.factory('usersResource', function($resource){
return $resource('/users', {})
})
myApp.controller('UserCtrl',['$scope', 'usersResource', function($scope, usersResource) {
usersResource.query().$promise.then(function(users) {
console.log('User query was succesful user count: ' + users.length)
})
@chbaranowski
chbaranowski / FindBundleClassLoader.java
Created October 15, 2013 06:56
Find the actual bundle classloader.
Bundle bundle = bundleContext.getBundle();
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
ClassLoader classLoader = bundleWiring.getClassLoader();