Buggy code:
@ RunWith ( MockitoJUnitRunner . class ) public class MongoResmiDaoTest { private static final String DOMAIN = "DOMAIN" ; private static final String TEST_COLLECTION = "testCollection" ; private static final String DOMAIN_CONCATENATION = "@" ; private static final String TEST_COLLECTION_NAME_IN_DB = ( ( MongoResmiDaoTest . DOMAIN ) + ( MongoResmiDaoTest . DOMAIN_CONCATENATION ) ) + ( MongoResmiDaoTest . TEST_COLLECTION ) ; private static final String TEST_ID = "testId" ; private static final ResourceId TEST_RESOURCE_ID = new ResourceId ( "testId" ) ; private static final String TEST_REL = "testRel" ; private static final String RELATION_COLLECTION_NAME = ( ( ( ( MongoResmiDaoTest . DOMAIN ) + ( MongoResmiDaoTest . DOMAIN_CONCATENATION ) ) + ( MongoResmiDaoTest . TEST_COLLECTION ) ) + "." ) + ( MongoResmiDaoTest . TEST_REL ) ; private static final String TEST_ID_RELATION_OBJECT = "relatedId" ; private static final int TEST_ORDER = 1 ; private static final Query TEST_QUERY = new Query ( ) ; @ Mock private MongoOperations mongoOperations ; private final JsonObjectMongoWriteConverter jsonObjectMongoWriteConverter = new JsonObjectMongoWriteConverter ( ) ; @ Mock DefaultNamespaceNormalizer defaultNameNormalizer ; @ Mock ResmiOrder resmiOrderMock ; private MongoResmiDao mongoResmiDao ; @ Before public void setup ( ) { } @ Test public void testFindById ( ) { } @ Test public void testFindRelation ( ) { } @ Test public void testFindRelationWithWildcard ( ) { JsonObject json = new JsonObject ( ) ; json . add ( "a" , new JsonPrimitive ( "1" ) ) ; json . add ( "_id" , new JsonPrimitive ( "456" ) ) ; json . add ( "_dst_id" , new JsonPrimitive ( MongoResmiDaoTest . TEST_ID_RELATION_OBJECT ) ) ; json . add ( "_src_id" , new JsonPrimitive ( MongoResmiDaoTest . TEST_ID ) ) ; List < JsonObject > jsonObjectList = Collections . singletonList ( json ) ; Pagination pagination = new Pagination ( 0 , 10 ) ; String collectionName = MongoResmiDaoTest . RELATION_COLLECTION_NAME ; ArgumentCaptor < Query > queryCaptor = ArgumentCaptor . forClass ( Query . class ) ; when ( mongoOperations . find ( queryCaptor . capture ( ) , Mockito . eq ( JsonObject . class ) , Mockito . eq ( collectionName ) ) ) . thenReturn ( jsonObjectList ) ; <START_BUG> ResourceUri resourceUri = new ResourceUri ( MongoResmiDaoTest . TEST_COLLECTION , "_" , MongoResmiDaoTest . TEST_REL ) ; <END_BUG> JsonElement result = mongoResmiDao . findRelation ( resourceUri , Optional . empty ( ) , Optional . of ( pagination ) , Optional . empty ( ) ) ; assertThat ( result . isJsonArray ( ) ) . isTrue ( ) ; assertThat ( result . getAsJsonArray ( ) . size ( ) ) . isSameAs ( jsonObjectList . size ( ) ) ; assertThat ( queryCaptor . getValue ( ) . fields ( ) . getFieldsObject ( ) . get ( "_id" ) ) . isEqualTo ( 0 ) ; for ( JsonElement element : result . getAsJsonArray ( ) ) { assertThat ( element . getAsJsonObject ( ) . get ( "id" ) ) . isEqualTo ( new JsonPrimitive ( MongoResmiDaoTest . TEST_ID_RELATION_OBJECT ) ) ; assertThat ( element . getAsJsonObject ( ) . has ( "_dst_id" ) ) . isFalse ( ) ; assertThat ( element . getAsJsonObject ( ) . get ( "_src_id" ) ) . isEqualTo ( new JsonPrimitive ( MongoResmiDaoTest . TEST_ID ) ) ; } } @ Test public void testRelationWithData ( ) throws NotFoundException { } @ Test public void testUpsert ( ) { } private Answer < JsonObject > answerWithId ( JsonObject json ) { } @ Test public void testDelete ( ) { } @ Test public void ensureCollectionIndexTest ( ) { } @ Test public void ensureRelationIndexTest ( ) { } @ Test public void averageTest ( ) { } @ Test public void averageRelationTest ( ) { } @ Test public void sumTest ( ) { } @ Test public void sumRelationTest ( ) { } @ Test public void maxTest ( ) { } @ Test public void maxOnEmptyCollectionTest ( ) { } @ Test public void maxOnNonExistentFieldTest ( ) { } @ Test public void maxRelationTest ( ) { } @ Test public void minTest ( ) { } @ Test public void minRelationTest ( ) { } @ Test public void histogramTest ( ) throws IOException { } @ Test public void histogramTopNTest ( ) throws IOException { } }

Fix:
ResourceUri resourceUri = new ResourceUri ( MongoResmiDaoTest . DOMAIN , MongoResmiDaoTest . TEST_COLLECTION , "_" , MongoResmiDaoTest . TEST_REL ) ;