From 676736c7506002bc136bfd78724052e2d457a448 Mon Sep 17 00:00:00 2001 From: Dranuhl Date: Mon, 29 Nov 2021 11:50:22 +0100 Subject: [PATCH] Add PackageEntry unit tests. --- .../rpm/builder/PackageEntryTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/de/dentrassi/rpm/builder/PackageEntryTest.java diff --git a/src/test/java/de/dentrassi/rpm/builder/PackageEntryTest.java b/src/test/java/de/dentrassi/rpm/builder/PackageEntryTest.java new file mode 100644 index 0000000..fe411c6 --- /dev/null +++ b/src/test/java/de/dentrassi/rpm/builder/PackageEntryTest.java @@ -0,0 +1,81 @@ +package de.dentrassi.rpm.builder; + +import static org.junit.Assert.*; + +import java.io.File; + +import org.junit.Test; + +public class PackageEntryTest +{ + public PackageEntryTest () + { + super(); + } + + @Test + public void testValidateNameNull () + { + final PackageEntry entry = new PackageEntry (); + entry.setLinkTo ( "something-to-link-to" ); + + assertThrows ( IllegalStateException.class, () -> entry.validate () ); + } + + @Test + public void testValidateNameEmpty () + { + final PackageEntry entry = new PackageEntry (); + entry.setName (""); + entry.setLinkTo ( "something-to-link-to" ); + + assertThrows ( IllegalStateException.class, () -> entry.validate () ); + } + + @Test + public void testValidateNoSource () + { + final PackageEntry entry = new PackageEntry (); + entry.setName ("some-entry"); + + assertThrows ( IllegalStateException.class, () -> entry.validate () ); + } + + @Test + public void testValidateGhostNull () + { + final PackageEntry entry = new PackageEntry (); + entry.setName ("some-entry"); + entry.setGhost ( null ); + + // no NullPointerException must be thrown + assertThrows ( IllegalStateException.class, () -> entry.validate () ); + } + + @Test + public void testValidateGhostSource() + { + final PackageEntry entry = new PackageEntry (); + entry.setName ("some-entry"); + entry.setGhost ( Boolean.TRUE ); + + try { + entry.validate (); + } + catch ( final RuntimeException e) + { + fail ( "Ghost entries do not require other sources, got error: " + e.getMessage () ); + } + } + + @Test + public void testValidateMultipleSourcesGhost() + { + final PackageEntry entry = new PackageEntry (); + entry.setName ("some-entry"); + entry.setFile ( new File ( "some-file-entry" ) ); + entry.setGhost ( Boolean.TRUE ); + + assertThrows ( IllegalStateException.class, () -> entry.validate () ); + } +}