Our dragon has broken free, we need to analyze all the places (classes) where the Dragon managed to do harm and mark all the code fragments that in your opinion of not correct.
A. Java
public class GuardianController {
@GetMapping("/guardians")
public Model guardians(Model model) {
return model.addAttribute("shield", "You have entered the Forbidden Zone!");
}
}
A. Kotlin
class GuardianController {
@GetMapping("/guardians")
fun guardians(model: Model): Model {
model.addAttribute("shield", "You have entered the Forbidden Zone!")
return model
}
}
B. Java
@Controller
public class CastleController {
private final Archers archers;
@Autowired
public CastleController(Archers archers) {
this.archers = archers;
}
@GetMapping("/castle")
public String castleDefenders(Model model) {
model.addAttribute("archers", archers.summonArchersToDefend());
return "castle";
}
@RequestMapping("/castle/rare")
public String guardians(Model model) {
model.addAttribute("rareEvent", archers.rareAttack());
return "castle";
}
}
B. Kotlin
@Controller
class CastleController(private val archers: Archers) {
@GetMapping("/castle")
fun castleDefenders(model: Model): String {
model.addAttribute("archers", archers.summonArchersToDefend())
return "castle"
}
@RequestMapping("/castle/rare")
fun guardians(model: Model): String {
model.addAttribute("rareEvent", archers.rareAttack())
return "castle"
}
}
C. Java
@Override
public interface BarrackRepository {
Optional findByDragon(Dragon dragon);
}
C. Kotlin
@Override
interface BarrackRepository {
fun findByDragon(dragon: Dragon): Optional
}
D. Java
@Component
public class Archers {
private final Dragon dragon;
@Autowired
public Archers(Dragon dragon) {
this.dragon = dragon;
}
public String summonArchersToDefend() {
return dragon.slayDragon() + "\nArcher Defender is summoned! You shall not pass dragon!";
}
public String rareAttack() {
return "The rare archer, Dragon Slayer.";
}
}
D. Kotlin
@Component
class Archers @Autowired constructor(private val dragon: Dragon) {
fun summonArchersToDefend(): String {
return dragon.slayDragon() + "\nArcher Defender is summoned! You shall not pass dragon!"
}
fun rareAttack(): String {
return "The rare archer, Dragon Slayer."
}
}