-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw2 #3
Conversation
Test expr
refactor tasks for checkstyle
Code Coverage
|
Не силен в junit, потому что пишу тесты на spock. Но вот мой пример теста: class PopularCommandExecutorTest {
private static final int MAX_ATTEMPS = 3;
private ConnectionManager connectionManager = mock(ConnectionManager.class);
private PopularCommandExecutor executor = new PopularCommandExecutor(connectionManager, MAX_ATTEMPS);
@Test
void tryExecute() throws Exception {
String command = "test";
Connection connection = mock(Connection.class);
when(connectionManager.getConnection()).thenReturn(connection);
executor.tryExecute(command);
verify(connection, times(1)).execute(command);
verify(connection, times(1)).close();
}
} |
test PopularCommandExecutor packages renamed
Java 21 (65) is not supported by the current version of Byte Buddy which officially supports Java 20 (64) - update Byte Buddy or set net.bytebuddy.experimental as a VM property |
|
Не знал куда это вводить, спасибо |
package edu.hw2.task3.connection; | ||
|
||
public interface Connection extends AutoCloseable { | ||
double PROBABLITY_BOUND = 0.5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В интерфейсе должен быть только общий контракт для всех реализаций.
@Override | ||
public void execute(String command) { | ||
if (isConnectionFailed()) { | ||
throw new ConnectionException("Connection cannot be established", new Exception()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так неправильно делать. Если нет cause, то надо использовать конструктор без нее. Создавать смысла нет, будет просто дублирование содержимого ConnectionException.
import edu.hw2.task3.connection.Connection; | ||
|
||
public interface ConnectionManager { | ||
double PROBABLITY_BOUND = 0.5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогично Connection.
Connection connection = manager.getConnection(); | ||
try { | ||
connection.execute(command); | ||
attemps = maxAttemps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше просто сделать return. Это гораздо понятнее.
tryExecute("apt update && apt upgrade -y"); | ||
} | ||
|
||
private void tryExecute(String command) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не выполнено требование:
Если tryExecute не смог выполнить команду (превышено количество попыток), то нужно вернуть ConnectionException, при этом сохранив оригинальное исключение в параметре cause
fix connection exception
public final class PopularCommandExecutor { | ||
private final ConnectionManager manager; | ||
private final int maxAttemps; | ||
private final static Logger LOGGER = LogManager.getLogger(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обычно константы объявляют вначале класса и отделяют строкой от других полей.
Не получилось протестировать 3 задание из-за рандома в выборе типа соединений и менеджера, пробовал подключить мокито - не получилось