Skip to content

Commit

Permalink
Update karl's languages to use test runner v3 features (#2493)
Browse files Browse the repository at this point in the history
* Update karl's languages to use test runner v3 features

* refactored tests and simplified display names
  • Loading branch information
aldotele authored Sep 27, 2023
1 parent a96c084 commit 2c87b03
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
17 changes: 8 additions & 9 deletions exercises/concept/karls-languages/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"

// set default encoding to UTF-8
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
plugins {
id "java"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation "junit:junit:4.13"
testImplementation platform("org.junit:junit-bom:5.10.0")
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.assertj:assertj-core:3.15.0"
}

test {
useJUnitPlatform()

testLogging {
exceptionFormat = 'full'
exceptionFormat = "full"
showStandardStreams = true
events = ["passed", "failed", "skipped"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,42 @@
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.assertj.core.api.Assertions.*;

public class LanguageListTest {

LanguageList languageList = new LanguageList();

@Test
@Tag("task:1")
@DisplayName("The isEmpty method returns true when the list contains no languages")
public void empty() {
assertThat(languageList.isEmpty()).isTrue();
}

@Test
@Tag("task:2")
@DisplayName("The isEmpty method returns false after adding a language to the list")
public void nonEmpty() {
languageList.addLanguage("Java");

assertThat(languageList.isEmpty()).isFalse();
}

@Test
public void addOneLanguage() {
languageList.addLanguage("Java");

assertThat(languageList.containsLanguage("Java")).isTrue();
assertThat(languageList.containsLanguage("Python")).isFalse();
}

@Test
public void addMultipleLanguages() {
languageList.addLanguage("Java");
languageList.addLanguage("Ruby");
languageList.addLanguage("C++");

assertThat(languageList.containsLanguage("Java")).isTrue();
assertThat(languageList.containsLanguage("Ruby")).isTrue();
assertThat(languageList.containsLanguage("C++")).isTrue();
assertThat(languageList.containsLanguage("Python")).isFalse();
}

@Test
@Tag("task:3")
@DisplayName("The removeLanguage method correctly removes a language from the list")
public void removeLanguage() {
languageList.addLanguage("Java");
languageList.addLanguage("Python");
languageList.addLanguage("Ruby");

languageList.removeLanguage("Python");
languageList.removeLanguage("Java");

assertThat(languageList.containsLanguage("Java")).isTrue();
assertThat(languageList.containsLanguage("Python")).isFalse();
assertThat(languageList.containsLanguage("Ruby")).isTrue();
assertThat(languageList.isEmpty()).isTrue();
}

@Test
@Tag("task:4")
@DisplayName("The firstLanguage method returns the first language that was added to the list")
public void firstLanguage() {
languageList.addLanguage("Java");
languageList.addLanguage("Python");
Expand All @@ -61,6 +46,8 @@ public void firstLanguage() {
}

@Test
@Tag("task:5")
@DisplayName("The count method returns the number of languages in the list")
public void countThree() {
languageList.addLanguage("Java");
languageList.addLanguage("Python");
Expand All @@ -70,18 +57,42 @@ public void countThree() {
}

@Test
@Tag("task:5")
@DisplayName("The count method returns 0 when the list is empty")
public void countEmpty() {
assertThat(languageList.count()).isEqualTo(0);
}

@Test
@Tag("task:6")
@DisplayName("The containsLanguage method returns true when the language is in the list")
public void containsLanguage() {
languageList.addLanguage("Java");

assertThat(languageList.containsLanguage("Java")).isTrue();
}

@Test
@Tag("task:6")
@DisplayName("The containsLanguage method returns false when the language is not in the list")
public void doesNotContainLanguage() {
languageList.addLanguage("Kotlin");

assertThat(languageList.containsLanguage("Java")).isFalse();
}

@Test
@Tag("task:7")
@DisplayName("The isExciting method returns true when the list contains Java")
public void excitingLanguageListWithJava() {
languageList.addLanguage("Java");

assertThat(languageList.isExciting()).isTrue();
}

@Test
@Tag("task:7")
@DisplayName("The isExciting method returns true when the list contains Kotlin")
public void excitingLanguageListWithKotlin() {
languageList.addLanguage("Python");
languageList.addLanguage("Kotlin");
Expand All @@ -90,6 +101,8 @@ public void excitingLanguageListWithKotlin() {
}

@Test
@Tag("task:7")
@DisplayName("The isExciting method returns false when the list contains neither Java nor Kotlin")
public void boringLanguageList() {
languageList.addLanguage("Python");
languageList.addLanguage("Ruby");
Expand Down

0 comments on commit 2c87b03

Please sign in to comment.