### Question:
MigrateService { public DBCredential guessCredentialProperties(DBCredential dbCredential) { Matcher threeFieldsMatcher = threeFieldsPattern.matcher(dbCredential.getName()); if (threeFieldsMatcher.matches()) { logger.info("Parsing " + dbCredential.getName()); String sdlc = threeFieldsMatcher.group(2); dbCredential.setSdlc(sdlc); } else{ try { String sdlc = dbCredential.getName().split("\\.")[1]; dbCredential.setSdlc(sdlc); } catch (Exception e) { logger.error("Error parsing key " + dbCredential.getName()); } } return dbCredential; }  DBCredential migrateCredential(DBCredential dbCredential, FideliusService fideliusService); DBCredential guessCredentialProperties(DBCredential dbCredential);  }### Answer:
@Test public void guessCredentialWith3Fields() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev.key"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("key", result.getShortKey()); }
@Test public void guessCredentialWith3FieldsAndSpecialCharacters() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev-int.<key#"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev-int", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("<key#", result.getShortKey()); }
@Test public void guessCredentialWith4Fields() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.component.dev.key"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("component", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("dev.key", result.getShortKey()); }
@Test public void guessCredentialWith4FieldsAndSpecialCharacters() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev-int.component.<key>"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev-int", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("component.<key>", result.getShortKey()); }
@Test public void guessCredentialWithMoreThan4Fields() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev.secret.long.key"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("secret.long.key", result.getShortKey()); }
@Test public void guessCredentialWithMoreThan4FieldsAndCharacters() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev-int.secret.long.<key*"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev-int", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("secret.long.<key*", result.getShortKey()); }
@Test public void guessCredentialWith3FieldsAndSpecialCharactersOnSDLC() throws Exception { DBCredential dbCredential = new DBCredential(); dbCredential.setName("APP.dev-int*.secret"); DBCredential result = migrateService.guessCredentialProperties(dbCredential); Assert.assertEquals("dev-int*", result.getSdlc()); Assert.assertEquals(null, result.getComponent()); Assert.assertEquals("APP.dev-int*.secret", result.getShortKey()); }