Clean up JUnit assertions (#5314)

This commit is contained in:
Basil Crow authored and GitHub committed 2021-03-02 08:17:27 +00:00
1 parent e4bbb27b9e
commit 9cf3f73abd
35 files changed
+82 -70

No files matched your search

+2 -1
View File
@@ -36,6 +36,7 @@ import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.FileUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -63,7 +64,7 @@ public class LauncherTest {
Thread.sleep(100);
long start = System.currentTimeMillis();
p.kill();
assertTrue(p.join()!=0);
assertNotEquals(0, p.join());
long end = System.currentTimeMillis();
long terminationTime = end - start;
assertTrue("Join did not finish promptly. The completion time (" + terminationTime + "ms) is longer than expected 15s", terminationTime < 15000);
+1 -1
View File
@@ -148,7 +148,7 @@ public class UtilTest {
public void testEncodeSpaces() {
final String urlWithSpaces = "http://hudson/job/Hudson Job";
String encoded = Util.encode(urlWithSpaces);
assertEquals(encoded, "http://hudson/job/Hudson%20Job");
assertEquals("http://hudson/job/Hudson%20Job", encoded);
}
/**
@@ -121,7 +121,7 @@ public class AbstractItemTest {
} catch (IOException e) {
//THEN
assertEquals(e.getMessage(),"Trying to rename an item that does not support this operation.");
assertEquals("Trying to rename an item that does not support this operation.", e.getMessage());
assertEquals("NameNotEditableItem",item.getName());
}
}
@@ -140,7 +140,7 @@ public class AbstractItemTest {
} catch (Failure f) {
//THEN
assertEquals(f.getMessage(),"Trying to rename an item that does not support this operation.");
assertEquals("Trying to rename an item that does not support this operation.", f.getMessage());
assertEquals("NameNotEditableItem",item.getName());
}
}
+10 -9
View File
@@ -37,6 +37,7 @@ import java.util.concurrent.Executors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -115,24 +116,24 @@ public class RunTest {
@Test
public void artifactListDisambiguation1() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a/b/c.xml", "d/f/g.xml", "h/i/j.xml");
assertEquals(a.get(0).getDisplayPath(), "c.xml");
assertEquals(a.get(1).getDisplayPath(), "g.xml");
assertEquals(a.get(2).getDisplayPath(), "j.xml");
assertEquals("c.xml", a.get(0).getDisplayPath());
assertEquals("g.xml", a.get(1).getDisplayPath());
assertEquals("j.xml", a.get(2).getDisplayPath());
}
@Test
public void artifactListDisambiguation2() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a/b/c.xml", "d/f/g.xml", "h/i/g.xml");
assertEquals(a.get(0).getDisplayPath(), "c.xml");
assertEquals(a.get(1).getDisplayPath(), "f/g.xml");
assertEquals(a.get(2).getDisplayPath(), "i/g.xml");
assertEquals("c.xml", a.get(0).getDisplayPath());
assertEquals("f/g.xml", a.get(1).getDisplayPath());
assertEquals("i/g.xml", a.get(2).getDisplayPath());
}
@Test
public void artifactListDisambiguation3() throws Exception {
List<? extends Run<?, ?>.Artifact> a = createArtifactList("a.xml", "a/a.xml");
assertEquals(a.get(0).getDisplayPath(), "a.xml");
assertEquals(a.get(1).getDisplayPath(), "a/a.xml");
assertEquals("a.xml", a.get(0).getDisplayPath());
assertEquals("a/a.xml", a.get(1).getDisplayPath());
}
@Issue("JENKINS-26777")
@@ -267,7 +268,7 @@ public class RunTest {
treeSet.add(r1);
treeSet.add(r2);
assertTrue(r1.compareTo(r2) != 0);
assertNotEquals(0, r1.compareTo(r2));
assertEquals(2, treeSet.size());
}
@@ -50,7 +50,7 @@ public class SearchTest {
SuggestedItem x = Search.find(si, "abc def ghi");
assertNotNull(x);
assertEquals(x.getUrl(),"/abc-def-ghi");
assertEquals("/abc-def-ghi", x.getUrl());
List<SuggestedItem> l = Search.suggest(si, "abc def ghi");
assertEquals(2,l.size());
@@ -28,7 +28,7 @@ public class PackedMapTest {
PackedMap<String,String> p = PackedMap.of(o);
assertEquals("b",p.get("a"));
assertEquals("d", p.get("c"));
assertEquals(p.size(),2);
assertEquals(2, p.size());
for (Entry<String,String> e : p.entrySet()) {
System.out.println(e.getKey()+'='+e.getValue());
}
@@ -49,8 +49,8 @@ public class RobustReflectionConverterTest {
@Test
public void robustUnmarshalling() {
Point p = read(new XStream2());
assertEquals(p.x,1);
assertEquals(p.y,2);
assertEquals(1, p.x);
assertEquals(2, p.y);
}
private Point read(XStream xs) {
@@ -14,7 +14,7 @@ public class FieldUtilsTest {
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_InnerClass() throws Exception {
InnerClassWithPublicFinalField sut = new InnerClassWithPublicFinalField();
FieldUtils.setProtectedFieldValue("myField", sut, "test");
assertEquals(sut.getMyField(), "original");
assertEquals("original", sut.getMyField());
}
@Test
@@ -22,14 +22,14 @@ public class FieldUtilsTest {
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_OuterClass() throws Exception {
OuterClassWithPublicFinalField sut = new OuterClassWithPublicFinalField();
FieldUtils.setProtectedFieldValue("myField", sut, "test");
assertEquals(sut.getMyField(), "original");
assertEquals("original", sut.getMyField());
}
@Test
public void setProtectedFieldValue_Should_Succeed() throws Exception {
InnerClassWithProtectedField sut = new InnerClassWithProtectedField();
FieldUtils.setProtectedFieldValue("myProtectedField", sut, "test");
assertEquals(sut.getMyNonFinalField(), "test");
assertEquals("test", sut.getMyNonFinalField());
}
@Test