Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Added JUnit libary #17

Closed
wants to merge 5 commits into from
Closed

Added JUnit libary #17

wants to merge 5 commits into from

Conversation

fwustrack
Copy link

I have added JUnit jupiter and assertJ to the project to make it easier to write tests in the future

Copy link
Collaborator

@SizableShrimp SizableShrimp left a comment

Choose a reason for hiding this comment

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

Really great start to making tests for the server bot. Thank you for taking the initiative of working on this!

Comment on lines 1 to +4
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this changed? Apache may have their own specific standard, but that is not much different from the original header before this change. I believe the original header is the default for generating a POM in IntelliJ and should work fine for our project. Having a line for the XML stating the version and encoding is also important to ensure there are zero possible compatibility issues between any IDEs or editors.

@@ -14,26 +15,26 @@

public class BotMain {

private static final Logger logger = LoggerFactory.getLogger(BotMain.class);
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use MethodHandles? With a proper IDE refactoring function, this should not be necessary if the class name is ever changed. MethodHandles is more low-level compared to Reflection and should not be used in a repository aimed at allowing beginner programmers to commit and view code. Using a direct call to .class from the name of the class seems easier and better for performance and code readability. However, I do believe the logger name change is better suited to fit conventions.

/**
* A command listener for JDA. It is responsible for listening to messages an invoking commands.
*/
public class CommandListener extends ListenerAdapter {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment on MessageHandles in BotMain. I believe this class should have a logger but make sure to keep formatting the same, as you accidentally deleted the empty line put between the first variable and the class declaration line.

@@ -54,6 +58,7 @@ public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
);
executor.execute(content, context);
} catch (CommandNotFoundException | NoSeparatorException ignored) {
LOG.trace("Command not foundor no separator in message {}", content);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small little typing issue.

Suggested change
LOG.trace("Command not foundor no separator in message {}", content);
LOG.trace("Command not found or no separator in message {}", content);

Comment on lines +16 to +18
private UserParsers() {
throw new IllegalStateException("Utility class");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be important to decide if we should throw an exception like this to state that this is a utility class or just have a single line of private UserParsers() {} and expect future contributors of this class or any other util class to not instantiate this class? Since we are targeting this repository towards beginners, it might make sense. However, this may not be necessary.

import java.util.Map;
import java.util.Optional;

/**
* A collection of messages, read from a file and maybe translated.
*/
public class Messages {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Copy link
Collaborator

Choose a reason for hiding this comment

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

See message on MethodHandles in BotMain.

});
} catch (IOException e) {
e.printStackTrace();
LOG.error("An error occurred while reading messages ",e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No space necessary. Maybe a typo when trying to put a space after the comma?

Suggested change
LOG.error("An error occurred while reading messages ",e);
LOG.error("An error occurred while reading messages", e);

import org.junit.jupiter.api.Test;

import java.time.Duration;
import static org.assertj.core.api.Assertions.*;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Space between imports and class declaration for standard.

Suggested change
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;

import static org.assertj.core.api.Assertions.*;
class DurationFormatterTest {

private DurationFormatter durationFormatterUnderTest;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a long variable name for no reason. A better name would be formatter or durationFormatter.


private DurationFormatter durationFormatterUnderTest;

@BeforeEach
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see no point in creating a new DurationFormatter before each test, maybe use @BeforeAll? Also, we may want to convert DurationFormatter to a static util class; however this can be done at a later date.

Suggested change
@BeforeEach
@BeforeAll

@SizableShrimp SizableShrimp added the enhancement New feature or request label Feb 7, 2020
@SizableShrimp SizableShrimp linked an issue Feb 7, 2020 that may be closed by this pull request
@SizableShrimp SizableShrimp removed a link to an issue Feb 7, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants