### Question:
UUIDSequence implements KeySequence { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof UUIDSequence)) { return false; } UUIDSequence that = (UUIDSequence) obj; return this.seqId == that.seqId; } UUIDSequence(KeySequenceConfig keySequenceConfig); @Override CharSequence nextReaderKey(); @Override CharSequence nextWriterKey(); @Override long readerKeysAvailable(); @Override KeySequenceConfig getConfig(boolean sharedInstance); @Override Iterator<CharSequence> nextReaderKeys(long maxKeys); @Override boolean equals(Object obj); @Override int hashCode(); static final int RESERVED_KEYS; }### Answer:
@Test public void equalsReturnsFalseIfNullProvided() { KeySequenceConfig config = createDefaultTestKeySequenceConfig(); KeySequence sequence = createDefaultTestUUIDSequence(config); boolean result = sequence.equals(null); assertFalse(result); }
@Test public void equalsReturnsFalseIfWrongTypeProvided() { KeySequenceConfig config = createDefaultTestKeySequenceConfig(); KeySequence sequence = createDefaultTestUUIDSequence(config); boolean result = sequence.equals(Object.class); assertFalse(result); }
@Test public void equalsReturnsFalseIfSequenceIdsAreDifferent() { KeySequenceConfig config1 = createDefaultTestKeySequenceConfig(); KeySequence sequence1 = createDefaultTestUUIDSequence(config1); KeySequenceConfig config2 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID + 1, RESERVED_KEYS, RESERVED_KEYS); KeySequence sequence2 = createDefaultTestUUIDSequence(config2); boolean result = sequence1.equals(sequence2); assertFalse(result); }
@Test public void equalsReturnsTrueIfSequenceIdsAreEqual() { KeySequenceConfig config1 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS, RESERVED_KEYS); KeySequence sequence1 = createDefaultTestUUIDSequence(config1); KeySequenceConfig config2 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS, RESERVED_KEYS); KeySequence sequence2 = createDefaultTestUUIDSequence(config2); boolean result = sequence1.equals(sequence2); assertTrue(result); }
@Test public void equalsReturnsTrueIfReaderIndicesAreDifferent() { KeySequenceConfig config1 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS, RESERVED_KEYS); KeySequence sequence1 = createDefaultTestUUIDSequence(config1); KeySequenceConfig config2 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS + 1, RESERVED_KEYS); KeySequence sequence2 = createDefaultTestUUIDSequence(config2); boolean result = sequence1.equals(sequence2); assertTrue(result); }
@Test public void equalsReturnsTrueIfWriterIndicesAreDifferent() { KeySequenceConfig config1 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS, RESERVED_KEYS); KeySequence sequence1 = createDefaultTestUUIDSequence(config1); KeySequenceConfig config2 = new KeySequenceConfig(DEFAULT_TEST_SEQ_ID, RESERVED_KEYS, RESERVED_KEYS + 1); KeySequence sequence2 = createDefaultTestUUIDSequence(config2); boolean result = sequence1.equals(sequence2); assertTrue(result); }