Skip to content

Commit

Permalink
[JENKINS-49649] - Fix tests and refactor the methods a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Feb 21, 2018
1 parent 31c35d5 commit e3de407
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
Expand Up @@ -218,7 +218,7 @@ public List<String> getFsObjectsList() throws IOException {



List<String> sortList(Map<String, Long> map) {
List<String> sortList(Map<String, Long> map) {
List<String> list;

if (map.isEmpty()) {
Expand All @@ -241,11 +241,11 @@ List<String> sortList(Map<String, Long> map) {

return list;
}




List<String> createTimeSortedList(Map<String, Long> map) {

static List<String> createTimeSortedList(Map<String, Long> map) {
List<String> list = new ArrayList<String>();

Collection<Long> valuesC = map.values();
Expand All @@ -271,7 +271,7 @@ List<String> createTimeSortedList(Map<String, Long> map) {



private boolean isSymlink(File file) throws IOException {
static private boolean isSymlink(File file) throws IOException {
if (file == null)
throw new NullPointerException("File must not be null");
File canon;
Expand Down
38 changes: 16 additions & 22 deletions src/test/java/alex/jenkins/plugins/ChangeSequenceTest.java
Expand Up @@ -8,28 +8,22 @@
import org.junit.Test;

public class ChangeSequenceTest {



public void setup(){
}

@Test
public void testSorting() {
boolean sortByLastModified = true;
boolean sortReverseOrder = false;
FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "path", "FILE", "", "", sortByLastModified, sortReverseOrder);

pd.map = new TreeMap<String, Long>();

TreeMap<String, Long> map = new TreeMap<>();
String test1 = "test1";
String test2 = "test2";
File f1 = new File(test1);
File f2 = new File(test2);

pd.map.put(f1.getName(), (long) 2);
pd.map.put(f2.getName(), (long) 1);
map.put(f1.getName(), (long) 2);
map.put(f2.getName(), (long) 1);

List<String> sortedList = pd.createTimeSortedList();
List<String> sortedList = FileSystemListParameterDefinition.createTimeSortedList(map);

Assert.assertEquals(test2,sortedList.get(0));
Assert.assertEquals(test1,sortedList.get(1));
Expand All @@ -42,17 +36,17 @@ public void testReverseOrder() {
boolean sortByLastModified = true;
boolean sortReverseOrder = true;
FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "path", "FILE", "", "", sortByLastModified, sortReverseOrder);
pd.map = new TreeMap<String, Long>();

TreeMap<String, Long> map = new TreeMap<>();
String test1 = "test1";
String test2 = "test2";
File f1 = new File(test1);
File f2 = new File(test2);

pd.map.put(f1.getName(), (long) 2);
pd.map.put(f2.getName(), (long) 1);
map.put(f1.getName(), (long) 2);
map.put(f2.getName(), (long) 1);

List<String> sortedList = pd.sortList();
List<String> sortedList = pd.sortList(map);

Assert.assertEquals(test1,sortedList.get(0));
Assert.assertEquals(test2,sortedList.get(1));
Expand All @@ -65,20 +59,20 @@ public void testAlphabeticOrder() {
boolean sortByLastModified = false;
boolean sortReverseOrder = false;
FileSystemListParameterDefinition pd = new FileSystemListParameterDefinition("name", "description", "path", "FILE", "", "", sortByLastModified, sortReverseOrder);
pd.map = new TreeMap<String, Long>();

TreeMap<String, Long> map = new TreeMap<>();
String test1 = "test1";
String test2 = "test2";
String test3 = "test3";
File f1 = new File(test1);
File f2 = new File(test2);
File f3 = new File(test3);

pd.map.put(f1.getName(), (long) 1);
pd.map.put(f3.getName(), (long) 3);
pd.map.put(f2.getName(), (long) 2);
map.put(f1.getName(), (long) 1);
map.put(f3.getName(), (long) 3);
map.put(f2.getName(), (long) 2);

List<String> sortedList = pd.sortList();
List<String> sortedList = pd.sortList(map);

Assert.assertEquals(test1,sortedList.get(0));
Assert.assertEquals(test2,sortedList.get(1));
Expand Down

0 comments on commit e3de407

Please sign in to comment.