replace #BAEL-913 test scenario with simple add and sum test (#1895)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
28adbeb53d
commit
4fd99ca7a5
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RequestMapping(value = "/adder", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@RestController
|
||||
public class AdderController {
|
||||
|
||||
private AdderService adderService;
|
||||
|
||||
public AdderController(AdderService adderService) {
|
||||
this.adderService = adderService;
|
||||
}
|
||||
|
||||
@GetMapping("/current")
|
||||
public int currentNum() {
|
||||
return adderService.currentBase();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public int add(@RequestParam int num) {
|
||||
return adderService.add(num);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AdderService {
|
||||
|
||||
private int num;
|
||||
|
||||
public void baseNum(int base) {
|
||||
this.num = base;
|
||||
}
|
||||
|
||||
public int currentBase() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public int add(int adder) {
|
||||
return this.num + adder;
|
||||
}
|
||||
|
||||
public int accumulate(int adder) {
|
||||
return this.num += adder;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RequestMapping(value = "/konamicode", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@RestController
|
||||
public class KonamiCodeController {
|
||||
|
||||
private final String classicCode = "↑↑↓↓←→←→BA";
|
||||
|
||||
@GetMapping("/classic")
|
||||
public String classicCode() {
|
||||
return classicCode;
|
||||
}
|
||||
|
||||
@GetMapping("/cheatable")
|
||||
public boolean cheatCheck(@RequestParam String cheatcode){
|
||||
return classicCode.equals(cheatcode);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* refer to <a href="https://en.wikipedia.org/wiki/Konami_Code">Konami Code</a>
|
||||
*/
|
||||
@Service
|
||||
public class KonamiCodeService {
|
||||
|
||||
private String classicCode = "↑↑↓↓←→←→BA";
|
||||
|
||||
public String getClassicCode() {
|
||||
return classicCode;
|
||||
}
|
||||
|
||||
public void alterClassicCode(String newCode) {
|
||||
classicCode = newCode;
|
||||
}
|
||||
|
||||
public boolean cheatWith(String cheatcode) {
|
||||
if ("↑↑↓↓←→←→BA".equals(cheatcode)) {
|
||||
stageLeft++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int stageLeft = 1;
|
||||
|
||||
public void clearStage() {
|
||||
stageLeft = 0;
|
||||
}
|
||||
|
||||
public int stageLeft() {
|
||||
return stageLeft;
|
||||
}
|
||||
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RequestMapping(value = "/konamicode", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@RestController
|
||||
public class KonamiCodeServiceInjectionController {
|
||||
|
||||
private KonamiCodeService konamiCodeService;
|
||||
|
||||
public KonamiCodeServiceInjectionController(KonamiCodeService konamiCodeService) {
|
||||
this.konamiCodeService = konamiCodeService;
|
||||
}
|
||||
|
||||
@PutMapping("/stages")
|
||||
public void clearStage(@RequestParam String action) {
|
||||
if ("clear".equals(action)) {
|
||||
konamiCodeService.clearStage();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/classic")
|
||||
public String classicCode() {
|
||||
return konamiCodeService.getClassicCode();
|
||||
}
|
||||
|
||||
@GetMapping("/cheatable")
|
||||
public boolean cheatCheck(@RequestParam String cheatcode) {
|
||||
return konamiCodeService.cheatWith(cheatcode);
|
||||
}
|
||||
|
||||
@GetMapping("/stages")
|
||||
public int stageLeft() {
|
||||
return konamiCodeService.stageLeft();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.serenity.spring;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RequestMapping(value = "/adder", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@RestController
|
||||
public class PlainAdderController {
|
||||
|
||||
private final int currentNumber = RandomUtils.nextInt();
|
||||
|
||||
@GetMapping("/current")
|
||||
public int currentNum() {
|
||||
return currentNumber;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public int add(@RequestParam int num) {
|
||||
return currentNumber + num;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user