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

Tests and small things #20

Merged
merged 56 commits into from
Jul 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2510cb2
test: Add permssions tests
alt-art Jul 13, 2024
91c7282
test: Add time converter tests
alt-art Jul 13, 2024
1e841a0
test: Add format place holder test
alt-art Jul 13, 2024
a8771d5
test: Add game event test
alt-art Jul 13, 2024
621ac21
test: Add chat event tests
alt-art Jul 13, 2024
9043570
test: Add sqlite tests
alt-art Jul 13, 2024
cfdc18c
test: Add config tests
alt-art Jul 13, 2024
1cb9edb
test: Add translations tests
alt-art Jul 13, 2024
762cc9b
test: Add telegram bot class tests
alt-art Jul 13, 2024
43c4e57
test: Add message listener feature tests
alt-art Jul 13, 2024
8c2df5e
test: Add pin message feature tests
alt-art Jul 13, 2024
d91eb1a
test: Add sent media feature tests
alt-art Jul 13, 2024
333fada
test: Add user autocomplete feature tests
alt-art Jul 13, 2024
720c194
chore: Add test dependencies to gradle
alt-art Jul 13, 2024
a839f06
fix: Log message don't need format placeholder
alt-art Jul 13, 2024
25cfd4c
fix: Config default atributes do not need to be public
alt-art Jul 13, 2024
763bf53
refactor: Use same variable already declared to get player nick
alt-art Jul 13, 2024
bd93885
refactor: Remove not needed bodyguards on advancement event
alt-art Jul 13, 2024
ebfe846
fix: Make reply messages use same username getter as the messages
alt-art Jul 13, 2024
18f3e16
refactor: Remove unneeded condition in username getter
alt-art Jul 13, 2024
8c7d1b0
refactor: Atributes from `MessageInfo` can be final
alt-art Jul 13, 2024
3187108
fix: Update pinned message only when a player enters the game
alt-art Jul 13, 2024
afcd953
refactor: Make HashMap outside the loop keeping less busy
alt-art Jul 13, 2024
697da1e
fix: Make feature public to easy access on tests
alt-art Jul 13, 2024
0cd46c0
fix: Make isNotAdmin public to easy access on tests
alt-art Jul 13, 2024
de343c0
fix: Mark unpinMessage chatId as not null
alt-art Jul 13, 2024
39b9407
fix: Mark deleteMessage chatId and messageId as not null
alt-art Jul 13, 2024
03e7193
refactor: `CommandSender` atributes can be final
alt-art Jul 13, 2024
55c2a7a
refactor: Add proper spacing on methods
alt-art Jul 13, 2024
f0358ea
refactor: Make `makeTimeMap` private
alt-art Jul 13, 2024
18391a8
fix: Make `Translation` public to easy access on tests
alt-art Jul 13, 2024
accabc0
fix: Check if `pinnedMessageId` is null to remove and unpin message
alt-art Jul 13, 2024
e971865
refactor: `argLength` can be final
alt-art Jul 13, 2024
e3e7cb4
fix: Remove one language from `TranslationsTest`
alt-art Jul 13, 2024
7c2a8be
feat: Send player leave message when server stops
alt-art Jul 13, 2024
e143292
feat: Add server start and stop log config and fix boolean config load
alt-art Jul 13, 2024
4dc3e6a
docs: Add server start and stop to config documentation
alt-art Jul 13, 2024
d64c5ae
docs: Add server start and stop to test
alt-art Jul 13, 2024
ff5c187
feat: Server start and stop events translations
alt-art Jul 13, 2024
0535b34
feat: Server start and stop events translations
alt-art Jul 13, 2024
8d662d3
refactor: Small typo in resource folder variable
alt-art Jul 13, 2024
17f8176
test: Pseudo lang server start and stop translation
alt-art Jul 13, 2024
4f7f589
feat: Start and stop event logs
alt-art Jul 13, 2024
0f3dee2
chore: Add actions test
alt-art Jul 13, 2024
19d9e56
fix: Change java version to see if actions works
alt-art Jul 13, 2024
c70d1b1
fix: Change gradlew command to see if actions works
alt-art Jul 13, 2024
3a46753
fix: Specify the test report path to see if actions works
alt-art Jul 13, 2024
c3636a9
fix: Return false when the command don't succeed
alt-art Jul 13, 2024
95677cf
test: Add `ConfigCommand` tests
alt-art Jul 13, 2024
5c4db94
test: Add `ConfigTabCompletion` tests
alt-art Jul 13, 2024
00f6b69
test: Add `MentionCommand` tests
alt-art Jul 19, 2024
6ba3d20
test: Add `ReloadCommand` tests
alt-art Jul 19, 2024
b9c1a24
test: Add `ReplyCommand` tests
alt-art Jul 19, 2024
7c409f7
test: Add `UserTabCompletion` tests
alt-art Jul 19, 2024
64e8bc6
fix: Make feature fields final to do tests
alt-art Jul 19, 2024
574db30
test: Fix `ConfigTest` amount of fields
alt-art Jul 19, 2024
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
Prev Previous commit
Next Next commit
test: Add translations tests
  • Loading branch information
alt-art committed Jul 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1cb9edbbfd8ac92d3ed0448928c54be1855cb5c9
149 changes: 149 additions & 0 deletions src/test/java/org/altart/telegrambridge/config/TranslationsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package org.altart.telegrambridge.config;

import org.altart.telegrambridge.StandardMockTest;
import org.altart.telegrambridge.TelegramBridge;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class TranslationsTest extends StandardMockTest {
@Mock
Plugin mockPlugin;

@Test
@DisplayName("Get translation")
void getTranslation() {
File resourseFolder = new File("src/test/resources");
when(mockPlugin.getDataFolder()).thenReturn(resourseFolder);

TelegramBridge.plugin = mockPlugin;

Translations translations = new Translations("en");
List<String> languageCodes = translations.getLoadedLanguages();
List<String> expectedLanguageCodes = Arrays.asList("en", "es", "jp", "pt", "ru", "uk", "tt");
assertEquals(expectedLanguageCodes.size(), languageCodes.size());
for (String lang : expectedLanguageCodes) {
assertTrue(languageCodes.contains(lang));
}
Translations.Translation translation = translations.get(null);
assertNotNull(translation);
verify(mockPlugin, times(1)).getDataFolder();
Field[] fields = translation.getClass().getDeclaredFields();
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new File(resourseFolder, "lang/en.yml"));
for (Field field : fields) {
field.setAccessible(true);
try {
if (field.getName().equals("__$hits$__")) {
continue;
}
assertEquals(yamlConfiguration.get(field.getName()), field.get(translation));
} catch (IllegalAccessException e) {
System.out.println(e.getMessage());
fail();
}
}
}

@Test
@DisplayName("Set default language")
void setDefaultLang() {
File resourseFolder = new File("src/test/resources");
when(mockPlugin.getDataFolder()).thenReturn(resourseFolder);

TelegramBridge.plugin = mockPlugin;

Translations translations = new Translations(null);
try {
translations.setDefaultLang("pt");
} catch (Exception e) {
fail();
}

Field[] fields = translations.get().getClass().getDeclaredFields();
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new File(resourseFolder, "lang/pt.yml"));
for (Field field : fields) {
field.setAccessible(true);
try {
if (field.getName().equals("__$hits$__")) {
continue;
}
assertEquals(yamlConfiguration.get(field.getName()), field.get(translations.get()));
} catch (IllegalAccessException e) {
System.out.println(e.getMessage());
fail();
}
}
}

@Test
@DisplayName("Set default language with invalid language and non-existent file")
void translationExceptions() {
File resourseFolder = new File("src/test/resources");
when(mockPlugin.getDataFolder()).thenReturn(resourseFolder);

TelegramBridge.plugin = mockPlugin;

Translations translations = new Translations(null);
assertThrows(Exception.class, () -> translations.setDefaultLang("fr"));

File mockFile = mock(File.class);
when(mockFile.exists()).thenReturn(false);
new Translations.Translation(mockFile);
verify(mockFile, times(1)).exists();
}

@Test
@DisplayName("Empty translations directory")
void emptyTranslationsDirectory() {
File resourseFolder = new File("src/test/resources/empty");
when(mockPlugin.getDataFolder()).thenReturn(resourseFolder);

TelegramBridge.plugin = mockPlugin;

new Translations(null);

verify(mockPlugin, times(1)).getDataFolder();
List<String> languageCodes = new Translations(null).getLoadedLanguages();
for (String lang : languageCodes) {
verify(mockPlugin, times(1)).saveResource("lang/" + lang + ".yml", false);
}

File langDir = new File(resourseFolder, "lang");
assertTrue(langDir.delete());
assertTrue(resourseFolder.delete());
}

@Test
@DisplayName("File passed as directory")
void nullTranslationsDirectory() {
File fileAsDir = new File("src/test/resources/lang/lang");
try {
assertTrue(fileAsDir.createNewFile());
} catch (IOException e) {
fail();
}

File translationsFolder = new File("src/test/resources/lang");
when(mockPlugin.getDataFolder()).thenReturn(translationsFolder);

TelegramBridge.plugin = mockPlugin;

new Translations(null);

verify(mockPlugin, times(1)).getDataFolder();
verify(mockPlugin, never()).saveResource("lang/tt.yml", false);

assertTrue(fileAsDir.delete());
}
}