View AssertJStringAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AssertJStringAssert { | |
private static final String DEV = "Developer"; | |
@Test | |
public void testStrings_WithAssertJ() { | |
assertThat(DEV).isNotNull().isNotEmpty().startsWith("Dev").contains("elo").hasSize(9); | |
} | |
} |
View JUnitStringAssert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
View HamcrestStringAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
View HelloController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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!"; | |
} | |
} |
View SecurityConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
class SecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.authorizeRequests() | |
.antMatchers("/hello").permitAll() | |
.anyRequest().authenticated(); | |
http.headers().cacheControl().disable(); |
View implicitBindingRule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
console.log(this.bar); | |
} | |
var o1 = { | |
bar: "bar2", | |
foo: function() { console.log(this.bar);} | |
}; | |
var bar="bar1"; |
View defaultThisRule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
console.log(this.bar); | |
} | |
var bar="bar1"; | |
foo(); // bar1 |
View itemsArrayList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
View groupingBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, Integer> accumulator = items.stream().collect(Collectors.groupingBy(Item::getName, Collectors.summingInt(Item::getValue))); |
View groupingByInJavaScript.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [ | |
{ name: "A", value: 10 }, | |
{ name: "B", value: 20 }, | |
{ name: "C", value: 30 }, | |
{ name: "A", value: 40 }, | |
{ name: "B", value: 50 }, | |
{ name: "C", value: 60 }]; | |
var accumulated = arr.reduce(function(accumulator, element) { | |
var currentValue = accumulator[element.name]; |
OlderNewer