Skip to content

Commit

Permalink
Agregando unit test y cambio menores en clase Gasolina
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosvasquez committed Oct 2, 2014
1 parent 8f20014 commit 38b872c
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/main/java/org/devdom/commons/Gasolina.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import org.devdom.commons.exceptions.MalformedXMLException;

/**
*
* Clase utilizada para obtener los precios de los carburantes en la República Dominicana
*
* @author Carlos Vásquez Polanco
* @since 0.6.7
*/
Expand All @@ -56,14 +57,16 @@ public Gasolina() throws MalformedXMLException {
}

/**
*
* Obtener objeto Feed con los precios actuales
* @see Feed
* @return
*/
public Feed getCurrentPrices(){
return feed;
}

/**
* Obtener el precio de un carburante dado el campo que desea ser evaluado
*
* @param item
* @return
Expand All @@ -77,34 +80,66 @@ public double get(String item){
return Double.parseDouble(parser.getProperty(feed, item));
}

/**
* Obtener el títuto usado en el RSS por el Ministerio de Industria y Comercio
* @return
*/
public String getTitle(){
return feed.getTitle();
}

/**
* Obtener el precio de la Gasolina Premium en la República Dominicana
* @return
*/
public double getCurrentGasolinaPremiumPrice(){
return get(Gasolina.GASOIL_PREMIUM);
}

/**
* Obtener el precio de la Gasolina Regular en la República Dominicana
* @return
*/
public double getCurrentGasolinaRegularPrice(){
return get(Gasolina.GASOIL_REGULAR);
}

/**
* Obtener el precio del Gasoil Premium en la República Dominicana
* @return
*/
public double getCurrentGasoilPremiumPrice(){
return get(Gasolina.GASOIL_PREMIUM);
}

/**
* Obtener el precio del Gasoil Regular en la República Dominicana
* @return
*/
public double getCurrentGasoilRegularPrice(){
return get(Gasolina.GASOIL_REGULAR);
}

/**
* Obtener el precio del Kerosene en la República Dominicana
* @return
*/
public double getCurrentKerosenePrice(){
return get(Gasolina.KEROSENE);
}

/**
* Obtener el precio del Gas Licuado De Petroleo en la República Dominicana
* @return
*/
public double getCurrentGasLicuadoDePetroleo(){
return get(Gasolina.GAS_LICUADO_DE_PETROLEO);
}

/**
* Obtener el precio del Gas Natural Vehicular en la República Dominicana
* @return
*/
public double getCurrentGasNautralVehicular(){
return get(Gasolina.GAS_NATURAL_VEHICULAR);
}
Expand Down
77 changes: 77 additions & 0 deletions src/test/java/org/devdom/commons/GasolinaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* The MIT License
*
* Copyright 2014 Developers Dominicanos.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.devdom.commons;

import org.devdom.commons.dto.Feed;
import org.devdom.commons.exceptions.MalformedXMLException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

/**
*
* @author Carlos Vásquez Polanco
*/
public class GasolinaTest {

private Gasolina gasolina;
private Feed feed;

public GasolinaTest() {
}

@Before
public void setUp() throws MalformedXMLException {
gasolina = new Gasolina();
}

/**
* Test of getCurrentPrices method, of class Gasolina.
*/
@Test
public void testGetCurrentPrices() {
feed = gasolina.getCurrentPrices();
assertNotNull("El objeto retornó nulo", feed);
assertTrue("No retornó precios válidos", ( Double.parseDouble(feed.getGas89()) > 0) );
}

/**
* Test of getCurrentGasolinaPremiumPrice method, of class Gasolina.
*/
@Test
public void testGetCurrentGasolinaPremiumPrice() {
assertTrue("No retornó precio para la gasolina premium", gasolina.get(Gasolina.GASOLINA_PREMIUM)>0);
}

/**
* Test of getCurrentGasolinaRegularPrice method, of class Gasolina.
*/
@Test
public void testGetCurrentGasolinaRegularPrice() {
assertTrue("No retornó precio para la gasolina regular", gasolina.get(Gasolina.GASOLINA_REGULAR)>0);
}

}

0 comments on commit 38b872c

Please sign in to comment.