Skip to content
Permalink
Browse files

[JENKINS-30551] Make ResultAction serializable.

  • Loading branch information
uhafner committed May 19, 2018
1 parent abd38ca commit 17c4d9f1e018b25814da27b75994dcb8c31fe2b8
@@ -1,5 +1,6 @@
package io.jenkins.plugins.analysis.core.views;

import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Collections;
@@ -32,14 +33,16 @@
*
* @author Ulli Hafner
*/
public class ResultAction implements HealthReportingAction, LastBuildAction, RunAction2, StaplerProxy {
public class ResultAction implements HealthReportingAction, LastBuildAction, RunAction2, StaplerProxy, Serializable {
private static final long serialVersionUID = 6683647181785654908L;

private transient Run<?, ?> owner;

private final AnalysisResult result;
private final HealthDescriptor healthDescriptor;
private final String id;
private final String name;
private final Charset charset;
private final String charset;

/**
* Creates a new instance of {@link ResultAction}.
@@ -64,7 +67,7 @@ public ResultAction(final Run<?, ?> owner, final AnalysisResult result, final He
this.healthDescriptor = healthDescriptor;
this.id = id;
this.name = name;
this.charset = charset;
this.charset = charset.name();
}

/**
@@ -128,6 +131,25 @@ public String getIconFileName() {
return null;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ResultAction that = (ResultAction) o;

return id.equals(that.id);
}

@Override
public int hashCode() {
return id.hashCode();
}

/**
* Returns whether a large image is defined.
*
@@ -200,6 +222,6 @@ private StaticAnalysisLabelProvider getLabelProvider() {
*/
@Override
public Object getTarget() {
return new IssuesDetail(owner, result, getLabelProvider(), charset);
return new IssuesDetail(owner, result, getLabelProvider(), Charset.forName(charset));
}
}
@@ -0,0 +1,39 @@
package io.jenkins.plugins.analysis.core.views;

import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.Priority;
import edu.hm.hafner.util.SerializableTest;
import io.jenkins.plugins.analysis.core.model.AnalysisResult;
import io.jenkins.plugins.analysis.core.quality.HealthDescriptor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import hudson.model.Run;

/**
* Tests the class {@link ResultAction}.
*
* @author Ullrich Hafner
*/
class ResultActionTest extends SerializableTest<ResultAction> {
@Test
void shouldRestoreRun() {
ResultAction action = createSerializable();

assertThat(action.getOwner()).isNull();

Run run = mock(Run.class);
action.onAttached(run);
assertThat(action.getOwner()).isSameAs(run);
}

@Override
protected ResultAction createSerializable() {
return new ResultAction(null, mock(AnalysisResult.class),
new HealthDescriptor(0, 0, Priority.HIGH),
"ID", "Name", StandardCharsets.UTF_8);
}
}

0 comments on commit 17c4d9f

Please sign in to comment.
You can’t perform that action at this time.