Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Ticket/GP-7 Upgrade tdd-exercises completed with "Junit 5" tests #12

Merged
merged 2 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.bobocode.bst;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertThat;

@RunWith(JUnit4.class)
public class BinarySearchTreeTest {

private BinarySearchTree<Integer> bst = new RecursiveBinarySearchTree<>();
Expand Down
40 changes: 21 additions & 19 deletions linked-list/src/test/java/com/bobocode/LinkedListTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.bobocode;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import org.junit.jupiter.api.Test;

import java.util.NoSuchElementException;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;


@RunWith(JUnit4.class)
public class LinkedListTest {

private List<Integer> intList = new LinkedList<>();
Expand Down Expand Up @@ -63,14 +65,14 @@ public void testGetLastElement() {
assertEquals(42, intList.getLast().intValue());
}

@Test(expected = NoSuchElementException.class)
@Test
public void testGetFirstOfEmptyList() {
intList.getFirst();
assertThrows(NoSuchElementException.class, () -> intList.getFirst());
}

@Test(expected = NoSuchElementException.class)
@Test
public void testGetLastOfEmptyList() {
intList.getLast();
assertThrows(NoSuchElementException.class, () -> intList.getLast());
}

@Test
Expand All @@ -82,23 +84,23 @@ public void testGetElementByIndex() {
assertEquals(52, intList.get(2).intValue());
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testGetElementByIndexOfEmptyTree() {
intList.get(1);
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(1));
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testGetElementByNegativeIndex() {
intList = LinkedList.of(1, 2, 3);

intList.get(-2);
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(-2));
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testGetElementBySizeIndex() {
intList = LinkedList.of(1, 2, 3);

intList.get(3);
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(3));
}

@Test
Expand Down Expand Up @@ -156,11 +158,11 @@ public void testSetElementByIndex() {
assertEquals(3, intList.size());
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testSetElementByInvalidIndex() {
intList = LinkedList.of(110, 111);

intList.set(3, 114);
assertThrows(IndexOutOfBoundsException.class, () -> intList.set(3, 114));
}

@Test
Expand Down Expand Up @@ -210,9 +212,9 @@ public void testRemoveSingleElementByIndex() {
assertEquals(0, intList.size());
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testRemoveElementOfEmptyList() {
intList.remove(0);
assertThrows(IndexOutOfBoundsException.class, () -> intList.remove(0));
}

@Test
Expand Down
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -40,4 +40,16 @@
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
14 changes: 5 additions & 9 deletions stack/src/test/java/com/bobocode/StackTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.bobocode;

import com.bobocode.exception.EmptyStackException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

@RunWith(JUnit4.class)
public class StackTest {

private Stack<Integer> intStack = new NodeStack<>();
Expand All @@ -20,9 +16,9 @@ public void testPushElementOntoEmptyStack() {
intStack.push(234);
}

@Test(expected = EmptyStackException.class)
@Test
public void testPopElementFromEmptyStack() {
intStack.pop();
assertThrows(EmptyStackException.class, () -> intStack.pop());
}

@Test
Expand Down