Buenas Tardes tengo un error el error es:
initializacionError,
Soy nuevo, y tengo un método:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DutyFreeHelperTest.class)
public class DutyFreeHelperTest {
private ApplicationSettingsRepository applicationSettingsRepository;
DutyFreeHelper d = new DutyFreeHelper();
@Test
@SuppressWarnings("unlikely-arg-type")
@Test
public void getDutyFreeFeeValueByGatewayExceptionTest()
{
BigDecimal dutyFreeValue = BigDecimal.valueOf(1);
dutyFreeValue = DutyFreeHelper.getDutyFreeFeeValueByGateway("cr", applicationSettingsRepository);
assertNotNull(dutyFreeValue);
equals(BigDecimal.valueOf(1));
}
@SuppressWarnings({ "unlikely-arg-type", "unused" })
@Test
public void getDutyFreeFeeValueByGatewayTest() {
BigDecimal dutyFreeValue = BigDecimal.valueOf(1);
DutyFreeHelper.getDutyFreeFeeValueByGateway("cr",null);
equals(BigDecimal.valueOf(1));
}
No se que me falta ya he leído muchas cosas, pero estoy aprendiendo solo sobre esto.
public static BigDecimal getDutyFreeFeeValueByGateway(String gateway, ApplicationSettingsRepository applicationSettingsRepository){
BigDecimal dutyFreeValue = BigDecimal.valueOf(0);
String wholeConfig;
String[] arrayConfig;
List<String> gatewaysWithFreeFee;
try{
gatewaysWithFreeFee = Arrays.asList(applicationSettingsRepository.findFirstByKeyName(Constants.DUTY_FREE_FEE).getValue().split(Constants.SEMICOLON));
if(gatewaysWithFreeFee != null){
wholeConfig = gatewaysWithFreeFee.stream().filter(x->x.contains(gateway)).findFirst().get();
if(!StringUtils.isEmpty(wholeConfig)){
arrayConfig = wholeConfig.split(Pattern.quote(Constants.PIPE));
dutyFreeValue = new BigDecimal(arrayConfig[1].trim());
}
}
}
catch (Exception ex){
log.error("DutyFreeHelper | getDutyFreeFeeValueByGateway gateway: {0} applicationSettingsRepository: {1} | Exception: {2}", gateway, applicationSettingsRepository, ex);
}
return dutyFreeValue;
}
este es el metodo solo entra en el catch pero no se por que que le falta ya que el applicationsetingrepository viene en null
otra cosa el applicationsetingrepository es esto
/**
* Spring Data repository for the ApplicationSettings entity.
*/
@SuppressWarnings("unused")
@Repository
@Transactional("quotingtoolTransactionManager")
@PersistenceContext(name = "quotingtoolEntityManagerFactory")
public interface ApplicationSettingsRepository extends JpaRepository<ApplicationSettings, Long> {
static final String CACHE_PREFIX = "price.";
public static final String FIND_FIRST_BY_KEY_NAME = CACHE_PREFIX + "findFirstByKeyName";
@Cacheable(value = FIND_FIRST_BY_KEY_NAME, key = "#p0")
ApplicationSettings findFirstByKeyName(String keyName);
}
ApplicationSettingsRepository
y su implementación a la lista de classes de el contexto de prueba que estás creando?@SpringBootTest(classes = DutyFreeHelperTest.class, ApplicationSettingsRepositoryImpl.class)
{DutyFreeHelperTest.class, ApplicationSettingsRepositoryImpl.class}