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
45 changes: 45 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and analyze with SonarCloud

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
branches:
- master

jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn clean verify sonar:sonar -Dsonar.projectKey=IVANFPARDO_refactoring-fowler-example -Dsonar.organization=ivanfpardo -Dsonar.host.url=https://sonarcloud.io -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml

60 changes: 60 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<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>com.ivanfpardo</groupId>
<artifactId>refactoring-fowler-example</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Sonar plugin -->
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
</plugin>

<!-- JaCoCo plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</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.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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <A HREF="mailto:clopezno@ubu.es">Carlos López</A>
* @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.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
*
*/

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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <A HREF="mailto:clopezno@ubu.es">Carlos López</A>
* @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.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
*
*/
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;
}

}
Loading