Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Robothy committed Oct 11, 2023
1 parent ec670c1 commit 67d3c51
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ dependencies {
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}

tasks.compileJava {
options.encoding = "UTF-8"
}

tasks.compileTestJava {
options.encoding = "UTF-8"
}

test {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/robothy/sdwebui/sdk/Txt2Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

public interface Txt2Image {

/**
* Generate images from text.
*
* @param options The options to generate images.
* @return The result of the generation.
*
* @throws io.github.robothy.sdwebui.sdk.exceptions.SdWebuiServerValidationException
* @throws io.github.robothy.sdwebui.sdk.exceptions.SdWebuiBadRequestException
*/
Txt2ImgResult txt2Img(Txt2ImageOptions options);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.robothy.sdwebui.sdk.models;

import static org.junit.jupiter.api.Assertions.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

class SystemInfoTest {

@Test
void testSerialization() throws JsonProcessingException {
SystemInfo systemInfo = new SystemInfo();
systemInfo.setEndpoint("http://localhost:8080");
systemInfo.setPlatform("Linux");
systemInfo.setPythonVersion("3.8.5");
systemInfo.setSdwebuiVersion("0.0.1");
ObjectMapper objectMapper = new ObjectMapper();
assertEquals(systemInfo, objectMapper
.readValue(objectMapper.writeValueAsString(systemInfo), SystemInfo.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.robothy.sdwebui.sdk.models.results;

import static org.junit.jupiter.api.Assertions.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.robothy.sdwebui.sdk.models.options.Txt2ImageOptions;
import java.util.List;
import org.junit.jupiter.api.Test;

class Txt2ImgResultTest {

@Test
void testSerialization() throws JsonProcessingException {
Txt2ImgResult txt2ImgResult = new Txt2ImgResult();
txt2ImgResult.setImages(List.of("image1", "image2"));
txt2ImgResult.setInfo("info");
txt2ImgResult.setParameters(Txt2ImageOptions.builder()
.prompt("1dog")
.build());

ObjectMapper objectMapper = new ObjectMapper();
assertEquals(txt2ImgResult, objectMapper.readValue(objectMapper
.writeValueAsString(txt2ImgResult), Txt2ImgResult.class));
}

}

0 comments on commit 67d3c51

Please sign in to comment.