For this code snippet
@Component
public class StorageResource {
@Autowired
private Storage storage;
public String addItem(StorageItem item) {
WrappedStorageItem wsi = new WrappedStorageItem(item);
storage.add(wsi);
return wsi.getId();
}
}
the unit test looks something like this
@Test
void testCase() {
StorageResource storageResource = new StorageResource();
Storage storageMock = createMock(Storage.class);
Whitebox.setInternalState(storageResource, Storage.class, storage);
StorageItem item = new StorageItem();
WrappedStorageItem wos = new WrappedStorageItem(item);
expectNew(WrappedStorageItem.class, item).andReturn(wos);
storageMock.add(wos);
expectLastCall();
replayAll();
storageResource.addItem(item);
verifyAll();
}
But how the test will look like if I use groovy
? Will it be less verbose?
Aucun commentaire:
Enregistrer un commentaire