Skip to content
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
10 changes: 3 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<licenses>
<license>
<name>The Apache V2 License</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand Down Expand Up @@ -65,6 +65,7 @@
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.504</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>

<dependencyManagement>
Expand All @@ -89,14 +90,9 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,52 @@
*/
package com.google.jenkins.plugins.metadata;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.MatcherAssert.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;

import hudson.model.Run;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

/**
* Unit test for {@link MetadataContainer}.
*/
@RunWith(MockitoJUnitRunner.class)
public class MetadataContainerTest {
@Mock private Run<?, ?> build;
@ExtendWith(MockitoExtension.class)
class MetadataContainerTest {

@Mock
private Run<?, ?> build;
private MetadataContainer underTest;

@Before
public void setup() {
@BeforeEach
void setup() {
underTest = new MetadataContainer();
}

@Test
public void ofNotPresent() {
void ofNotPresent() {
assertNotSame(underTest, MetadataContainer.of(build));
}

@Test
public void ofPresent() {
void ofPresent() {
when(build.getAction(MetadataContainer.class)).thenReturn(underTest);
assertSame(underTest, MetadataContainer.of(build));
}

@Test
public void getMetadata() {
void getMetadata() {
TestMetadata data = new TestMetadata("data");
underTest.add(data);

Expand All @@ -68,14 +70,14 @@ public void getMetadata() {
}

@Test
public void add() {
void add() {
TestMetadata data = new TestMetadata("data");
underTest.add(data);
assertThat(underTest.getMetadata().get(data.getKey()), contains(data));
}

@Test
public void addAll() {
void addAll() {
TestMetadata data1 = new TestMetadata("key1");
TestMetadata data2 = new TestMetadata("key2");
TestMetadata data3 = new TestMetadata("key2"); // intentionally the same
Expand All @@ -89,7 +91,7 @@ public void addAll() {
}

@Test
public void removeAll() {
void removeAll() {
TestMetadata data1 = new TestMetadata("key");
TestMetadata data2 = new TestMetadata("key");

Expand All @@ -102,22 +104,24 @@ public void removeAll() {
}

@Test
public void getSerializedMetadata() {
void getSerializedMetadata() {
TestMetadata data = new TestMetadata("data");
underTest.add(data);
assertEquals(
underTest.listSerialize(ImmutableList.of(data)),
underTest.getSerializedMetadata().get(data.getKey()));
}

@Test(expected = MetadataSerializationException.class)
public void serialize_exception() {
underTest.serialize(new NotSerializable());
@Test
void serialize_exception() {
assertThrows(MetadataSerializationException.class, () ->
underTest.serialize(new NotSerializable()));
}

@Test(expected = MetadataSerializationException.class)
public void deserialize_exception() {
underTest.deserialize(NotSerializable.class, "bad");
@Test
void deserialize_exception() {
assertThrows(MetadataSerializationException.class, () ->
underTest.deserialize(NotSerializable.class, "bad"));
}

/**
Expand All @@ -134,6 +138,7 @@ public String getKey() {
}
private final String key;
}

/**
* A class that can't be serialized nor deserialized, for testing of exception
* handling.
Expand Down
Loading