@Test
public void update_characteristics_when_restoring_characteristics() throws Exception {
when(dao.selectEnabledCharacteristics(session)).thenReturn(newArrayList(
// Order and name have changed
new CharacteristicDto().setId(1).setKey("PORTABILITY").setName("Portability updated").setOrder(2).setCreatedAt(oldDate).setUpdatedAt(oldDate),
new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler updated").setParentId(1).setCreatedAt(oldDate).setUpdatedAt(oldDate)
));
debtModelBackup.restoreCharacteristics(
new DebtModel()
.addRootCharacteristic(new DefaultDebtCharacteristic().setKey("PORTABILITY").setName("Portability").setOrder(1))
.addSubCharacteristic(new DefaultDebtCharacteristic().setKey("COMPILER").setName("Compiler"), "PORTABILITY"),
now,
session
);
verify(dao, times(2)).update(characteristicCaptor.capture(), eq(session));
CharacteristicDto dto1 = characteristicCaptor.getAllValues().get(0);
assertThat(dto1.getId()).isEqualTo(1);
assertThat(dto1.getKey()).isEqualTo("PORTABILITY");
assertThat(dto1.getName()).isEqualTo("Portability");
assertThat(dto1.getParentId()).isNull();
assertThat(dto1.getOrder()).isEqualTo(1);
assertThat(dto1.getCreatedAt()).isEqualTo(oldDate);
assertThat(dto1.getUpdatedAt()).isEqualTo(now);
CharacteristicDto dto2 = characteristicCaptor.getAllValues().get(1);
assertThat(dto2.getId()).isEqualTo(2);
assertThat(dto2.getKey()).isEqualTo("COMPILER");
assertThat(dto2.getName()).isEqualTo("Compiler");
assertThat(dto2.getParentId()).isEqualTo(1);
assertThat(dto2.getOrder()).isNull();
assertThat(dto2.getCreatedAt()).isEqualTo(oldDate);
assertThat(dto2.getUpdatedAt()).isEqualTo(now);
}