-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Add some failing unit tests and improve the existing ones
- Loading branch information
Showing
33 changed files
with
1,044 additions
and
21 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
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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
core/src/test/java/be/darkkraft/transferproxy/network/packet/PacketTestBase.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,57 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet; | ||
|
||
import be.darkkraft.transferproxy.api.network.packet.Packet; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.util.function.Function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PacketTestBase { | ||
|
||
private ByteBuf buf; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
this.buf = Unpooled.buffer(); | ||
} | ||
|
||
protected <T extends Packet> void test(final T packet, final Function<ByteBuf, T> builder) { | ||
packet.write(this.buf); | ||
assertEquals(packet, builder.apply(this.buf)); | ||
assertEquals(0, this.buf.readableBytes()); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
this.buf.release(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
.../java/be/darkkraft/transferproxy/network/packet/config/FinishConfigurationPacketTest.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,37 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet.config; | ||
|
||
import be.darkkraft.transferproxy.network.packet.PacketTestBase; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FinishConfigurationPacketTest extends PacketTestBase { | ||
|
||
@Test | ||
void testWriteReadConsistency() { | ||
this.test(new FinishConfigurationPacket(), FinishConfigurationPacket::new); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
core/src/test/java/be/darkkraft/transferproxy/network/packet/config/KeepAlivePacketTest.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,39 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet.config; | ||
|
||
import be.darkkraft.transferproxy.network.packet.PacketTestBase; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class KeepAlivePacketTest extends PacketTestBase { | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {0L, 5L, Long.MIN_VALUE, Long.MAX_VALUE}) | ||
void testWriteReadConsistency(final long payload) { | ||
this.test(new KeepAlivePacket(payload), KeepAlivePacket::new); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...c/test/java/be/darkkraft/transferproxy/network/packet/config/PluginMessagePacketTest.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,39 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet.config; | ||
|
||
import be.darkkraft.transferproxy.network.packet.PacketTestBase; | ||
import be.darkkraft.transferproxy.network.packet.config.payload.BrandPayload; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PluginMessagePacketTest extends PacketTestBase { | ||
|
||
@Test | ||
void testWriteReadConsistency() { | ||
this.test(new PluginMessagePacket("minecraft:brand", new BrandPayload("vanilla")), PluginMessagePacket::from); | ||
this.test(new PluginMessagePacket("minecraft:unknown", null), PluginMessagePacket::from); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
.../darkkraft/transferproxy/network/packet/config/clientbound/AddResourcePackPacketTest.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,64 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet.config.clientbound; | ||
|
||
import be.darkkraft.transferproxy.network.packet.PacketTestBase; | ||
import be.darkkraft.transferproxy.util.test.TestGenerationUtil; | ||
import io.netty.handler.codec.DecoderException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class AddResourcePackPacketTest extends PacketTestBase { | ||
|
||
@Test | ||
void testWriteReadConsistency() { | ||
this.test(new AddResourcePackPacket(UUID.randomUUID(), "url", "hash", true, TestGenerationUtil.generateComplexComponent()), | ||
AddResourcePackPacket::new); | ||
} | ||
|
||
@Test | ||
void testWriteTooLongUrl() { | ||
assertThrows(DecoderException.class, | ||
() -> this.test(new AddResourcePackPacket(UUID.randomUUID(), | ||
"a".repeat(Short.MAX_VALUE + 1), | ||
"hash", | ||
true, | ||
TestGenerationUtil.generateComplexComponent()), AddResourcePackPacket::new)); | ||
} | ||
|
||
@Test | ||
void testWriteTooLongHash() { | ||
assertThrows(DecoderException.class, | ||
() -> this.test(new AddResourcePackPacket(UUID.randomUUID(), | ||
"url", | ||
"a".repeat(41), | ||
true, | ||
TestGenerationUtil.generateComplexComponent()), AddResourcePackPacket::new)); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...kkraft/transferproxy/network/packet/config/clientbound/ConfigCookieRequestPacketTest.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,37 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Darkkraft | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package be.darkkraft.transferproxy.network.packet.config.clientbound; | ||
|
||
import be.darkkraft.transferproxy.network.packet.PacketTestBase; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ConfigCookieRequestPacketTest extends PacketTestBase { | ||
|
||
@Test | ||
void testWriteReadConsistency() { | ||
this.test(new ConfigCookieRequestPacket("minecraft:cookie_key"), ConfigCookieRequestPacket::new); | ||
} | ||
|
||
} |
Oops, something went wrong.