This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: PermSyncの動作不良修正、テストコード追加 (#310)
- Loading branch information
Showing
3 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/test/com/jaoafa/javajaotan2/lib/DiscordMinecraftLinkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.jaoafa.javajaotan2.lib; | ||
|
||
import com.jaoafa.javajaotan2.Main; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SuppressWarnings("FieldCanBeLocal") | ||
class DiscordMinecraftLinkTest { | ||
private final String minecraftName = "mine_book000"; | ||
private final UUID minecraftUUID = UUID.fromString("32ff7cdc-a1b4-450a-aa7e-6af75fe8c37c"); | ||
private final String discordName = "tomachi"; | ||
private final String discordDiscriminator = "0310"; | ||
private final long discordId = 221991565567066112L; | ||
|
||
DiscordMinecraftLink linkForMinecraft; | ||
DiscordMinecraftLink linkForDiscord; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
try { | ||
Main.setConfig(new JavajaotanConfig()); | ||
} catch (RuntimeException e) { | ||
e.printStackTrace(); | ||
return; // CI用 | ||
} | ||
try { | ||
linkForMinecraft = DiscordMinecraftLink.get(minecraftUUID); | ||
linkForDiscord = DiscordMinecraftLink.get(discordId); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
assertNotNull(linkForMinecraft); | ||
assertNotNull(linkForDiscord); | ||
} | ||
|
||
@Test | ||
void isFound() { | ||
assertTrue(linkForMinecraft.isFound()); | ||
assertTrue(linkForDiscord.isFound()); | ||
} | ||
|
||
@Test | ||
void isLinked() { | ||
assertTrue(linkForMinecraft.isLinked()); | ||
assertTrue(linkForDiscord.isLinked()); | ||
} | ||
|
||
@Test | ||
void getMinecraftName() { | ||
assertEquals(minecraftName, linkForMinecraft.getMinecraftName()); | ||
assertEquals(minecraftName, linkForDiscord.getMinecraftName()); | ||
} | ||
|
||
@Test | ||
void getMinecraftUUID() { | ||
assertEquals(minecraftUUID, linkForMinecraft.getMinecraftUUID()); | ||
assertEquals(minecraftUUID, linkForDiscord.getMinecraftUUID()); | ||
} | ||
|
||
@Test | ||
void getDiscordId() { | ||
assertEquals(Long.toUnsignedString(discordId), linkForMinecraft.getDiscordId()); | ||
assertEquals(Long.toUnsignedString(discordId), linkForDiscord.getDiscordId()); | ||
} | ||
|
||
@Test | ||
void getDiscordName() { | ||
assertEquals(discordName, linkForMinecraft.getDiscordName()); | ||
assertEquals(discordName, linkForDiscord.getDiscordName()); | ||
} | ||
|
||
@Test | ||
void getDiscordDiscriminator() { | ||
assertEquals(discordDiscriminator, linkForMinecraft.getDiscordDiscriminator()); | ||
assertEquals(discordDiscriminator, linkForDiscord.getDiscordDiscriminator()); | ||
} | ||
|
||
@Test | ||
void getDisconnectPermGroup() { | ||
assertNull(linkForMinecraft.getDisconnectPermGroup()); | ||
assertNull(linkForDiscord.getDisconnectPermGroup()); | ||
} | ||
|
||
@Test | ||
void getAllForMinecraft() throws SQLException { | ||
List<DiscordMinecraftLink> connections = DiscordMinecraftLink.getAllForMinecraft(); | ||
DiscordMinecraftLink dml = connections | ||
.stream() | ||
.filter(c -> c.getDiscordId().equals(Long.toUnsignedString(discordId))) | ||
.findFirst() | ||
.orElse(null); | ||
assertNotNull(dml); | ||
assertTrue(dml.isFound()); | ||
assertTrue(dml.isLinked()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/com/jaoafa/javajaotan2/lib/MinecraftPermGroupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.jaoafa.javajaotan2.lib; | ||
|
||
import com.jaoafa.javajaotan2.Main; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class MinecraftPermGroupTest { | ||
MinecraftPermGroup mpg; | ||
|
||
@BeforeEach | ||
void setUp() throws SQLException { | ||
try { | ||
Main.setConfig(new JavajaotanConfig()); | ||
} catch (RuntimeException e) { | ||
e.printStackTrace(); | ||
return; // CI用 | ||
} | ||
mpg = new MinecraftPermGroup(UUID.fromString("32ff7cdc-a1b4-450a-aa7e-6af75fe8c37c")); | ||
} | ||
|
||
@Test | ||
void isFound() { | ||
assertTrue(mpg.isFound()); | ||
} | ||
|
||
@Test | ||
void getGroup() { | ||
assertEquals(MinecraftPermGroup.Group.ADMIN, mpg.getGroup()); | ||
} | ||
|
||
@Test | ||
void isTemporary() { | ||
assertFalse(mpg.isTemporary()); | ||
} | ||
|
||
@Test | ||
void getExpiredAt() { | ||
assertNull(mpg.getExpiredAt()); | ||
} | ||
} |