Skip to content
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

Merged
merged 9 commits into from
Oct 18, 2023
Merged

Hw2 #3

merged 9 commits into from
Oct 18, 2023

Conversation

bifidok
Copy link
Owner

@bifidok bifidok commented Oct 15, 2023

Не получилось протестировать 3 задание из-за рандома в выборе типа соединений и менеджера, пробовал подключить мокито - не получилось

@github-actions
Copy link

github-actions bot commented Oct 15, 2023

Code Coverage

Overall Project NaN% NaN% 🍏

There is no coverage information present for the Files changed

@infomouse
Copy link

Не получилось протестировать 3 задание из-за рандома в выборе типа соединений и менеджера, пробовал подключить мокито - не получилось

Попробуйте вот так:
image

@infomouse
Copy link

Не получилось протестировать 3 задание из-за рандома в выборе типа соединений и менеджера, пробовал подключить мокито - не получилось

Не силен в 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
@bifidok
Copy link
Owner Author

bifidok commented Oct 15, 2023

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
raphw/byte-buddy#1396
Ошибка из-за мокито появилась, но на 19 jdk тесты проходят

@infomouse
Copy link

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 raphw/byte-buddy#1396 Ошибка из-за мокито появилась, но на 19 jdk тесты проходят

А фикс из тикета пробовали?
image

@bifidok
Copy link
Owner Author

bifidok commented Oct 16, 2023

Не знал куда это вводить, спасибо

src/main/java/edu/hw2/task2/Square.java Show resolved Hide resolved
src/main/java/edu/hw2/task2/Rectangle.java Outdated Show resolved Hide resolved
src/main/java/edu/hw2/task4/Call.java Outdated Show resolved Hide resolved
package edu.hw2.task3.connection;

public interface Connection extends AutoCloseable {
double PROBABLITY_BOUND = 0.5;

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());

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;

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;

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) {

Choose a reason for hiding this comment

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

Не выполнено требование:
Если tryExecute не смог выполнить команду (превышено количество попыток), то нужно вернуть ConnectionException, при этом сохранив оригинальное исключение в параметре cause

Alexander added 2 commits October 18, 2023 17:44
fix connection exception
public final class PopularCommandExecutor {
private final ConnectionManager manager;
private final int maxAttemps;
private final static Logger LOGGER = LogManager.getLogger();

Choose a reason for hiding this comment

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

Обычно константы объявляют вначале класса и отделяют строкой от других полей.

@bifidok bifidok merged commit eac30d8 into main Oct 18, 2023
2 checks passed
@bifidok bifidok deleted the hw2 branch October 24, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants