Skip to content
Snippets Groups Projects
Commit c6464f58 authored by jez04's avatar jez04
Browse files

feat: initial version of sourcode

parent 4756f461
Branches
No related merge requests found
Pipeline #993 canceled with stages
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
\ No newline at end of file
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.vsb.fei.java2</groupId>
<artifactId>lab01-text2asciiart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lab01-text2asciiart</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
<JUnit.version>5.10.1</JUnit.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${JUnit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.leego/banana -->
<dependency>
<groupId>io.leego</groupId>
<artifactId>banana</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
</build>
</project>
package cz.vsb.fei.java2.lab01text2asciiart;
public class ConversionException extends Exception {
private static final long serialVersionUID = 195515812503598135L;
public ConversionException(String message) {
super(message);
}
}
package cz.vsb.fei.java2.lab01text2asciiart;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import io.leego.banana.BananaUtils;
import io.leego.banana.Font;
/**
* Class <b>App</b> - extends class Application and it is an entry point of the
* program
*
* @author Java I
*/
public class Text2AsciiArt {
public String convert(String text) throws ConversionException {
return convert(text, Font.STANDARD.getName());
}
public String convert(String text, String fontName) throws ConversionException {
Optional<Font> selectedFont = Font.values().stream().filter(font -> Objects.equals(font.getName(), fontName))
.findAny();
if (selectedFont.isEmpty()) {
throw new ConversionException("Uknown font name: " + fontName);
}
return BananaUtils.bananaify(text, selectedFont.get());
}
public List<String> getAllfontNames() {
return Font.values().stream().map(Font::getName).toList();
}
}
\ No newline at end of file
module cz.vsb.fei.java2.lab01text2asciiart {
requires banana;
}
\ No newline at end of file
package cz.vsb.fei.java2.jez04best;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
*/
class AppTest {
/**
* Rigorous Test :-)
*/
@Test
void shouldAnswerWithTrue() {
assertTrue(true);
}
}
package cz.vsb.fei.java2.lab01text2asciiart;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.leego.banana.Font;
class Text2AsciiArtTest {
Text2AsciiArt text2AsciiArt;
@BeforeEach
void init() {
text2AsciiArt = new Text2AsciiArt();
}
@Test
void testConvertText() throws ConversionException {
MatcherAssert.assertThat(text2AsciiArt.convert("TEST"), not(emptyOrNullString()));
}
@Test
void testConvertTextAndFont() throws ConversionException {
MatcherAssert.assertThat(text2AsciiArt.convert("TEST", "ANSI Shadow"), not(emptyOrNullString()));
}
@Test
void testConvertTextUknownFont(){
assertThrows(ConversionException.class, () -> text2AsciiArt.convert("TEST", "uknown font"));
}
@Test
void testGetAllfontNames() {
List<String> result = text2AsciiArt.getAllfontNames();
MatcherAssert.assertThat(result, not(empty()));
assertTrue(result.contains(Font.STANDARD.getName()));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment