Skip to content
Snippets Groups Projects
Commit b2f15981 authored by Arnaud LABOUREL's avatar Arnaud LABOUREL
Browse files

added junit test

parent be750f55
No related branches found
No related tags found
No related merge requests found
Pipeline #47542 passed
# From: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml
image: gradle:8.11.1-jdk23
before_script:
- GRADLE_USER_HOME="$(pwd)/.gradle"
- export GRADLE_USER_HOME
build:
stage: build
script: gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
test:
stage: test
script: gradle check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
...@@ -11,8 +11,9 @@ repositories { ...@@ -11,8 +11,9 @@ repositories {
} }
dependencies { dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0")) testImplementation("org.junit.jupiter:junit-jupiter:5.12.0")
testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.assertj:assertj-core:3.27.2")
antlr("org.antlr:antlr4:4.13.2") antlr("org.antlr:antlr4:4.13.2")
} }
......
#Thu Mar 06 13:04:05 CET 2025 #Thu Mar 06 13:04:05 CET 2025
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
...@@ -26,6 +26,9 @@ public class Characters { ...@@ -26,6 +26,9 @@ public class Characters {
} }
private static char getCharacter(String character) { private static char getCharacter(String character) {
if (character == null) {
throw new IllegalArgumentException("Character is null");
}
if(character.length() != 1 ) { if(character.length() != 1 ) {
throw new IllegalArgumentException(character + " is not a character"); throw new IllegalArgumentException(character + " is not a character");
} }
......
package sample.attributes;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
public class CharactersTest {
@Test
void testDepthOf(){
assertThat(Characters.depthOf("Z", 10)).isCloseTo(0., withinPercentage(0.001));
assertThat(Characters.depthOf("a", 10)).isCloseTo(0., withinPercentage(0.001));
assertThat(Characters.depthOf("j", 10)).isCloseTo((3./7)*10, withinPercentage(0.001));
}
@Test
void testExceptionDepthOf(){
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.depthOf("aa", 10));
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.depthOf("", 1));
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.depthOf(null, 5));
}
@Test
void testHeightOf(){
assertThat(Characters.heightOf("G", 100)).isCloseTo(100., withinPercentage(0.001));
assertThat(Characters.heightOf("l", 50)).isCloseTo(50., withinPercentage(0.001));
assertThat(Characters.heightOf("a", 105)).isCloseTo((4./7)*105, withinPercentage(0.001));
}
@Test
void testExceptionHeightOf(){
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.heightOf("mm", 10));
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.heightOf("", 1));
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> Characters.heightOf(null, 5));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment