package ru.dreamteam.couch.util;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import ru.dreamteam.couch.CouchEntity;
public class HasIdComparatorTest {
private HasIdComparator comparator;
private CouchEntity couchEntity1;
@Before
public void setUp() {
comparator = HasIdComparator.INSTANCE;
couchEntity1 = new CouchEntity();
couchEntity1.setId("1");
}
@Test
public void testBothNull() throws Exception {
Assert.assertEquals(0, comparator.compare(null, null));
}
@Test
public void testSameObjects() throws Exception {
Assert.assertEquals(0, comparator.compare(couchEntity1, couchEntity1));
}
@Test
public void testDiff() throws Exception {
CouchEntity couchEntity2 = new CouchEntity();
couchEntity2.setId("2");
Assert.assertTrue(comparator.compare(couchEntity1, couchEntity2) < 0);
Assert.assertTrue(comparator.compare(couchEntity2, couchEntity1) > 0);
}
@Test
public void testOneIdNull() throws Exception {
CouchEntity couchEntity2 = new CouchEntity();
Assert.assertTrue(comparator.compare(couchEntity1, couchEntity2) > 0);
Assert.assertTrue(comparator.compare(couchEntity2, couchEntity1) < 0);
}
@Test
public void testOneNull() throws Exception {
Assert.assertTrue(comparator.compare(couchEntity1, null) > 0);
Assert.assertTrue(comparator.compare(null, couchEntity1) < 0);
}
}