Skip to content

Commit

Permalink
Simplify assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Dec 17, 2024
1 parent 5883dcc commit 826630c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
9 changes: 5 additions & 4 deletions src/test/java/hudson/plugins/ec2/SlaveTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -504,8 +505,8 @@ public void testMinimumNumberOfInstancesActiveRangeConfig() throws Exception {
Assert.assertNotNull(stored);
Assert.assertEquals("11:00", stored.getMinimumNoInstancesActiveTimeRangeFrom());
Assert.assertEquals("15:00", stored.getMinimumNoInstancesActiveTimeRangeTo());
Assert.assertEquals(false, stored.getDay("monday"));
Assert.assertEquals(true, stored.getDay("tuesday"));
Assert.assertFalse(stored.getDay("monday"));
Assert.assertTrue(stored.getDay("tuesday"));
}

@Test
Expand Down Expand Up @@ -698,7 +699,7 @@ public void provisionOndemandSetsAwsNetworkingOnNetworkInterface() throws Except

assertEquals(actualNet.getSubnetId(), Util.fixEmpty(template.getSubnetId()));
assertEquals(actualNet.getGroups(), Stream.of("some-group-id").collect(Collectors.toList()));
assertEquals(actualRequest.getSubnetId(), null);
assertNull(actualRequest.getSubnetId());
assertEquals(actualRequest.getSecurityGroupIds(), Collections.emptyList());
assertEquals(actualRequest.getSecurityGroups(), Collections.emptyList());
}
Expand Down Expand Up @@ -1090,7 +1091,7 @@ public void provisionOnDemandWithUnsupportedInstanceMetadata() throws Exception

RunInstancesRequest actualRequest = riRequestCaptor.getValue();
InstanceMetadataOptionsRequest metadataOptionsRequest = actualRequest.getMetadataOptions();
assertEquals(metadataOptionsRequest, null);
assertNull(metadataOptionsRequest);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public void testAssociatePublicIpSetting() {
null,
true,
"");
assertEquals(true, st.getAssociatePublicIp());
assertTrue(st.getAssociatePublicIp());
}

@Test
Expand Down
35 changes: 18 additions & 17 deletions src/test/java/hudson/plugins/ec2/TemplateLabelsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
package hudson.plugins.ec2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.amazonaws.services.ec2.model.InstanceType;
import hudson.model.Label;
Expand Down Expand Up @@ -95,45 +96,45 @@ private void setUpCloud(String label, Node.Mode mode) throws Exception {
public void testLabelAtom() throws Exception {
setUpCloud(LABEL1 + " " + LABEL2);

assertEquals(true, ac.canProvision(new LabelAtom(LABEL1)));
assertEquals(true, ac.canProvision(new LabelAtom(LABEL2)));
assertEquals(false, ac.canProvision(new LabelAtom("aaa")));
assertEquals(true, ac.canProvision((Label) null));
assertTrue(ac.canProvision(new LabelAtom(LABEL1)));
assertTrue(ac.canProvision(new LabelAtom(LABEL2)));
assertFalse(ac.canProvision(new LabelAtom("aaa")));
assertTrue(ac.canProvision((Label) null));
}

@Test
public void testLabelExpression() throws Exception {
setUpCloud(LABEL1 + " " + LABEL2);

assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " && " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression(LABEL1 + " && aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
assertTrue(ac.canProvision(Label.parseExpression(LABEL1 + " || " + LABEL2)));
assertTrue(ac.canProvision(Label.parseExpression(LABEL1 + " && " + LABEL2)));
assertTrue(ac.canProvision(Label.parseExpression(LABEL1 + " || aaa")));
assertFalse(ac.canProvision(Label.parseExpression(LABEL1 + " && aaa")));
assertFalse(ac.canProvision(Label.parseExpression("aaa || bbb")));
assertFalse(ac.canProvision(Label.parseExpression("aaa || bbb")));
}

@Test
public void testEmptyLabel() throws Exception {
setUpCloud("");

assertEquals(true, ac.canProvision((Label) null));
assertTrue(ac.canProvision((Label) null));
}

@Test
public void testExclusiveMode() throws Exception {
setUpCloud(LABEL1 + " " + LABEL2, Node.Mode.EXCLUSIVE);

assertEquals(true, ac.canProvision(new LabelAtom(LABEL1)));
assertEquals(true, ac.canProvision(new LabelAtom(LABEL2)));
assertEquals(false, ac.canProvision(new LabelAtom("aaa")));
assertEquals(false, ac.canProvision((Label) null));
assertTrue(ac.canProvision(new LabelAtom(LABEL1)));
assertTrue(ac.canProvision(new LabelAtom(LABEL2)));
assertFalse(ac.canProvision(new LabelAtom("aaa")));
assertFalse(ac.canProvision((Label) null));
}

@Test
public void testExclusiveModeEmptyLabel() throws Exception {
setUpCloud("", Node.Mode.EXCLUSIVE);

assertEquals(false, ac.canProvision((Label) null));
assertFalse(ac.canProvision((Label) null));
}
}

0 comments on commit 826630c

Please sign in to comment.