package ru.matevosyan;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
 * Created by Admin on 07.05.2017.
 */
public class DepartmentTest {
    @Test
    public void whenPassDepartmentSerThanCheckSortedDepartment() {

        //assign
        TreeSet<String> depCode = new TreeSet<>();
        Department department = new Department(depCode);

        TreeSet<String> code = new TreeSet<>();
        DepartmentCode departmentCode = new DepartmentCode(code);

        List<String> codeExpected = new ArrayList<>();
        Iterator iterator = department.getName().iterator();
        int i = 0;

        //act
        code.add("K1");
        code.add("K2");

        depCode.add("K1\\SK1");
        depCode.add("K1\\SK2");
        depCode.add("K1\\SK1\\SSK1");
        depCode.add("K1\\SK1\\SSK2");
        depCode.add("K2\\SK1\\SSK1");
        depCode.add("K2\\SK1\\SSK2");
        depCode.add("K2");

        codeExpected.add("K1");
        codeExpected.add("K1\\SK1");
        codeExpected.add("K1\\SK1\\SSK1");
        codeExpected.add("K1\\SK1\\SSK2");
        codeExpected.add("K1\\SK2");
        codeExpected.add("K2");
        codeExpected.add("K2\\SK1\\SSK1");
        codeExpected.add("K2\\SK1\\SSK2");

        depCode.addAll(departmentCode.getCode());

        //assert
        while (iterator.hasNext()) {
            assertThat(iterator.next(), is(codeExpected.get(i++)));
        }
    }
}
@@ -512,24 +512,26 @@
 (depCode);%0A%0A
+//
         Tree
@@ -558,32 +558,34 @@
 ew TreeSet%3C%3E();%0A
+//
         Departme
@@ -785,16 +785,18 @@
   //act%0A
+//
         
@@ -803,32 +803,34 @@
 code.add(%22K1%22);%0A
+//
         code.add
@@ -1389,24 +1389,26 @@
 1%5C%5CSSK2%22);%0A%0A
+//
         depC
@@ -1583,10 +1583,1112 @@
  %7D%0A    %7D
+%0A%0A    @Test%0A    public void whenPassDepartmentSerThanCheckDescendingSortedDepartment() %7B%0A        //assign%0A        TreeSet%3CString%3E depCode = new TreeSet%3C%3E();%0A        Department department = new Department(depCode);%0A%0A        List%3CString%3E codeExpected = new ArrayList%3C%3E();%0A        Iterator iterator = department.getName().iterator();%0A        int i = 0;%0A%0A        //act%0A%0A        depCode.add(%22K1%5C%5CSK1%22);%0A        depCode.add(%22K1%5C%5CSK2%22);%0A        depCode.add(%22K1%5C%5CSK1%5C%5CSSK1%22);%0A        depCode.add(%22K1%5C%5CSK1%5C%5CSSK2%22);%0A        depCode.add(%22K2%5C%5CSK1%5C%5CSSK1%22);%0A        depCode.add(%22K2%5C%5CSK1%5C%5CSSK2%22);%0A        depCode.add(%22K2%22);%0A%0A%0A        codeExpected.add(%22K2%5C%5CSK1%5C%5CSSK2%22);%0A        codeExpected.add(%22K2%5C%5CSK1%5C%5CSSK1%22);%0A        codeExpected.add(%22K2%22);%0A        codeExpected.add(%22K1%5C%5CSK2%22);%0A        codeExpected.add(%22K1%5C%5CSK1%5C%5CSSK2%22);%0A        codeExpected.add(%22K1%5C%5CSK1%5C%5CSSK1%22);%0A        codeExpected.add(%22K1%5C%5CSK1%22);%0A        codeExpected.add(%22K1%22);%0A%0A%0A%0A        //assert%0A        while (iterator.hasNext()) %7B%0A            department.descendingSort();%0A            assertThat(iterator.next(), is(codeExpected.get(i++)));%0A        %7D%0A    %7D
 %0A%7D

change DepartmentTest.java