diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d020cccd --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* +/bin/ + +#Eclipse file +.project +.classpath + +#Maven target +/target \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index faeab2d6..00000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: java -before_script: - - sudo apt-get install ant-optional -jdk: - - openjdk8 diff --git a/README.md b/README.md index 2fc3deb3..704635f2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ refactoring-fowler-example ========================== -[![Build Status](https://travis-ci.org/clopezno/refactoring-fowler-example.svg?branch=master)](https://travis-ci.org/clopezno/refactoring-fowler-example) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/82d8b811489b4a58ad3bc2e79f32aede)](https://app.codacy.com/app/clopezno/refactoring-fowler-example?utm_source=github.com&utm_medium=referral&utm_content=clopezno/refactoring-fowler-example&utm_campaign=Badge_Grade_Dashboard) Java code example to teach basic refactoring concepts. -Travis CI is applied to continuous integration and Codacy to continuous quality assurance. -[In this Udemy course the last vídeo](https://www.udemy.com/refactoriza-para-mejorar-la-calidad-del-codigo-java/) explains how to use Travis in this repository. + + diff --git a/build.xml b/build.xml deleted file mode 100644 index 24573915..00000000 --- a/build.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - Practica 1 de desarrollo avanzado de sistemas software - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar deleted file mode 100644 index 9d5fe16e..00000000 Binary files a/lib/hamcrest-core-1.3.jar and /dev/null differ diff --git a/lib/jacocoant.jar b/lib/jacocoant.jar deleted file mode 100644 index bf9968d9..00000000 Binary files a/lib/jacocoant.jar and /dev/null differ diff --git a/lib/junit-4.12.jar b/lib/junit-4.12.jar deleted file mode 100644 index 3a7fc266..00000000 Binary files a/lib/junit-4.12.jar and /dev/null differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..cb7ebb0a --- /dev/null +++ b/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + ubu.gii + javaAppFowler + 1.0-SNAPSHOT + + Refactoring Fowler Example + + https://github.com/clopezno/refactoring-fowler-example + + + UTF-8 + 8 + 8 + 5.9.1 + 0.8.8 + 3.0.0-M7 + + + + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.jacoco + jacoco-maven-plugin + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + + + + + \ No newline at end of file diff --git a/src/ubu/gii/dass/refactoring/Customer.java b/src/main/java/ubu/gii/Customer.java similarity index 94% rename from src/ubu/gii/dass/refactoring/Customer.java rename to src/main/java/ubu/gii/Customer.java index a5631232..ab2e3e04 100644 --- a/src/ubu/gii/dass/refactoring/Customer.java +++ b/src/main/java/ubu/gii/Customer.java @@ -1,75 +1,75 @@ -package ubu.gii.dass.refactoring; - -/** -* Tema Refactorizaciones -* -* Ejemplo de aplicaci�n de refactorizaciones. Actualizado para colecciones gen�ricas de java 1.5 -* -* @author M. Fowler y Carlos L�pez -* @version 1.1 -* @see java.io.File -* -*/ -import java.util.*; - -public class Customer { - private String _name; - private List _rentals; - - public Customer(String name) { - _name = name; - _rentals = new ArrayList(); - - }; - - public void addRental(Rental arg) { - _rentals.add(arg); - } - - public String getName() { - return _name; - }; - - public String statement() { - double totalAmount = 0; - int frequentRenterPoints = 0; - Iterator rentals = _rentals.iterator(); - String result = "Rental Record for " + getName() + "\n"; - while (rentals.hasNext()) { - double thisAmount = 0; - Rental each = rentals.next(); - // determine amounts for each line - switch (each.getMovie().getPriceCode()) { - case Movie.REGULAR: - thisAmount += 2; - if (each.getDaysRented() > 2) - thisAmount += (each.getDaysRented() - 2) * 1.5; - break; - case Movie.NEW_RELEASE: - thisAmount += each.getDaysRented() * 3; - break; - case Movie.CHILDRENS: - thisAmount += 1.5; - if (each.getDaysRented() > 3) - thisAmount += (each.getDaysRented() - 3) * 1.5; - break; - } - - // add frequent renter points - frequentRenterPoints++; - // add bonus for a two day new release rental - if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) - && each.getDaysRented() > 1) - frequentRenterPoints++; - // show figures for this rental - result += "\t" + each.getMovie().getTitle() + "\t" - + String.valueOf(thisAmount) + "\n"; - totalAmount += thisAmount; - } - // add footer lines - result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; - result += "You earned " + String.valueOf(frequentRenterPoints) - + " frequent renter points"; - return result; - } -} +package ubu.gii; + +/** +* Tema Refactorizaciones +* +* Ejemplo de aplicaci�n de refactorizaciones. Actualizado para colecciones gen�ricas de java 1.5 +* +* @author M. Fowler y Carlos L�pez +* @version 1.1 +* @see java.io.File +* +*/ +import java.util.*; + +public class Customer { + private String _name; + private List _rentals; + + public Customer(String name) { + _name = name; + _rentals = new ArrayList(); + + }; + + public void addRental(Rental arg) { + _rentals.add(arg); + } + + public String getName() { + return _name; + }; + + public String statement() { + double totalAmount = 0; + int frequentRenterPoints = 0; + Iterator rentals = _rentals.iterator(); + String result = "Rental Record for " + getName() + "\n"; + while (rentals.hasNext()) { + double thisAmount = 0; + Rental each = rentals.next(); + // determine amounts for each line + switch (each.getMovie().getPriceCode()) { + case Movie.REGULAR: + thisAmount += 2; + if (each.getDaysRented() > 2) + thisAmount += (each.getDaysRented() - 2) * 1.5; + break; + case Movie.NEW_RELEASE: + thisAmount += each.getDaysRented() * 3; + break; + case Movie.CHILDRENS: + thisAmount += 1.5; + if (each.getDaysRented() > 3) + thisAmount += (each.getDaysRented() - 3) * 1.5; + break; + } + + // add frequent renter points + frequentRenterPoints++; + // add bonus for a two day new release rental + if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) + && each.getDaysRented() > 1) + frequentRenterPoints++; + // show figures for this rental + result += "\t" + each.getMovie().getTitle() + "\t" + + String.valueOf(thisAmount) + "\n"; + totalAmount += thisAmount; + } + // add footer lines + result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; + result += "You earned " + String.valueOf(frequentRenterPoints) + + " frequent renter points"; + return result; + } +} diff --git a/src/ubu/gii/dass/refactoring/Movie.java b/src/main/java/ubu/gii/Movie.java similarity index 90% rename from src/ubu/gii/dass/refactoring/Movie.java rename to src/main/java/ubu/gii/Movie.java index c5e768f2..81f2494b 100644 --- a/src/ubu/gii/dass/refactoring/Movie.java +++ b/src/main/java/ubu/gii/Movie.java @@ -1,38 +1,38 @@ -package ubu.gii.dass.refactoring; -/** - * Tema Refactorizaciones - * - * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones - * genéricas de java 1.5. - * - * @author M. Fowler y Carlos López - * @version 1.1 - * @see java.io.File - * - */ - -public class Movie { - public static final int CHILDRENS = 2; - public static final int REGULAR = 0; - public static final int NEW_RELEASE = 1; - - private String _title; - private int _priceCode; - - public Movie(String title, int priceCode) { - _title = title; - _priceCode = priceCode; - } - - public int getPriceCode() { - return _priceCode; - } - - public void setPriceCode(int arg) { - _priceCode = arg; - } - - public String getTitle() { - return _title; - } -} +package ubu.gii; +/** + * Tema Refactorizaciones + * + * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones + * genéricas de java 1.5. + * + * @author M. Fowler y Carlos López + * @version 1.1 + * @see java.io.File + * + */ + +public class Movie { + public static final int CHILDRENS = 2; + public static final int REGULAR = 0; + public static final int NEW_RELEASE = 1; + + private String _title; + private int _priceCode; + + public Movie(String title, int priceCode) { + _title = title; + _priceCode = priceCode; + } + + public int getPriceCode() { + return _priceCode; + } + + public void setPriceCode(int arg) { + _priceCode = arg; + } + + public String getTitle() { + return _title; + } +} diff --git a/src/ubu/gii/dass/refactoring/Rental.java b/src/main/java/ubu/gii/Rental.java similarity index 89% rename from src/ubu/gii/dass/refactoring/Rental.java rename to src/main/java/ubu/gii/Rental.java index 265c5fca..ddb51fa7 100644 --- a/src/ubu/gii/dass/refactoring/Rental.java +++ b/src/main/java/ubu/gii/Rental.java @@ -1,30 +1,30 @@ -package ubu.gii.dass.refactoring; -/** - * Tema Refactorizaciones - * - * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones - * genéricas de java 1.5. - * - * @author M. Fowler y Carlos López - * @version 1.1 - * @see java.io.File - * - */ -public class Rental { - private Movie _movie; - private int _daysRented; - - public Rental(Movie movie, int daysRented) { - _movie = movie; - _daysRented = daysRented; - } - - public int getDaysRented() { - return _daysRented; - } - - public Movie getMovie() { - return _movie; - } - -} +package ubu.gii; +/** + * Tema Refactorizaciones + * + * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones + * genéricas de java 1.5. + * + * @author M. Fowler y Carlos López + * @version 1.1 + * @see java.io.File + * + */ +public class Rental { + private Movie _movie; + private int _daysRented; + + public Rental(Movie movie, int daysRented) { + _movie = movie; + _daysRented = daysRented; + } + + public int getDaysRented() { + return _daysRented; + } + + public Movie getMovie() { + return _movie; + } + +} diff --git a/src/ubu/gii/dass/refactoring/VideoClubAplicacion.java b/src/main/java/ubu/gii/VideoClubAplicacion.java similarity index 89% rename from src/ubu/gii/dass/refactoring/VideoClubAplicacion.java rename to src/main/java/ubu/gii/VideoClubAplicacion.java index 45dd9bf1..d3c5fc82 100644 --- a/src/ubu/gii/dass/refactoring/VideoClubAplicacion.java +++ b/src/main/java/ubu/gii/VideoClubAplicacion.java @@ -1,23 +1,23 @@ -package ubu.gii.dass.refactoring; -public class VideoClubAplicacion { - - public static void main(String[] arg) { - Movie m1 = new Movie("Sky Captain", 1); - Movie m3 = new Movie("Accion Mutante", 0); - Movie m4 = new Movie("Hermano Oso", 2); - - Customer c1 = new Customer("Manuel"); - - Rental r1 = new Rental(m1, 5); - Rental r2 = new Rental(m3, 1); - Rental r3 = new Rental(m4, 10); - - c1.addRental(r1); - c1.addRental(r2); - c1.addRental(r3); - - System.out.println(c1.statement()); - - } - +package ubu.gii; +public class VideoClubAplicacion { + + public static void main(String[] arg) { + Movie m1 = new Movie("Sky Captain", 1); + Movie m3 = new Movie("Accion Mutante", 0); + Movie m4 = new Movie("Hermano Oso", 2); + + Customer c1 = new Customer("Manuel"); + + Rental r1 = new Rental(m1, 5); + Rental r2 = new Rental(m3, 1); + Rental r3 = new Rental(m4, 10); + + c1.addRental(r1); + c1.addRental(r2); + c1.addRental(r3); + + System.out.println(c1.statement()); + + } + } \ No newline at end of file diff --git a/src/ubu/gii/dass/refactoring/VideoClubTest.java b/src/test/java/ubu/gii/VideoClubTest.java similarity index 64% rename from src/ubu/gii/dass/refactoring/VideoClubTest.java rename to src/test/java/ubu/gii/VideoClubTest.java index 82205d33..0283106a 100644 --- a/src/ubu/gii/dass/refactoring/VideoClubTest.java +++ b/src/test/java/ubu/gii/VideoClubTest.java @@ -1,59 +1,64 @@ -package ubu.gii.dass.refactoring; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tema Refactorizaciones - * - * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones - * genéricas de java 1.5 - * - * @author M. Fowler y Carlos L�pez - * @version 1.1 - - * - */ -public class VideoClubTest { - protected Movie m0, m11, m12, m2; - protected Customer c1; - - @Before - public void setUp() { - m11 = new Movie("Sky Captain", 1); - m12 = new Movie("Alejandro Magno", 1); - m0 = new Movie("Accion Mutante", 0); - m2 = new Movie("Hermano Oso", 2); - - c1 = new Customer("Manuel"); - } - - @After - public void tearDown() throws Exception {} - - @Test - public void testAlquiler() { - - Rental r1 = new Rental(m11, 5); - Rental r2 = new Rental(m0, 1); - Rental r3 = new Rental(m2, 10); - - c1.addRental(r1); - c1.addRental(r2); - c1.addRental(r3); - - String salida = c1.statement(); - - String salidaEsperada = new String("Rental Record for Manuel\n" - + "\tSky Captain\t15.0\n" + "\tAccion Mutante\t2.0\n" - + "\tHermano Oso\t12.0\n" + "Amount owed is 29.0\n" - + "You earned 4 frequent renter points"); - - assertTrue("Calcula mal el alquiler", salidaEsperada.equals(salida)); - - } - -} +package ubu.gii; + + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import ubu.gii.Customer; +import ubu.gii.Movie; +import ubu.gii.Rental; + +/** + * Tema Refactorizaciones + * + * Ejemplo de aplicación de refactorizaciones. Actualizado para colecciones + * genéricas de java 1.5 + * + * @author M. Fowler y Carlos L�pez + * @version 1.1 + + * + */ +public class VideoClubTest { + protected static Movie m0, m11, m12, m2; + protected static Customer c1; + + @BeforeAll + public static void setUp() { + m11 = new Movie("Sky Captain", 1); + m12 = new Movie("Alejandro Magno", 1); + m0 = new Movie("Accion Mutante", 0); + m2 = new Movie("Hermano Oso", 2); + + c1 = new Customer("Manuel"); + } + + @AfterAll + public static void tearDown() throws Exception {} + + @Test + public void testAlquiler() { + + Rental r1 = new Rental(m11, 5); + Rental r2 = new Rental(m0, 1); + Rental r3 = new Rental(m2, 10); + + c1.addRental(r1); + c1.addRental(r2); + c1.addRental(r3); + + String salida = c1.statement(); + + String salidaEsperada = new String("Rental Record for Manuel\n" + + "\tSky Captain\t15.0\n" + "\tAccion Mutante\t2.0\n" + + "\tHermano Oso\t12.0\n" + "Amount owed is 29.0\n" + + "You earned 4 frequent renter points"); + + assertTrue(salidaEsperada.equals(salida),"Calcula mal el alquiler"); + + } + +}