Create Project with Sample Spring Shell Tests
Just like spring-shell/spring-shell-samples shows examples of Spring Shell features, create a project with samples of Spring Shell unit, functional and integration tests. Issue: SHL-192 https://jira.spring.io/browse/SHL-192
This commit is contained in:
committed by
Eric Bottard
parent
5447db5da7
commit
5ec589909e
@@ -0,0 +1,19 @@
|
||||
package com.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
* Main entry point for the illustrative Spring Shell Calculator application.
|
||||
*
|
||||
* @author Sualeh Fatehi
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class CalculatorApplication {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(CalculatorApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.shell.standard.ShellCommandGroup;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* Basic commands for the illustrative Spring Shell Calculator application.
|
||||
*
|
||||
* @author Sualeh Fatehi
|
||||
*/
|
||||
@ShellComponent
|
||||
@ShellCommandGroup("Calculator Commands")
|
||||
public class CalculatorCommands {
|
||||
|
||||
@Autowired
|
||||
private CalculatorState state;
|
||||
|
||||
@ShellMethod(value = "Add two integers")
|
||||
public int add(final int a, final int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@ShellMethod(value = "Add an integer to the value in memory")
|
||||
public int addToMemory(final int b) {
|
||||
final int sum = state.getMemory() + b;
|
||||
state.setMemory(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.example;
|
||||
|
||||
/**
|
||||
*
|
||||
* Program state for the illustrative Spring Shell Calculator application.
|
||||
*
|
||||
* @author Sualeh Fatehi
|
||||
*/
|
||||
public class CalculatorState {
|
||||
|
||||
private int memory;
|
||||
|
||||
public void clear() {
|
||||
memory = 0;
|
||||
}
|
||||
|
||||
public int getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
public void setMemory(final int memory) {
|
||||
this.memory = memory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user