### Question:
SegmentTransfer { public void transfer() { Segment realtSeg = null; Segment histSeg = null; try { SEG_SVC.save(histSegKey); realtSeg = newSegment(realtSegKey); histSeg = newSegment(histSegKey); SegmentBuilder segBuilder = new SegmentBuilder(histSeg, realtSeg.getMetaData().getFieldNames(), Collections.singletonList(realtSeg), Collections.singletonList(realtSeg.getAllShowIndex())); segBuilder.build(); onSucceed(); } catch (Exception e) { remove(histSegKey); SwiftLoggers.getLogger().error("seg transfer from {} to {} failed", realtSegKey, histSegKey, e); } finally { SegmentUtils.releaseHisSeg(Arrays.asList(realtSeg, histSeg)); } } SegmentTransfer(SegmentKey realtSegKey); void transfer();  }### Answer:
@Test public void transfer() throws Exception { SegmentKey newSegKey = mock(SegmentKey.class); mockStatic(SegmentUtils.class); Segment oldSeg = mock(Segment.class, RETURNS_DEEP_STUBS), newSeg = mock(Segment.class); when(SegmentUtils.newSegment(oldSegKey)).thenReturn(oldSeg); when(SegmentUtils.newSegment(newSegKey)).thenReturn(newSeg); SegmentTransfer transfer = new SegmentTransfer(oldSegKey); transfer.transfer(); verifyNew(SegmentBuilder.class).withArguments(newSeg, oldSeg.getMetaData().getFieldNames(), Collections.singletonList(oldSeg), Collections.singletonList(oldSeg.getAllShowIndex())); verify(segmentBuilder).build(); verifyStatic(SegmentUtils.class); SegmentUtils.clearSegment(oldSegKey); verify(SwiftContext.get().getBean(SegmentService.class)).getSegment(newSegKey); verifyStatic(SegmentUtils.class); SegmentUtils.releaseHisSeg(Arrays.asList(oldSeg, newSeg)); }