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
@WebMvcTest | |
class HttpControllersTests(@Autowired val mockMvc: MockMvc) { | |
@MockkBean | |
private lateinit var articleRepository: ArticleRepository | |
@Test | |
fun `List articles`() { | |
val user = User("testUser", "John", "Doe") | |
val spring5Article = Article("Spring Framework 5.0 goes GA", "Dear Spring community ...", "Lorem ipsum", user) |
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 | |
@RequestMapping("/api/article") | |
class ArticleController(private val repository: ArticleRepository) { | |
@GetMapping("/") | |
fun findAll() = repository.findAllByOrderByAddedAtDesc() | |
@GetMapping("/{id}") | |
fun findOne(@PathVariable id: UUID) = | |
repository.findBySlug(slug) ?: ResponseStatusException(HttpStatus.NOT_FOUND, "This article does not exist") |
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
<html> | |
<head> | |
<title>{{title}}</title> | |
</head> | |
<body> | |
<h1>{{title}}</h1> | |
</body> | |
</html> |
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
package com.example.blog | |
import org.springframework.stereotype.Controller | |
import org.springframework.ui.Model | |
import org.springframework.ui.set | |
import org.springframework.web.bind.annotation.GetMapping | |
@Controller | |
class HtmlController { |
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
//Null reference | |
var a: String = "abc" | |
a = null //compilation error | |
//output: Null can not be a value of a non-null type String | |
//Nullable operator ? | |
var a: String? = "abc" | |
a = null //ok | |
print(a) |
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
class Customer(val name: String, val email: String, val company: String) |
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
//Customer POJO class to represent entity Customer | |
class Customer(val name: String, val email: String, val company: String) | |
public class Customer{ | |
String name; | |
String email; | |
String company; | |
//constructor to initialise fields |