Refactored duplicated tests into a parameterized one (#5077)
* Added test parameters to avoid code duplication Signed-off-by: Elvys Soares <eas5@cin.ufpe.br> * Added test parameters to avoid code duplication and updated JUnit to 5.7.1 version Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>
This commit is contained in:
@@ -416,10 +416,10 @@ project(":tests"){
|
|||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
testImplementation project(":core")
|
testImplementation project(":core")
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-params:5.3.1"
|
testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.1"
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.1"
|
||||||
testImplementation arcModule("backends:backend-headless")
|
testImplementation arcModule("backends:backend-headless")
|
||||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.1"
|
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
test{
|
test{
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import arc.util.io.*;
|
|||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.params.*;
|
||||||
|
import org.junit.jupiter.params.provider.*;
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
@@ -10,28 +12,17 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
public class IOTests{
|
public class IOTests{
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
void writeEnglish(){
|
@NullSource
|
||||||
|
@ValueSource(strings = {
|
||||||
|
"asd asd asd asd asdagagasasjakbgeah;jwrej 23424234",
|
||||||
|
"这个服务器可以用自己的语言说话"
|
||||||
|
})
|
||||||
|
void writeStringTest(String string){
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||||
TypeIO.writeString(buffer, "asd asd asd asd asdagagasasjakbgeah;jwrej 23424234");
|
TypeIO.writeString(buffer, string);
|
||||||
buffer.position(0);
|
buffer.position(0);
|
||||||
assertEquals(TypeIO.readString(buffer), "asd asd asd asd asdagagasasjakbgeah;jwrej 23424234");
|
assertEquals(TypeIO.readString(buffer), string);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void writeChinese(){
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
|
||||||
TypeIO.writeString(buffer, "这个服务器可以用自己的语言说话");
|
|
||||||
buffer.position(0);
|
|
||||||
assertEquals(TypeIO.readString(buffer), "这个服务器可以用自己的语言说话");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void writeNull(){
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
|
||||||
TypeIO.writeString(buffer, null);
|
|
||||||
buffer.position(0);
|
|
||||||
assertNull(TypeIO.readString(buffer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user