### Question:
CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 );  }### Answer:
@Test public void testNullCSNs() { assertEquals( 0, comparator.compare( null, null ) ); Csn csn2 = new Csn( System.currentTimeMillis(), 1, 1, 1 ); assertEquals( -1, comparator.compare( null, csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), null ) ); }
@Test public void testEqualsCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 0, 0 ); assertEquals( 0, comparator.compare( csn1.toString(), csn2.toString() ) ); }
@Test public void testDifferentTimeStampCSNs() { long t0 = System.currentTimeMillis(); long t1 = System.currentTimeMillis() + 1000; Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t1, 0, 0, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); }
@Test public void testDifferentChangeCountCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 1, 0, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); }
@Test public void testDifferentReplicaIdCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 1, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); }
@Test public void testDifferentOperationNumberCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 0, 1 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); }