### Question:
ComparatorUsingFolderName implements Comparator<Folder>, Serializable { @Override public int compare(Folder f1, Folder f2) { int stringCompareTo = f1.getName().compareTo(f2.getName()); if (stringCompareTo == 0) { return f2.getUid().compareTo(f1.getUid()); } else { if (f1.getName().equals(defaultFolderName)) { return -1; } if (f2.getName().equals(defaultFolderName)) { return 1; } if (stringCompareTo > 0) { return 1; } return -1; } } ComparatorUsingFolderName(String defaultFolderName); @Override int compare(Folder f1, Folder f2);  }### Answer:
@Test public void foldersAZ() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("z").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(-1); }
@Test public void foldersAZHigherUid() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(5).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("z").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(-1); }
@Test public void foldersAZWhenSameUids() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("z").uid(1).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(-1); }
@Test public void foldersZA() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("z").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(1); }
@Test public void foldersZAHigherUid() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("z").uid(5).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(1); }
@Test public void foldersZAWhenSameUids() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("z").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(1); }
@Test public void foldersAA() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(1); }
@Test public void foldersAAHigherUid() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(5).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(2).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(-1); }
@Test public void foldersAAWhenSameUids() { int result = new ComparatorUsingFolderName("defaultName").compare( Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build(), Folder.builder().name("a").uid(1).ownerLoginAtDomain("login@domain").build()); assertThat(result).isEqualTo(0); }