Я решил проблему, используя следующий трюк при назначении теневого пути для представления контейнера:
[UIBezierPath bezierPathWithRoundedRect:cell.bounds cornerRadius:12]
Обратите внимание, что путь к тени - это закругленный прямоугольник с тем же угловым радиусом, что и фон что ячейка содержит:
//this is the border for the UIView that is added to a cell
cell.backgroundView.layer.cornerRadius = 12;
cell.backgroundView.layer.masksToBounds = YES;
cell.backgroundView.layer.borderColor = [UIColor darkGrayColor].CGColor;
cell.backgroundView.layer.borderWidth = 1;
//this is the shadow around the cell itself (cannot have round corners with borders and shadow, need to use two views
cell.layer.shadowRadius = 2;
cell.layer.cornerRadius = 12;
cell.layer.masksToBounds = NO;
[[cell layer] setShadowColor:[[UIColor darkGrayColor] CGColor]];
[[cell layer] setShadowOffset:CGSizeMake(0.0,0.0)];
[[cell layer] setShadowOpacity:1.0];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.bounds cornerRadius:12];
[[cell layer] setShadowPath:[path CGPath]];
Вы должны настроить @Spy
в методе @Before
, потому что во время создания класса макеты еще не инициализированы:
public class MyWebSocketHandlerDecpratorTest {
@Mock
private WebSocketSession session;
@Mock
WebSocketHandler delegate;
private WebSocketHandlerDecorator webSocketHandlerDecorator;
@InjectMocks
MyWebSocketHandlerDecorator myWebSocketHandlerDecorator;
private TextMessage message;
@Before
public void set_up(){
MockitoAnnotations.initMocks(this);
webSocketHandlerDecorator = Mockito.spy(new WebSocketHandlerDecorator(delegate));
message = new TextMessage("Test Message".getBytes());
}
@Test
public void handleMessage()throws Exception{
myWebSocketHandlerDecorator.handleMessage(session, message);
verify(webSocketHandlerDecorator, times(1)).handleMessage(session, message);
}
}