Skip to content
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

Migrate tests to JUnit5 #1580

Merged
merged 1 commit into from
Feb 17, 2025
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
Expand Up @@ -14,28 +14,30 @@
import java.util.HashSet;
import java.util.Set;
import jenkins.model.GlobalConfiguration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class ConfigurationTest {
@Rule
public final JenkinsRule r = new JenkinsRule();
@WithJenkins
class ConfigurationTest {

private JenkinsRule r;

private Computer computer;
private NodeLabelCache nodeLabelCache;
private PlatformDetails platformDetails;

@Before
public void setUp() throws IOException, InterruptedException {
@BeforeEach
void setUp(JenkinsRule r) throws IOException, InterruptedException {
this.r = r;
computer = r.jenkins.toComputer();
nodeLabelCache = ComputerListener.all().get(NodeLabelCache.class);
platformDetails = nodeLabelCache.requestComputerPlatformDetails(computer, computer.getChannel());
}

@Test
public void configuredNameOnlyLabel() {
void configuredNameOnlyLabel() {
PlatformLabelerNodeProperty nodeProperty = new PlatformLabelerNodeProperty();
LabelConfig labelConfig = new LabelConfig();
labelConfig.setArchitecture(false);
Expand All @@ -59,7 +61,7 @@ public void configuredNameOnlyLabel() {
}

@Test
public void configuredTwoLabels() {
void configuredTwoLabels() {
PlatformLabelerNodeProperty nodeProperty = new PlatformLabelerNodeProperty();
LabelConfig labelConfig = new LabelConfig();
labelConfig.setArchitectureName(false);
Expand All @@ -83,7 +85,7 @@ public void configuredTwoLabels() {
}

@Test
public void configuredAllLabelsOnEphemeralNode() throws Exception {
void configuredAllLabelsOnEphemeralNode() throws Exception {

// Create and connect the agent
DumbSlave agent = r.createSlave(Label.get("agent"));
Expand Down Expand Up @@ -125,7 +127,7 @@ public void configuredAllLabelsOnEphemeralNode() throws Exception {
}

@Test
public void configuredAllLabelsOnNode() {
void configuredAllLabelsOnNode() {
PlatformLabelerNodeProperty nodeProperty = new PlatformLabelerNodeProperty();
LabelConfig labelConfig = new LabelConfig();
nodeProperty.setLabelConfig(labelConfig);
Expand Down Expand Up @@ -155,7 +157,7 @@ public void configuredAllLabelsOnNode() {
}

@Test
public void nodeConfigOverridesGlobalConfig() {
void nodeConfigOverridesGlobalConfig() {

PlatformLabelerGlobalConfiguration globalConfig =
GlobalConfiguration.all().getInstance(PlatformLabelerGlobalConfiguration.class);
Expand Down Expand Up @@ -190,7 +192,7 @@ public void nodeConfigOverridesGlobalConfig() {
}

@Test
public void globalConfigOnlyArchitecture() {
void globalConfigOnlyArchitecture() {

PlatformLabelerGlobalConfiguration globalConfig =
GlobalConfiguration.all().getInstance(PlatformLabelerGlobalConfiguration.class);
Expand Down Expand Up @@ -218,7 +220,7 @@ public void globalConfigOnlyArchitecture() {
}

@Test
public void configRoundTripTest() throws Exception {
void configRoundTripTest() throws Exception {
PlatformLabelerGlobalConfiguration globalConfig =
GlobalConfiguration.all().getInstance(PlatformLabelerGlobalConfiguration.class);
LabelConfig globalLabelConfigBefore = globalConfig.getLabelConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static org.hamcrest.Matchers.is;

import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class LabelConfigTest {
class LabelConfigTest {

private final Random random = new Random();

Expand All @@ -23,10 +23,8 @@ public class LabelConfigTest {
private boolean randomIsWindowsFeatureUpdate;
private boolean randomIsOsName;

public LabelConfigTest() {}

@Before
public void setUp() {
@BeforeEach
void setUp() {
LabelConfig randomSrcLabelConfig = new LabelConfig();

randomIsArchitecture = random.nextBoolean();
Expand All @@ -52,7 +50,7 @@ public void setUp() {
}

@Test
public void testConstructorNullArg() {
void testConstructorNullArg() {
LabelConfig nullLabelConfig = new LabelConfig(null);
assertThat(nullLabelConfig.isArchitecture(), is(defaultConfig.isArchitecture()));
assertThat(nullLabelConfig.isName(), is(defaultConfig.isName()));
Expand All @@ -63,97 +61,97 @@ public void testConstructorNullArg() {
}

@Test
public void testIsArchitecture() {
void testIsArchitecture() {
assertThat(defaultConfig.isArchitecture(), is(true));
assertThat(randomConfig.isArchitecture(), is(randomIsArchitecture));
}

@Test
public void testSetArchitecture() {
void testSetArchitecture() {
defaultConfig.setArchitecture(!randomIsArchitecture);
assertThat(defaultConfig.isArchitecture(), is(!randomIsArchitecture));
}

@Test
public void testIsName() {
void testIsName() {
assertThat(defaultConfig.isName(), is(true));
assertThat(randomConfig.isName(), is(randomIsName));
}

@Test
public void testSetName() {
void testSetName() {
defaultConfig.setName(!randomIsName);
assertThat(defaultConfig.isName(), is(!randomIsName));
}

@Test
public void testIsVersion() {
void testIsVersion() {
assertThat(defaultConfig.isVersion(), is(true));
assertThat(randomConfig.isVersion(), is(randomIsVersion));
}

@Test
public void testSetVersion() {
void testSetVersion() {
defaultConfig.setVersion(!randomIsVersion);
assertThat(defaultConfig.isVersion(), is(!randomIsVersion));
}

@Test
public void testIsArchitectureName() {
void testIsArchitectureName() {
assertThat(defaultConfig.isArchitectureName(), is(true));
assertThat(randomConfig.isArchitectureName(), is(randomIsArchitectureName));
}

@Test
public void testSetArchitectureName() {
void testSetArchitectureName() {
defaultConfig.setArchitectureName(!randomIsArchitectureName);
assertThat(defaultConfig.isArchitectureName(), is(!randomIsArchitectureName));
}

@Test
public void testIsNameVersion() {
void testIsNameVersion() {
assertThat(defaultConfig.isNameVersion(), is(true));
assertThat(randomConfig.isNameVersion(), is(randomIsNameVersion));
}

@Test
public void testSetNameVersion() {
void testSetNameVersion() {
defaultConfig.setNameVersion(!randomIsNameVersion);
assertThat(defaultConfig.isNameVersion(), is(!randomIsNameVersion));
}

@Test
public void testIsArchitectureNameVersion() {
void testIsArchitectureNameVersion() {
assertThat(defaultConfig.isArchitectureNameVersion(), is(true));
assertThat(randomConfig.isArchitectureNameVersion(), is(randomIsArchitectureNameVersion));
}

@Test
public void testSetArchitectureNameVersion() {
void testSetArchitectureNameVersion() {
defaultConfig.setArchitectureNameVersion(!randomIsArchitectureNameVersion);
assertThat(defaultConfig.isArchitectureNameVersion(), is(!randomIsArchitectureNameVersion));
}

@Test
public void testIsWindowsFeatureUpdate() {
void testIsWindowsFeatureUpdate() {
assertThat(defaultConfig.isWindowsFeatureUpdate(), is(true));
assertThat(randomConfig.isWindowsFeatureUpdate(), is(randomIsWindowsFeatureUpdate));
}

@Test
public void testSetWindowsFeatureUpdate() {
void testSetWindowsFeatureUpdate() {
defaultConfig.setWindowsFeatureUpdate(!randomIsWindowsFeatureUpdate);
assertThat(defaultConfig.isWindowsFeatureUpdate(), is(!randomIsWindowsFeatureUpdate));
}

@Test
public void testIsOsName() {
void testIsOsName() {
assertThat(defaultConfig.isOsName(), is(true));
assertThat(randomConfig.isOsName(), is(randomIsOsName));
}

@Test
public void testSetOsName() {
void testSetOsName() {
defaultConfig.setOsName(!randomIsOsName);
assertThat(defaultConfig.isOsName(), is(!randomIsOsName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class LsbReleaseFakeFileTest {
class LsbReleaseFakeFileTest {
@TempDir
File dataDir;
private File dataDir;

private String fakeDistributorId = "megasupercorp";
private String fakeRelease = "1.2.3";
private final String fakeDistributorId = "megasupercorp";
private final String fakeRelease = "1.2.3";
private LsbRelease fakeLsbRelease;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import org.junit.jupiter.api.Test;

public class LsbReleaseFakeTest {
private String fakeDistributorId = "megasupercorp";
private String fakeRelease = "1.2.3";
private LsbRelease fakeLsbRelease = new LsbRelease(fakeDistributorId, fakeRelease);
class LsbReleaseFakeTest {
private final String fakeDistributorId = "megasupercorp";
private final String fakeRelease = "1.2.3";
private final LsbRelease fakeLsbRelease = new LsbRelease(fakeDistributorId, fakeRelease);

@Test
void matchingFakeDistributorId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class LsbReleaseRealTest {
class LsbReleaseRealTest {
private LsbRelease lsbRelease;

@BeforeEach
Expand Down
Loading