This question already has an answer here:
Here I have class and i want to write a testcase. Testcase also given below.But in the test case expectedPrefixArray.add(String.valueOf( field.get(CACHE_KEY_PREFIX.KeyPrefix.class))); return a nullpointer.What is the reason for this? Accessebility also set to true. Some help me please.......................
public enum CACHE_KEY_PREFIX {
SYMBOL_CACHE(new String[]{KeyPrefix.KEY_PREFIX_SYMBOL_CACHE_SRC_DEFAULT, KeyPrefix.KEY_PREFIX_SYMBOL_CACHE_SRC_RIC,
KeyPrefix.KEY_PREFIX_SYMBOL_CACHE_SRC_ISIN}),
EXCHANGE_CACHE(new String[]{KeyPrefix.KEY_PREFIX_EXCHANGE_CACHE_TAG_DEFAULT, KeyPrefix.KEY_PREFIX_EXCHANGE_CACHE_TAG_207,
KeyPrefix.KEY_PREFIX_EXCHANGE_CACHE_TAG_100, KeyPrefix.KEY_PREFIX_EXCHANGE_CACHE_TICK_SIZES}),
LOGIN_ID_MAPPINGS_CACHE(new String[]{KeyPrefix.KEY_PREFIX_LOGIN_CASH_ACNT_MAP, KeyPrefix.KEY_PREFIX_LOGIN_TRADING_MAP}),
U08_BENEFICIARY_ACCOUNT_CACHE(new String[]{KeyPrefix.KEY_PREFIX_BENEFICIARY_CACHE}),
CURRENCY_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CURRENCY_STORE, KeyPrefix.KEY_PREFIX_DECIMAL_CURRENCY}),
U06_CASH_ACCOUNT_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CASH_ACNT_TRANSACTION}),
U06_CASH_ACCOUNT_MASTER_DATA_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CASH_ACNT_MASTER_DATA}),
MARKET_RESTRICTION_CACHE(new String[]{KeyPrefix.KEY_PREFIX_ALLOWED_TIF_BY_STATUS, KeyPrefix.KEY_PREFIX_ALLOWED_ACTION_BY_STATUS,
KeyPrefix.KEY_PREFIX_ALLOWED_ORDER_TYPES}),
USER_ID_MAPPINGS_CACHE(new String[]{KeyPrefix.KEY_PREFIX_USERID_CASH_ACNT_MAP}),
ORD_CHANNEL_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CHANNEL}),
MARGIN_SYMBOL_CACHE(new String[]{KeyPrefix.KEY_PREFIX_MARGIN_SYMBOL_MARGINABILITY, KeyPrefix.KEY_PREFIX_MARGIN_STOCK_CONCENTRATION}),
U07_TRADING_ACNT_CACHE(new String[]{KeyPrefix.KEY_PREFIX_TRD_ANCT_BY_NO, KeyPrefix.KEY_PREFIX_TRD_ANCT_BY_EXT_NO, KeyPrefix.KEY_PREFIX_TRD_ANCT_BY_ID}),
TRADING_MARKET_CACHE(new String[]{KeyPrefix.KEY_PREFIX_TRADNG_MRKT, KeyPrefix.KEY_PREFIX_CNN_ALIAS_TRADNG_MRKT,
KeyPrefix.KEY_PREFIX_TRADNG_MRKT_EXG_BY_TAGS, KeyPrefix.KEY_PREFIX_TRADNG_MRKT_BY_TYPE, KeyPrefix.KEY_PREFIX_EXEBRK_TRADNG_MRKT,
KeyPrefix.KEY_PREFIX_M29_MARKET_BY_EXG, KeyPrefix.KEY_PREFIX_M29_MARKET_BY_ALL}),
COMMISSION_GROUP_BY_CHANNEL_CACHE(new String[]{KeyPrefix.KEY_PREFIX_COMMISION_GRP_BY_CHANNEL_DLMTD}),
POWER_OF_ATTORNEY_CACHE(new String[]{KeyPrefix.KEY_PREFIX_POA}),
EXT_REF_MAP_CACHE(new String[]{KeyPrefix.KEY_PREFIX_EXT_REF_MAP_CACHE_RCLIORDID, KeyPrefix.KEY_PREFIX_EXT_REF_MAP_CACHE_EXGORDID}),
TRADING_HOLDING_MAPPING_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CASH_TRADING_MAP, KeyPrefix.KEY_PREFIX_CASH_ACNT_TO_HOLDING_MAP}),
COMMISSION_SLABS_CACHE(new String[]{KeyPrefix.KEY_PREFIX_COMMISSION_GRP, KeyPrefix.KEY_PREFIX_EXEC_BROKER_COMMISSION_DLMTD, KeyPrefix.KEY_PREFIX_CUSTOMER_COMMISSION_DLMTD,
KeyPrefix.KEY_PREFIX_COMMISSION_DISCOUNT_DLMTD}),
CHARGE_CACHE(new String[]{KeyPrefix.KEY_PREFIX_CHARGE}),
//Todo remove this
CASH_PRECISION_CACHE(new String[]{KeyPrefix.CACHE_KEY_CASH_PRECESSION});
public static class KeyPrefix {
public static final String KEY_PREFIX_SYMBOL_CACHE_SRC_RIC = "RIC";
public static final String KEY_PREFIX_SYMBOL_CACHE_SRC_ISIN = "ISIN";
public static final String KEY_PREFIX_SYMBOL_CACHE_SRC_DEFAULT = "DEFAULT";
public static final String KEY_PREFIX_EXCHANGE_CACHE_TAG_100 = "TAG_100";
public static final String KEY_PREFIX_EXCHANGE_CACHE_TAG_207 = "TAG_207";
public static final String KEY_PREFIX_EXCHANGE_CACHE_TAG_DEFAULT = "DEFAULT";
public static final String KEY_PREFIX_EXCHANGE_CACHE_TICK_SIZES = "EXG_TICK";
public static final String KEY_PREFIX_LOGIN_TRADING_MAP = "LTMAP";
public static final String KEY_PREFIX_LOGIN_CASH_ACNT_MAP = "LCMAP";
public static final String KEY_PREFIX_BENEFICIARY_CACHE = "U08BEN";
public static final String KEY_PREFIX_CURRENCY_STORE = "CRSTR";
public static final String KEY_PREFIX_DECIMAL_CURRENCY = "DCR";
public static final String KEY_PREFIX_CASH_ACNT_TRANSACTION = "TXNCash";
public static final String KEY_PREFIX_CASH_ACNT_MASTER_DATA = "MSTRCash";
public static final String KEY_PREFIX_ALLOWED_TIF_BY_STATUS = "MKT_TIF";
public static final String KEY_PREFIX_ALLOWED_ACTION_BY_STATUS = "MKT_STATUS";
public static final String KEY_PREFIX_ALLOWED_ORDER_TYPES = "ORD_TYPES";
public static final String KEY_PREFIX_USERID_CASH_ACNT_MAP = "LUCMAP";
public static final String KEY_PREFIX_CHANNEL = "ORDCHNEL";
public static final String KEY_PREFIX_MARGIN_SYMBOL_MARGINABILITY = "SYMBOL_MAR";
public static final String KEY_PREFIX_MARGIN_STOCK_CONCENTRATION = "STOCK_CON";
public static final String KEY_PREFIX_TRD_ANCT_BY_NO = "TRD_NO";
public static final String KEY_PREFIX_TRD_ANCT_BY_EXT_NO = "TRD_NO_EXT";
public static final String KEY_PREFIX_TRD_ANCT_BY_ID = "TRD_ID";
public static final String KEY_PREFIX_TRADNG_MRKT = "TM";
public static final String KEY_PREFIX_CNN_ALIAS_TRADNG_MRKT = "CATM";
public static final String KEY_PREFIX_TRADNG_MRKT_EXG_BY_TAGS = "EXG_BY_TAGS_49_56";
public static final String KEY_PREFIX_TRADNG_MRKT_BY_TYPE = "TYPE_TM";
public static final String KEY_PREFIX_EXEBRK_TRADNG_MRKT = "EXTM";
public static final String KEY_PREFIX_M29_MARKET_BY_EXG = "M29MKT_EXG";
public static final String KEY_PREFIX_M29_MARKET_BY_ALL = "M29MKT_ALL";
public static final String KEY_PREFIX_COMMISION_GRP_BY_CHANNEL_DLMTD = "CHCOM";
public static final String KEY_PREFIX_POA = "POA";
public static final String KEY_PREFIX_COMMISSION_GRP = "GRP";
public static final String KEY_PREFIX_EXEC_BROKER_COMMISSION_DLMTD = "ECOM";
public static final String KEY_PREFIX_CUSTOMER_COMMISSION_DLMTD = "CCOM";
public static final String KEY_PREFIX_COMMISSION_DISCOUNT_DLMTD = "DCOM";
public static final String KEY_PREFIX_EXT_REF_MAP_CACHE_RCLIORDID = "RCLIORDID";
public static final String KEY_PREFIX_EXT_REF_MAP_CACHE_EXGORDID = "EXGORDID";
public static final String KEY_PREFIX_CASH_TRADING_MAP = "CASH_TRADING";
public static final String KEY_PREFIX_CASH_ACNT_TO_HOLDING_MAP = "CASH_ACC_HOLDINGS_MAP";
public static final String CACHE_KEY_CASH_PRECESSION = "CASH_PRECESSION";
public static final String KEY_PREFIX_CHARGE = "CHARGE";
}
public String[] prefixArray;
CACHE_KEY_PREFIX(String[] prefixArray) {
this.prefixArray = prefixArray;
}
public static String KEY_SEPARATOR = "~";
public static String KEY_PREFIX_DEFAULT = "KEY_DEFAULT";
@Test
public void checkCachePrefixAvailableTest() throws Exception {
List<String> expectedPrefixArray = new ArrayList<>();
List<String> actualPrefixArray = new ArrayList<>();
CACHE_KEY_PREFIX[] yourEnums = CACHE_KEY_PREFIX.values();
Field[] cacheNames =
CACHE_KEY_PREFIX.KeyPrefix.class.getDeclaredFields();
//list of expected prefixes
for (Field field : cacheNames) {
field.setAccessible(true);
expectedPrefixArray.add(String.valueOf(
field.get(CACHE_KEY_PREFIX.KeyPrefix.class)));
}
//list of actual prefixes
for (int i = 0; i < yourEnums.length; i++) {
String[] prefix = CACHE_KEY_PREFIX.values()[i].prefixArray;
for (int j = 0; j < CACHE_KEY_PREFIX.values()[i].prefixArray.length;
j++) {
actualPrefixArray.add(prefix[j]);
}
}
Aucun commentaire:
Enregistrer un commentaire