Skip to content

Instantly share code, notes, and snippets.

View r-winkler's full-sized avatar
🎯
Focusing

René Winkler r-winkler

🎯
Focusing
  • Bern, Switzerland
View GitHub Profile
public class JUnitStringAssert {
private static final String DEV = "Developer";
@Test
public void testString() {
assertNotNull(DEV);
assertFalse("".equals(DEV));
assertTrue(DEV.startsWith("Dev"));
assertTrue(DEV.contains("elo"));
public class HamcrestStringAssert {
private static final String DEV = "Developer";
@Test
public void testString() {
assertThat(DEV, is(notNullValue()));
assertThat(DEV, not(isEmptyString()));
assertThat(DEV, startsWith("Dev"));
assertThat(DEV.length(), equalTo(9));
public class AssertJStringAssert {
private static final String DEV = "Developer";
@Test
public void testStrings_WithAssertJ() {
assertThat(DEV).isNotNull().isNotEmpty().startsWith("Dev").contains("elo").hasSize(9);
}
}
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHello(HttpServletResponse response) throws InterruptedException {
response.setHeader("Cache-Control", "max-age=5");
TimeUnit.SECONDS.sleep(2);
return "Hello World!";
}
}
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/hello").permitAll()
.anyRequest().authenticated();
http.headers().cacheControl().disable();
function foo(){
console.log(this.bar);
}
var bar="bar1";
foo(); // bar1
function foo(){
console.log(this.bar);
}
var o1 = {
bar: "bar2",
foo: function() { console.log(this.bar);}
};
var bar="bar1";
List<Item> items = Arrays.asList(
new Item("A", 10),
new Item("B", 20),
new Item("C", 30),
new Item("A", 40),
new Item("B", 50),
new Item("C", 60));
Map<String, Integer> accumulator = items.stream().collect(Collectors.groupingBy(Item::getName, Collectors.summingInt(Item::getValue)));
List<Item> result = new ArrayList<>();
for (Map.Entry<String,Integer> entry : accumulator.entrySet()){
result.add(new Item(entry.getKey(), entry.getValue()));
}