Skip to content

Commit d613701

Browse files
committed
Reformat code after adding .editorconfig
1 parent efd21be commit d613701

File tree

24 files changed

+525
-506
lines changed

24 files changed

+525
-506
lines changed

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/console/CharactersCounter.java

+26-26
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77

88
public class CharactersCounter {
99

10-
private final InputStream inputStream;
11-
private final PrintStream printStream;
12-
13-
public CharactersCounter(InputStream inputStream, PrintStream printStream) {
14-
Objects.requireNonNull(inputStream, "inputStream must not be null");
15-
Objects.requireNonNull(printStream, "printStream must not be null");
16-
this.inputStream = inputStream;
17-
this.printStream = printStream;
18-
}
19-
20-
public void displayCharactersCount() {
21-
askForInput();
22-
String input = readInput();
23-
if (input == null || input.isBlank()) {
24-
this.printStream.println("Please enter something as input!");
25-
return;
10+
private final InputStream inputStream;
11+
private final PrintStream printStream;
12+
13+
public CharactersCounter(InputStream inputStream, PrintStream printStream) {
14+
Objects.requireNonNull(inputStream, "inputStream must not be null");
15+
Objects.requireNonNull(printStream, "printStream must not be null");
16+
this.inputStream = inputStream;
17+
this.printStream = printStream;
2618
}
27-
this.printStream.printf("%s has %d characters.%n", input, input.length());
28-
}
2919

30-
@SuppressWarnings("PMD.SystemPrintln")
31-
private void askForInput() {
32-
System.out.print("What is the input string? ");
33-
}
20+
public void displayCharactersCount() {
21+
askForInput();
22+
String input = readInput();
23+
if (input == null || input.isBlank()) {
24+
this.printStream.println("Please enter something as input!");
25+
return;
26+
}
27+
this.printStream.printf("%s has %d characters.%n", input, input.length());
28+
}
29+
30+
@SuppressWarnings("PMD.SystemPrintln")
31+
private void askForInput() {
32+
System.out.print("What is the input string? ");
33+
}
3434

35-
private String readInput() {
36-
try (Scanner scanner = new Scanner(this.inputStream)) {
37-
return scanner.hasNext() ? scanner.nextLine() : null;
35+
private String readInput() {
36+
try (Scanner scanner = new Scanner(this.inputStream)) {
37+
return scanner.hasNext() ? scanner.nextLine() : null;
38+
}
3839
}
39-
}
4040

4141
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/console/Main.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
public class Main {
44

5-
public static void main(String[] args) {
6-
CharactersCounter charactersCounter = new CharactersCounter(System.in, System.out);
7-
charactersCounter.displayCharactersCount();
8-
}
5+
public static void main(String[] args) {
6+
CharactersCounter charactersCounter = new CharactersCounter(System.in, System.out);
7+
charactersCounter.displayCharactersCount();
8+
}
99

1010
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCount.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
final class CharactersCount {
44

5-
private final String input;
5+
private final String input;
66

7-
private CharactersCount(String input) {
8-
if (input == null || input.isBlank()) {
9-
throw new IllegalArgumentException("input must not be blank");
7+
private CharactersCount(String input) {
8+
if (input == null || input.isBlank()) {
9+
throw new IllegalArgumentException("input must not be blank");
10+
}
11+
this.input = input;
1012
}
11-
this.input = input;
12-
}
1313

14-
static CharactersCount of(String input) {
15-
return new CharactersCount(input);
16-
}
14+
static CharactersCount of(String input) {
15+
return new CharactersCount(input);
16+
}
1717

18-
@Override
19-
public String toString() {
20-
return "%s has %d characters.".formatted(this.input, this.input.length());
21-
}
18+
@Override
19+
public String toString() {
20+
return "%s has %d characters.".formatted(this.input, this.input.length());
21+
}
2222
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCountApplication.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
public class CharactersCountApplication extends Application {
88

9-
@Override
10-
public void start(Stage stage) {
11-
CharactersCountViewModel viewModel = new CharactersCountViewModel();
12-
CharactersCountView view = new CharactersCountView(viewModel);
13-
Scene scene = new Scene(view, 400, 200);
14-
stage.setTitle("Counting the Number of Characters");
15-
stage.setScene(scene);
16-
stage.show();
17-
}
9+
@Override
10+
public void start(Stage stage) {
11+
CharactersCountViewModel viewModel = new CharactersCountViewModel();
12+
CharactersCountView view = new CharactersCountView(viewModel);
13+
Scene scene = new Scene(view, 400, 200);
14+
stage.setTitle("Counting the Number of Characters");
15+
stage.setScene(scene);
16+
stage.show();
17+
}
1818

1919
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCountView.java

+24-24
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88

99
final class CharactersCountView extends VBox {
1010

11-
private final TextField inputTextField = new TextField();
12-
13-
private final Label outputLabel = new Label();
14-
15-
private final CharactersCountViewModel viewModel;
16-
17-
CharactersCountView(CharactersCountViewModel viewModel) {
18-
this.viewModel = viewModel;
19-
createView();
20-
bindViewModel();
21-
}
22-
23-
private void createView() {
24-
setSpacing(10);
25-
setAlignment(Pos.CENTER);
26-
setPadding(new Insets(10, 20, 10, 20));
27-
this.getChildren().addAll(new Label("What is the input string?"), this.inputTextField, this.outputLabel);
28-
}
29-
30-
private void bindViewModel() {
31-
this.inputTextField.textProperty().bindBidirectional(this.viewModel.inputProperty());
32-
this.outputLabel.textProperty().bind(this.viewModel.outputProperty());
33-
this.viewModel.inputProperty().addListener((obs, ov, nv) -> this.viewModel.countInputCharacters());
34-
}
11+
private final TextField inputTextField = new TextField();
12+
13+
private final Label outputLabel = new Label();
14+
15+
private final CharactersCountViewModel viewModel;
16+
17+
CharactersCountView(CharactersCountViewModel viewModel) {
18+
this.viewModel = viewModel;
19+
createView();
20+
bindViewModel();
21+
}
22+
23+
private void createView() {
24+
setSpacing(10);
25+
setAlignment(Pos.CENTER);
26+
setPadding(new Insets(10, 20, 10, 20));
27+
this.getChildren().addAll(new Label("What is the input string?"), this.inputTextField, this.outputLabel);
28+
}
29+
30+
private void bindViewModel() {
31+
this.inputTextField.textProperty().bindBidirectional(this.viewModel.inputProperty());
32+
this.outputLabel.textProperty().bind(this.viewModel.outputProperty());
33+
this.viewModel.inputProperty().addListener((obs, ov, nv) -> this.viewModel.countInputCharacters());
34+
}
3535
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCountViewModel.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55

66
final class CharactersCountViewModel {
77

8-
private final StringProperty input = new SimpleStringProperty();
8+
private final StringProperty input = new SimpleStringProperty();
99

10-
private final StringProperty output = new SimpleStringProperty();
10+
private final StringProperty output = new SimpleStringProperty();
1111

12-
StringProperty inputProperty() {
13-
return this.input;
14-
}
12+
StringProperty inputProperty() {
13+
return this.input;
14+
}
1515

16-
StringProperty outputProperty() {
17-
return this.output;
18-
}
16+
StringProperty outputProperty() {
17+
return this.output;
18+
}
1919

20-
void countInputCharacters() {
21-
String inputValue = this.input.getValue();
22-
if (inputValue == null || inputValue.isBlank()) {
23-
this.output.set("Please enter some input string.");
24-
} else {
25-
this.output.set(CharactersCount.of(inputValue).toString());
20+
void countInputCharacters() {
21+
String inputValue = this.input.getValue();
22+
if (inputValue == null || inputValue.isBlank()) {
23+
this.output.set("Please enter some input string.");
24+
} else {
25+
this.output.set(CharactersCount.of(inputValue).toString());
26+
}
2627
}
27-
}
2828

2929
}

characters-count/src/main/java/com/craftsmanshipinsoftware/charscnt/gui/Main.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class Main {
66

7-
public static void main(String[] args) {
8-
Application.launch(CharactersCountApplication.class);
9-
}
7+
public static void main(String[] args) {
8+
Application.launch(CharactersCountApplication.class);
9+
}
1010

1111
}

characters-count/src/test/java/com/craftsmanshipinsoftware/charscnt/console/CharactersCounterTests.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99

1010
class CharactersCounterTests {
1111

12-
@Test
13-
void displayCharactersCount_GivenNoInput_ShouldAskToInputSomething() {
14-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
15-
CharactersCounter charactersCounter = new CharactersCounter(new ByteArrayInputStream(new byte[]{}), new PrintStream(outputStream));
12+
@Test
13+
void displayCharactersCount_GivenNoInput_ShouldAskToInputSomething() {
14+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
15+
CharactersCounter charactersCounter = new CharactersCounter(new ByteArrayInputStream(new byte[]{}),
16+
new PrintStream(outputStream));
1617

17-
charactersCounter.displayCharactersCount();
18+
charactersCounter.displayCharactersCount();
1819

19-
assertThat(outputStream).hasToString("Please enter something as input!" + System.lineSeparator());
20-
}
20+
assertThat(outputStream).hasToString("Please enter something as input!" + System.lineSeparator());
21+
}
2122

22-
@Test
23-
void displayCharactersCount_GivenValidInput_ShouldDisplayCharactersCount() {
24-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
25-
CharactersCounter charactersCounter = new CharactersCounter(new ByteArrayInputStream("Durim".getBytes()), new PrintStream(outputStream));
23+
@Test
24+
void displayCharactersCount_GivenValidInput_ShouldDisplayCharactersCount() {
25+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
26+
CharactersCounter charactersCounter = new CharactersCounter(new ByteArrayInputStream("Durim".getBytes()),
27+
new PrintStream(outputStream));
2628

27-
charactersCounter.displayCharactersCount();
29+
charactersCounter.displayCharactersCount();
2830

29-
assertThat(outputStream).hasToString("Durim has 5 characters." + System.lineSeparator());
30-
}
31+
assertThat(outputStream).hasToString("Durim has 5 characters." + System.lineSeparator());
32+
}
3133

3234
}

characters-count/src/test/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCountTests.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010

1111
class CharactersCountTests {
1212

13-
@NullAndEmptySource
14-
@ValueSource(strings = {" "})
15-
@ParameterizedTest(name = "Given input: [{0}]")
16-
void of_GivenInvalidInput_ShouldThrowException(String input) {
17-
assertThatIllegalArgumentException().isThrownBy(() -> CharactersCount.of(input)).withMessage("input must not be blank");
18-
}
13+
@NullAndEmptySource
14+
@ValueSource(strings = {" "})
15+
@ParameterizedTest(name = "Given input: [{0}]")
16+
void of_GivenInvalidInput_ShouldThrowException(String input) {
17+
assertThatIllegalArgumentException()
18+
.isThrownBy(() -> CharactersCount.of(input))
19+
.withMessage("input must not be blank");
20+
}
1921

20-
@Test
21-
void of_GivenValidInput_ShouldReturnCharactersCount() {
22-
String input = "Durim";
22+
@Test
23+
void of_GivenValidInput_ShouldReturnCharactersCount() {
24+
String input = "Durim";
2325

24-
CharactersCount charactersCount = CharactersCount.of(input);
26+
CharactersCount charactersCount = CharactersCount.of(input);
2527

26-
assertThat(charactersCount).hasToString("Durim has 5 characters.");
27-
}
28+
assertThat(charactersCount).hasToString("Durim has 5 characters.");
29+
}
2830
}

characters-count/src/test/java/com/craftsmanshipinsoftware/charscnt/gui/CharactersCountViewModelTests.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99

1010
class CharactersCountViewModelTests {
1111

12-
@NullAndEmptySource
13-
@ValueSource(strings = {" "})
14-
@ParameterizedTest(name = "Given input: [{0}]")
15-
void countInputCharacters_GivenInputIsEmpty_ShouldOutputPleaseEnterSomeInputString(String input) {
16-
CharactersCountViewModel viewModel = new CharactersCountViewModel();
17-
viewModel.inputProperty().setValue(input);
12+
@NullAndEmptySource
13+
@ValueSource(strings = {" "})
14+
@ParameterizedTest(name = "Given input: [{0}]")
15+
void countInputCharacters_GivenInputIsEmpty_ShouldOutputPleaseEnterSomeInputString(String input) {
16+
CharactersCountViewModel viewModel = new CharactersCountViewModel();
17+
viewModel.inputProperty().setValue(input);
1818

19-
viewModel.countInputCharacters();
19+
viewModel.countInputCharacters();
2020

21-
assertThat(viewModel.outputProperty().getValue()).isEqualTo("Please enter some input string.");
22-
}
21+
assertThat(viewModel.outputProperty().getValue()).isEqualTo("Please enter some input string.");
22+
}
2323

24-
@Test
25-
void countInputCharacters_GivenInputIsHelloWorld_ShouldOutputCharacterCount() {
26-
CharactersCountViewModel viewModel = new CharactersCountViewModel();
27-
viewModel.inputProperty().setValue("Hello, World!");
24+
@Test
25+
void countInputCharacters_GivenInputIsHelloWorld_ShouldOutputCharacterCount() {
26+
CharactersCountViewModel viewModel = new CharactersCountViewModel();
27+
viewModel.inputProperty().setValue("Hello, World!");
2828

29-
viewModel.countInputCharacters();
29+
viewModel.countInputCharacters();
3030

31-
assertThat(viewModel.outputProperty().getValue()).isEqualTo("Hello, World! has 13 characters.");
32-
}
31+
assertThat(viewModel.outputProperty().getValue()).isEqualTo("Hello, World! has 13 characters.");
32+
}
3333

3434
}

0 commit comments

Comments
 (0)