Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.


92 changes: 0 additions & 92 deletions build.xml

This file was deleted.

Binary file removed lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file removed lib/jacocoant.jar
Binary file not shown.
Binary file removed lib/junit-4.12.jar
Binary file not shown.
82 changes: 82 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ubu.gii</groupId>
<artifactId>javaAppFowler</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Refactoring Fowler Example</name>

<url>https://github.com/clopezno/refactoring-fowler-example</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>

</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -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 <A HREF="mailto:clopezno@ubu.es">Carlos L�pez</A>
* @version 1.1
* @see java.io.File
*
*/
import java.util.*;
public class Customer {
private String _name;
private List<Rental> _rentals;
public Customer(String name) {
_name = name;
_rentals = new ArrayList<Rental>();
};
public void addRental(Rental arg) {
_rentals.add(arg);
}
public String getName() {
return _name;
};
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Iterator<Rental> 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 <A HREF="mailto:clopezno@ubu.es">Carlos L�pez</A>
* @version 1.1
* @see java.io.File
*
*/
import java.util.*;

public class Customer {
private String _name;
private List<Rental> _rentals;

public Customer(String name) {
_name = name;
_rentals = new ArrayList<Rental>();

};

public void addRental(Rental arg) {
_rentals.add(arg);
}

public String getName() {
return _name;
};

public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Iterator<Rental> 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;
}
}
Loading