interface ZIF_DAO_MATERIAL
public .
methods GET
importing
!PMATERIALNUMBER type MATNR
returning
value(PMARA) type MARA .
endinterface.
class ZCL_DAO_MATERIAL definition
public
create public .
public section.
interfaces ZIF_DAO_MATERIAL .
class-methods GETINSTANCE
returning
value(PINSTANCE) type ref to ZIF_DAO_MATERIAL .
class-methods SETINSTANCE
importing
!PINSTANCE type ref to ZIF_DAO_MATERIAL.
protected section.
private section.
CLASS-DATA:
instance type ref to ZIF_DAO_MATERIAL,
instanceObj type ref to ZCL_DAO_MATERIAL.
ENDCLASS.
CLASS ZCL_DAO_MATERIAL IMPLEMENTATION.
method GETINSTANCE.
if ( instance IS INITIAL ).
CREATE OBJECT instanceObj.
instance ?= instanceObj.
endif.
pInstance = instance.
endmethod.
method SETINSTANCE.
instance = pInstance.
endmethod.
method ZIF_DAO_MATERIAL~GET.
SELECT *
INTO @pMARA
FROM MARA
WHERE matnr = @pMaterialnumber.
ENDSELECT.
endmethod.
ENDCLASS.
class ZCL_MATERIAL_FACADE definition
public
final
create public .
public section.
METHODS:
constructor,
getGrossWeight importing pMaterialnumber type MATNR
returning value(pGrossWeight) type BRGEW.
protected section.
private section.
DATA: materialDao type ref to ZIF_DAO_MATERIAL.
ENDCLASS.
CLASS ZCL_MATERIAL_FACADE IMPLEMENTATION.
method constructor.
materialDao = ZCL_DAO_MATERIAL=>getInstance( ).
endmethod.
method getGrossWeight.
DATA: mara type MARA.
mara = materialDao->get( pMaterialnumber ).
pGrossWeight = mara-brgew.
endmethod.
ENDCLASS.
class ZCL_DAO_MATERIAL_TESTDOUBLE definition
public
final
create public
for testing .
public section.
class-methods getTestDouble
returning
value(PMATERIALDAOTESTDOUBLE) type ref to ZIF_DAO_MATERIAL .
protected section.
private section.
ENDCLASS.
CLASS ZCL_DAO_MATERIAL_TESTDOUBLE IMPLEMENTATION.
METHOD getTestDouble.
DATA: lo_answer type ref to lclAnswerMaterialDaoGet.
pMaterialDaoTestDouble ?= cl_abap_testdouble=>create( 'ZIF_DAO_MATERIAL' ).
CREATE OBJECT lo_answer.
cl_abap_testdouble=>configure_call( pMaterialDaoTestDouble )->ignore_all_parameters( )->set_answer( lo_answer ).
pMaterialDaoTestDouble->get( 'DUMMY_ARTIKEL' ).
ENDMETHOD.
ENDCLASS.
CLASS lclAnswerMaterialDaoGet DEFINITION.
public section.
interfaces if_abap_testdouble_answer.
ENDCLASS.
CLASS lclAnswerMaterialDaoGet IMPLEMENTATION.
METHOD if_abap_testdouble_answer~answer.
DATA: lv_src_materialnumber_data TYPE REF TO data,
retMara type MARA.
FIELD-SYMBOLS: <lv_src_materialnumber> TYPE MATNR,
<retMara> type MARA.
lv_src_materialnumber_data = arguments->get_param_importing( 'pMaterialnumber' ).
ASSIGN lv_src_materialnumber_data->* TO <lv_src_materialnumber>.
if ( <lv_src_materialnumber> = 'EXISTING_ARTIKEL1' OR <lv_src_materialnumber> = 'EXISTING_ARTIKEL2' ).
retMara-brgew = 2.
else.
retMara-brgew = 0.
endif.
result->set_param_returning( retMara ).
endmethod.
ENDCLASS.
class ZCL_MATERIAL_FACADE_TDOUB_UNIT definition FOR TESTING.
"#AU Risk_Level Harmless
PUBLIC SECTION.
private section.
DATA: materialFacade type ref to ZCL_MATERIAL_FACADE.
CLASS-METHODS:
class_setup.
METHODS:
setup,
testGetGrossWeightWithTDouble FOR TESTING.
ENDCLASS.
CLASS ZCL_MATERIAL_FACADE_TDOUB_UNIT IMPLEMENTATION.
method class_setup.
DATA: materialDaoTestDouble type ref to ZIF_DAO_MATERIAL.
materialDaoTestDouble = ZCL_DAO_MATERIAL_TESTDOUBLE=>getTestDouble( ).
ZCL_DAO_MATERIAL=>setinstance( materialDaoTestDouble ).
endmethod.
method setup.
create object materialFacade.
endmethod.
method testGetGrossWeightWithTDouble.
DATA: grossWeight type mara-brgew.
grossWeight = materialFacade->getGrossWeight( 'EXISTING_ARTIKEL1' ).
cl_aunit_assert=>assert_equals( EXP = 2 ACT = grossWeight MSG = '' ).
grossWeight = materialFacade->getGrossWeight( 'EXISTING_ARTIKEL2' ).
cl_aunit_assert=>assert_equals( EXP = 2 ACT = grossWeight MSG = '' ).
grossWeight = materialFacade->getGrossWeight( 'MISSING_ARTIKEL' ).
cl_aunit_assert=>assert_equals( EXP = 0 ACT = grossWeight MSG = '' ).
endmethod.
ENDCLASS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |