SamSelectionRequest extends AbstractSeSelectionRequest<
        AbstractSamCommandBuilder<? extends AbstractSamResponseParser>> { @Override protected CalypsoSam parse(SeResponse seResponse) { List<AbstractSamCommandBuilder<? extends AbstractSamResponseParser>> commandBuilders = getCommandBuilders(); if (commandBuilders.size() == 1) { List<ApduResponse> apduResponses = seResponse.getApduResponses(); if (apduResponses == null) { throw new CalypsoDesynchronizedExchangesException( "Mismatch in the number of requests/responses"); } commandBuilders.get(0).createResponseParser(apduResponses.get(0)).checkStatus(); } return new CalypsoSam(seResponse); } SamSelectionRequest(SamSelector samSelector);   }
@Test public void samSelectionRequest_parse() { SamSelector samSelector = SamSelector.builder() .samRevision(SamRevision.AUTO) .build(); SamSelectionRequest samSelectionRequest = new SamSelectionRequest(samSelector); SelectionStatus selectionStatus = new SelectionStatus(new AnswerToReset(ATR), null, true); CalypsoSam calypsoSam = samSelectionRequest.parse(new SeResponse(true, true, selectionStatus, null)); assertThat(calypsoSam.getSamRevision()).isEqualTo(SamRevision.C1); assertThat(calypsoSam.getSerialNumber()).isEqualTo(SN); }
@Test public void samSelectionRequest_unlock_ok() { SamSelector samSelector = SamSelector.builder() .samRevision(SamRevision.AUTO) .unlockData(UNLOCK_DATA) .build(); SamSelectionRequest samSelectionRequest = new SamSelectionRequest(samSelector); SelectionStatus selectionStatus = new SelectionStatus(new AnswerToReset(ATR), null, true); List<ApduResponse> apduResponses = new ArrayList<ApduResponse>(); apduResponses.add(UNLOCK_APDU_RESPONSE_OK); CalypsoSam calypsoSam = samSelectionRequest.parse(new SeResponse(true, true, selectionStatus, apduResponses)); assertThat(calypsoSam.getSamRevision()).isEqualTo(SamRevision.C1); assertThat(calypsoSam.getSerialNumber()).isEqualTo(SN); }
@Test(expected = CalypsoSamCommandException.class) public void samSelectionRequest_unlock_ko() { SamSelector samSelector = SamSelector.builder() .samRevision(SamRevision.AUTO) .unlockData(UNLOCK_DATA) .build(); SamSelectionRequest samSelectionRequest = new SamSelectionRequest(samSelector); SelectionStatus selectionStatus = new SelectionStatus(new AnswerToReset(ATR), null, true); List<ApduResponse> apduResponses = new ArrayList<ApduResponse>(); apduResponses.add(UNLOCK_APDU_RESPONSE_KO); CalypsoSam calypsoSam = samSelectionRequest.parse(new SeResponse(true, true, selectionStatus, apduResponses)); }