Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/35-methods-using/115-string-immutability/App.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
public class App {
public static void main(String[] args) {
var email = " SupporT@hexlet.io\n";

public static final String email = " SupporT@hexlet.io\n";

public static String normalize() {
// BEGIN
email = email.trim();
email = email.toLowerCase();
System.out.println(email);
return email.trim().toLowerCase();
// END
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

емнип на данном этапе студенты не работали со свойствами. Поэтому давайте оставим все внутри одного метода, с переменной. Да и создание своих методов рассмаривается дальше (поэтому мы тут и печатаем на экран).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошо. Будем печатать. Печать добавляет перевод строки, который мы здесь, как и в других тестах, удаляем с помощью actual.trim() Но это слишком сильно, так как удаляет не только последний символ. Из за этого получился данный баг. Теперь в тесте удаляется только последний символ, и только если он - перевод строки

}
17 changes: 5 additions & 12 deletions modules/35-methods-using/115-string-immutability/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;

import static org.assertj.core.api.Assertions.assertThat;

class Test {

public static void main(String[] args) {
final var expected = "support@hexlet.io";

ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

App.main(null);

final var actual = out.toString().trim();

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(actual);

assertThat(actual).isEqualTo(expected);
final var actual = App.normalize();
assertThat(expected).isEqualTo(actual);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
* Удаление концевых пробельных символов с помощью метода `.trim()`, например, было: `" hexlet\n "`, стало: `"hexlet"`
* Приведение к нижнему регистру с помощью метода `toLowerCase()`. Было: `"SUPPORT@hexlet.io"`, стало: `"support@hexlet.io"`.

Обновите переменную `email` записав в неё то же самое значение, но обработанное по схеме указанной выше. Распечатайте то, что получилось, на экран.
Напишите метод `normalize()`
```
public static final String email = " SupporT@hexlet.io\n";
public static String normalize() {
...
}
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь осталось про метод normalize

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вернул обратно как было. Да, теперь получается нет разницы с тем, что было раньше, за исключением теста. Причина бага как раз в нем

который для заданного значения `email` вернет его же, но обработанное по схеме указанной выше.
Loading