Skip to content

Commit

Permalink
Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK committed Aug 18, 2023
1 parent 6aa1046 commit c4cb9af
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 56 deletions.
30 changes: 0 additions & 30 deletions src/test/java/com/github/imdmk/automessage/DurationUtilTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.imdmk.automessage;

import com.github.imdmk.automessage.notification.Notification;
import com.github.imdmk.automessage.notification.NotificationFormatter;
import com.github.imdmk.automessage.notification.implementation.ChatNotification;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class NotificationFormatterTest {

@Test
void testFormat() {
ChatNotification notificationToFormat = new ChatNotification("This plugin is called {PLUGIN} and its author is {AUTHOR}.");

Notification excepted = new ChatNotification("This plugin is called AutoMessage and its author is imDMK.");
Notification result = new NotificationFormatter(notificationToFormat)
.placeholder("{PLUGIN}", "AutoMessage")
.placeholder("{AUTHOR}", "imDMK")
.build();

assertEquals(excepted, result);
}
}
26 changes: 0 additions & 26 deletions src/test/java/com/github/imdmk/automessage/StringUtilTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.imdmk.automessage.util;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ComponentUtilTest {

@Test
void testDeserialize() {
String resultContent = "<red>DMK";

Component result = ComponentUtil.deserialize(resultContent);
Component excepted = Component.text("DMK").color(NamedTextColor.RED);

assertEquals(excepted, result);
}

@Test
void testLegacyDeserialize() {
String resultContent = "§4DMK";

Component result = ComponentUtil.deserialize(resultContent);
Component excepted = Component.text("DMK").color(NamedTextColor.DARK_RED);

assertEquals(excepted, result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.imdmk.automessage.util;

import org.junit.jupiter.api.Test;

import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DurationUtilTest {

@Test
void testHumanReadable() {
Duration ofSeconds = Duration.ofSeconds(5);
String secondsExcepted = "5s";
String secondsResult = DurationUtil.toHumanReadable(ofSeconds);

Duration ofMinutes = Duration.ofMinutes(5);
String minutesExcepted = "5m";
String minutesResult = DurationUtil.toHumanReadable(ofMinutes);

Duration ofHours = Duration.ofHours(10);
String hoursExcepted = "10h";
String hoursResult = DurationUtil.toHumanReadable(ofHours);

assertEquals(secondsExcepted, secondsResult);
assertEquals(minutesExcepted, minutesResult);
assertEquals(hoursExcepted, hoursResult);
}

@Test
void testToTicks() {
Duration ofSeconds = Duration.ofSeconds(6);
long ofSecondsExcepted = 120;
long ofSecondsResult = DurationUtil.toTicks(ofSeconds);

Duration ofMinutes = Duration.ofMinutes(3);
long ofMinutesExcepted = 3600;
long ofMinutesResult = DurationUtil.toTicks(ofMinutes);

assertEquals(ofSecondsExcepted, ofSecondsResult);
assertEquals(ofMinutesExcepted, ofMinutesResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.imdmk.automessage.util;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class RandomUtilTest {

@Test
void testRandom() {
List<String> strings = List.of("DMK", "AutoMessage");

Optional<String> randomString = RandomUtil.getRandom(strings);

assertTrue(randomString.isPresent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.imdmk.automessage.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class StringUtilTest {

@Test
void isIntegerTest() {
String integer = "10";
boolean excepted = true;

assertEquals(excepted, StringUtil.isInteger(integer));
}
}

0 comments on commit c4cb9af

Please sign in to comment.