Skip to content

Upgrade to JUnit 5 for unit tests #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
<junit.version>5.5.2</junit.version>
<hamcrest.version>1.3</hamcrest.version>
<mockito.version>1.10.19</mockito.version>
<jdk.source.version>1.8</jdk.source.version>
Expand Down Expand Up @@ -223,8 +223,14 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/tagtraum/perf/gcviewer/GCViewerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author martin.geldmacher
*/
public class GCViewerTest {
class GCViewerTest {

@Test
public void singleArgumentOpensGui() throws Exception {
void singleArgumentOpensGui() throws Exception {
GCViewerGuiController controller = mock(GCViewerGuiController.class);
GCViewer gcViewer = new GCViewer(controller, new GCViewerArgsParser());

Expand All @@ -32,7 +32,7 @@ public void singleArgumentOpensGui() throws Exception {
}

@Test
public void singleArgumentWithSeriesOpensGui() throws Exception {
void singleArgumentWithSeriesOpensGui() throws Exception {
GCViewerGuiController controller = mock(GCViewerGuiController.class);
GCViewer gcViewer = new GCViewer(controller, new GCViewerArgsParser());

Expand All @@ -43,7 +43,7 @@ public void singleArgumentWithSeriesOpensGui() throws Exception {
}

@Test
public void moreThan3ArgumentsPrintsUsage() throws Exception {
void moreThan3ArgumentsPrintsUsage() throws Exception {
GCViewerGuiController controller = mock(GCViewerGuiController.class);
GCViewer gcViewer = new GCViewer(controller, new GCViewerArgsParser());

Expand All @@ -54,7 +54,7 @@ public void moreThan3ArgumentsPrintsUsage() throws Exception {
}

@Test
public void export() throws Exception {
void export() throws Exception {
GCViewerGuiController controller = mock(GCViewerGuiController.class);
GCViewer gcViewer = new GCViewer(controller, new GCViewerArgsParser());

Expand All @@ -65,7 +65,7 @@ public void export() throws Exception {
}

@Test
public void exportFileNotFound() throws Exception {
void exportFileNotFound() throws Exception {
GCViewerGuiController controller = mock(GCViewerGuiController.class);
GCViewer gcViewer = new GCViewer(controller, new GCViewerArgsParser());

Expand All @@ -76,7 +76,7 @@ public void exportFileNotFound() throws Exception {
}

@Test
public void illegalExportFormat() throws Exception {
void illegalExportFormat() throws Exception {
GCViewer gcViewer = new GCViewer();

String[] args = {"-t", "INVALID"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.tagtraum.perf.gcviewer;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import org.junit.Test;

import com.tagtraum.perf.gcviewer.util.BuildInfoReader;
import org.junit.jupiter.api.Test;

/**
* Tests the class {@link BuildInfoReader} - makes sure that the properties from the file
Expand All @@ -16,17 +15,17 @@
* @author <a href="mailto:gcviewer@gmx.ch">Joerg Wuethrich</a>
* <p>created on: 05.12.2012</p>
*/
public class TestBuildInfoReader {
class TestBuildInfoReader {

@Test
public void readVersion() {
void readVersion() {
String version = BuildInfoReader.getVersion();
assertThat("version", version, notNullValue());
assertThat("must not be empty", version, not(isEmptyOrNullString()));
}

@Test
public void readBuildDate() {
void readBuildDate() {
String buildDate = BuildInfoReader.getBuildDate();
assertThat("buildDate", buildDate, notNullValue());
assertThat("must not be empty", buildDate, not(isEmptyOrNullString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Tests the class {@link com.tagtraum.perf.gcviewer.GCViewerArgsParser}
Expand All @@ -19,99 +22,94 @@
* @author <a href="mailto:smendenh@redhat.com">Samuel Mendenhall</a>
* <p>created on: 06.09.2014</p>
*/
public class TestGCViewerArgsParser {
class TestGCViewerArgsParser {

@Test
public void noArguments() throws Exception {
void noArguments() throws Exception {
String[] args = {};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 0);
assertEquals(gcViewerArgsParser.getType(), DataWriterType.SUMMARY);
assertEquals(0, gcViewerArgsParser.getArgumentCount());
assertEquals(DataWriterType.SUMMARY, gcViewerArgsParser.getType());
}

@Test
public void onlyGCLog() throws Exception {
void onlyGCLog() throws Exception {
String[] args = {"some_gc.log"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 1);
assertEquals(gcViewerArgsParser.getGcResource(), new GcResourceFile("some_gc.log"));
assertEquals(gcViewerArgsParser.getType(), DataWriterType.SUMMARY);
assertEquals(1, gcViewerArgsParser.getArgumentCount());
assertEquals(new GcResourceFile("some_gc.log"), gcViewerArgsParser.getGcResource());
assertEquals(DataWriterType.SUMMARY, gcViewerArgsParser.getType());
}

@Test
public void onlyGcLogSeries() throws Exception {
void onlyGcLogSeries() throws Exception {
String[] args = {"some_gc.log.0;some_gc.log.1;some_gc.log.2"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 1);
assertEquals(1, gcViewerArgsParser.getArgumentCount());
List<GCResource> resources = Arrays.asList(new GcResourceFile("some_gc.log.0"), new GcResourceFile("some_gc.log.1"), new GcResourceFile("some_gc.log.2"));
assertEquals(gcViewerArgsParser.getGcResource(), new GcResourceSeries(resources));
assertEquals(gcViewerArgsParser.getType(), DataWriterType.SUMMARY);
assertEquals(new GcResourceSeries(resources), gcViewerArgsParser.getGcResource());
assertEquals(DataWriterType.SUMMARY, gcViewerArgsParser.getType());
}

@Test
public void gcAndExportFile() throws Exception {
void gcAndExportFile() throws Exception {
String[] args = {"some_gc.log", "export_to.csv"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 2);
assertEquals(gcViewerArgsParser.getGcResource(), new GcResourceFile("some_gc.log"));
assertEquals(gcViewerArgsParser.getSummaryFilePath(), "export_to.csv");
assertEquals(gcViewerArgsParser.getType(), DataWriterType.SUMMARY);
assertEquals(2, gcViewerArgsParser.getArgumentCount());
assertEquals(new GcResourceFile("some_gc.log"), gcViewerArgsParser.getGcResource());
assertEquals("export_to.csv", gcViewerArgsParser.getSummaryFilePath());
assertEquals(DataWriterType.SUMMARY, gcViewerArgsParser.getType());
}

@Test
public void gcSeriesAndExportFile() throws Exception {
void gcSeriesAndExportFile() throws Exception {
String[] args = {"some_gc.log.0;some_gc.log.1;some_gc.log.2", "export_to.csv"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 2);
assertEquals(2, gcViewerArgsParser.getArgumentCount());
List<GCResource> resources = Arrays.asList(new GcResourceFile("some_gc.log.0"), new GcResourceFile("some_gc.log.1"), new GcResourceFile("some_gc.log.2"));
assertEquals(gcViewerArgsParser.getGcResource(), new GcResourceSeries(resources));
assertEquals(gcViewerArgsParser.getSummaryFilePath(), "export_to.csv");
assertEquals(gcViewerArgsParser.getType(), DataWriterType.SUMMARY);
assertEquals(new GcResourceSeries(resources), gcViewerArgsParser.getGcResource());
assertEquals("export_to.csv", gcViewerArgsParser.getSummaryFilePath());
assertEquals(DataWriterType.SUMMARY, gcViewerArgsParser.getType());
}

@Test
public void onlyType() throws Exception {
void onlyType() throws Exception {
String[] args = {"-t", "CSV_TS"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 0);
assertEquals(gcViewerArgsParser.getType(), DataWriterType.CSV_TS);
assertEquals(0, gcViewerArgsParser.getArgumentCount());
assertEquals(DataWriterType.CSV_TS, gcViewerArgsParser.getType());
}

@Test
public void allInitialArgsWithType() throws Exception {
void allInitialArgsWithType() throws Exception {
String[] args = {"some_gc.log", "export_to.csv", "the_chart.png", "-t", "CSV"};
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);

assertEquals(gcViewerArgsParser.getArgumentCount(), 3);
assertEquals(gcViewerArgsParser.getGcResource(), new GcResourceFile("some_gc.log"));
assertEquals(gcViewerArgsParser.getSummaryFilePath(), "export_to.csv");
assertEquals(gcViewerArgsParser.getChartFilePath(), "the_chart.png");
assertEquals(gcViewerArgsParser.getType(), DataWriterType.CSV);
assertEquals(3, gcViewerArgsParser.getArgumentCount());
assertEquals(new GcResourceFile("some_gc.log"), gcViewerArgsParser.getGcResource());
assertEquals("export_to.csv", gcViewerArgsParser.getSummaryFilePath());
assertEquals("the_chart.png", gcViewerArgsParser.getChartFilePath());
assertEquals(DataWriterType.CSV, gcViewerArgsParser.getType());
}

@Test
public void illegalType() {
void illegalType() {
String[] args = {"some_gc.log", "export_to.csv", "the_chart.png", "-t", "ILLEGAL"};
try {
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
gcViewerArgsParser.parseArguments(args);
fail("GCVIewerArgsParserException expected");
}
catch (GCViewerArgsParserException e) {
assertThat("exception message", e.getMessage(), startsWith("Illegal type 'ILLEGAL'"));
}
GCViewerArgsParser gcViewerArgsParser = new GCViewerArgsParser();
GCViewerArgsParserException e = assertThrows(GCViewerArgsParserException.class, () -> gcViewerArgsParser.parseArguments(args));
assertThat("exception message", e.getMessage(), startsWith("Illegal type 'ILLEGAL'"));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tagtraum.perf.gcviewer;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,33 @@
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

/**
* @author martin.geldmacher
*/
@RunWith(MockitoJUnitRunner.class)
public class GCModelLoaderFactoryTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
class GCModelLoaderFactoryTest {

@Test
public void createFor_GcResourceFile() throws Exception {
void createFor_GcResourceFile() {
GCResource gcResource = mock(GcResourceFile.class);
assertThat(GCModelLoaderFactory.createFor(gcResource), instanceOf(GCModelLoaderImpl.class));
}

@Test
public void createFor_GcResourceSeries() throws Exception {
void createFor_GcResourceSeries() {
GCResource gcResource = mock(GcResourceSeries.class);
assertThat(GCModelLoaderFactory.createFor(gcResource), instanceOf(GCModelSeriesLoaderImpl.class));
}

@Test
public void createFor_GcResourceUnknown() throws Exception {
expectedException.expect(IllegalArgumentException.class);
void createFor_GcResourceUnknown() {
GCResource gcResource = mock(GCResource.class);
GCModelLoaderFactory.createFor(gcResource);
assertThrows(IllegalArgumentException.class, () -> GCModelLoaderFactory.createFor(gcResource));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.tagtraum.perf.gcviewer.ctrl.impl;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;

Expand All @@ -11,16 +12,12 @@
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

public class GCModelSeriesLoaderImplTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void getGcResource() throws Exception {
void getGcResource() throws Exception {
ArrayList<GCResource> gcResourceList = new ArrayList<>();
gcResourceList.add(new GcResourceFile(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_8_0Series-Part1.txt").getPath()));
gcResourceList.add(new GcResourceFile(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_8_0Series-Part2.txt").getPath()));
Expand All @@ -31,13 +28,12 @@ public void getGcResource() throws Exception {
}

@Test
public void GCModelSeriesLoaderImpl_ForEmptySeries() throws Exception {
expectedException.expect(IllegalArgumentException.class);
new GCModelSeriesLoaderImpl(new GcResourceSeries(new ArrayList<>()));
void GCModelSeriesLoaderImpl_ForEmptySeries() {
assertThrows(IllegalArgumentException.class, () -> new GCModelSeriesLoaderImpl(new GcResourceSeries(new ArrayList<>())));
}

@Test
public void loadGcModel() throws Exception {
void loadGcModel() throws Exception {
ArrayList<GCResource> gcResourceList = new ArrayList<>();
gcResourceList.add(new GcResourceFile(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_8_0Series-Part1.txt").getPath()));
gcResourceList.add(new GcResourceFile(UnittestHelper.getResource(FOLDER.OPENJDK, "SampleSun1_8_0Series-Part2.txt").getPath()));
Expand Down
Loading