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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.digite.kata.refactoring;

public interface AmountInterface
{
public int getPriceCode();
public double getAmount(int a_rentalDays);
}
22 changes: 22 additions & 0 deletions src/main/java/com/digite/kata/refactoring/ChildrenMovie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.digite.kata.refactoring;

public class ChildrenMovie implements AmountInterface {
@Override
public int getPriceCode() {
return Movie.CHILDRENS;
}

@Override
public double getAmount(int a_rentalDays)
{
/*
* thisAmount += 1.5; if (each.getDaysRented() > 3) thisAmount +=
* (each.getDaysRented() - 3) * 1.5;
*/
double w_rentAmount = 1.5;
if (a_rentalDays > 3)
w_rentAmount += (a_rentalDays - 3) * 1.5;
return w_rentAmount;
}

}
37 changes: 37 additions & 0 deletions src/main/java/com/digite/kata/refactoring/JTestMovie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.digite.kata.refactoring;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;

public class JTestMovie
{
@Test
public void testRegularMovie()
{
Movie w_movieObj = new Movie("Movie1", 0);
w_movieObj.setPriceCode(4);
AmountInterface w_regMov = new RegularMovie();
double w_amount = w_movieObj.getAmount(w_movieObj, w_regMov);
assertEquals(w_amount, 5);
}

@Test
public void testChildrenMovie()
{
Movie w_movieObj = new Movie("Movie2", 2);
w_movieObj.setPriceCode(4);
AmountInterface w_childMovie = new ChildrenMovie();
double w_amount = w_movieObj.getAmount(w_movieObj, w_childMovie);
assertEquals(w_amount, 3);
}

@Test
public void testNewReleaseMovie()
{
Movie w_movieObj = new Movie("Movie3", 1);
w_movieObj.setPriceCode(4);
AmountInterface w_regMov = new NewReleaseMovie();
double w_amount = w_movieObj.getAmount(w_movieObj, w_regMov);
assertEquals(w_amount, 12);
}
}
21 changes: 13 additions & 8 deletions src/main/java/com/digite/kata/refactoring/Movie.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.digite.kata.refactoring;

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) {
public static final int CHILDRENS = 2;
public static final int NEW_RELEASE = 1;
public static final int REGULAR = 0;
private String _title;
private int _priceCode;
public Movie(String title, int priceCode) {
_title = title;
_priceCode = priceCode;
}
Expand All @@ -23,4 +23,9 @@ public int getPriceCode() {
public void setPriceCode(int priceCode) {
_priceCode = priceCode;
}
}

public double getAmount(Movie a_movie, AmountInterface a_amount) {
double w_amount = a_amount.getAmount(a_movie.getPriceCode());
return w_amount;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/digite/kata/refactoring/NewReleaseMovie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.digite.kata.refactoring;

public class NewReleaseMovie implements AmountInterface{
@Override
public int getPriceCode() {
return Movie.NEW_RELEASE;
}

@Override
public double getAmount(int a_rentalDays)
{
//thisAmount += each.getDaysRented() * 3;
double w_rentAmount = a_rentalDays * 3;
return w_rentAmount;
}

}
18 changes: 18 additions & 0 deletions src/main/java/com/digite/kata/refactoring/RegularMovie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.digite.kata.refactoring;

public class RegularMovie implements AmountInterface{

public int getPriceCode() {
return Movie.REGULAR;
}

public double getAmount(int a_rentalDays)
{
/* if (each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 1.5;*/
double w_rentAmount = 2;
if (a_rentalDays > 2)
w_rentAmount += (a_rentalDays - 2) * 1.5;
return w_rentAmount;
}
}