Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clase4abril Sarai #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
13 changes: 7 additions & 6 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
Expand All @@ -18,10 +13,16 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -12,4 +12,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.compiler.source=11
10 changes: 10 additions & 0 deletions data/coches2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"coches": [
{
"marca": "Chevrolet",
"modelo": "Camaro",
"año": 2023,
"precio": 52000
}
]
}
10 changes: 10 additions & 0 deletions data/coches3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"coches": [
{
"marca": "Ford",
"modelo": "Mustang",
"año": 2021,
"precio": 45000
}
]
}
10 changes: 10 additions & 0 deletions data/coches4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"coches": [
{
"marca": "Toyota",
"modelo": "Corolla",
"año": 2022,
"precio": 22000
}
]
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
<release>11</release>
</configuration>
</plugin>
<plugin>
Expand Down
6 changes: 4 additions & 2 deletions src/org/hmis/Coche.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
Coche other = (Coche) obj;
return año == other.año && Objects.equals(marca, other.marca) && Objects.equals(modelo, other.modelo)
&& precio == other.precio;
return año == other.año &&
Objects.equals(marca, other.marca) &&
Objects.equals(modelo, other.modelo) &&
precio == other.precio;
}


Expand Down
219 changes: 219 additions & 0 deletions test/org/hmis/CocheTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package org.hmis;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

class CocheTest {
@Test
void testEqualsObject() {
Coche coche1 = new Coche (); // Arrange
assertTrue(coche1.equals(coche1)); // Action // Assert
}

@Test
void testEqualsObjectNull() {
Coche coche1 = new Coche (); // Arrange
Coche coche2 = null;
assertFalse(coche1.equals(coche2)); // Action // Assert
}

@Test
void testEqualsObjectString() {
Coche coche1 = new Coche (); // Arrange
String coche2 = "";
assertFalse(coche1.equals(coche2)); // Action // Assert
}

@Test
void testEqualsObjectMultiple1() {
Coche primero = new Coche ("Chevrolet", "Camaro", 2023, 52000);
Coche segundo = new Coche ("Chevrolet", "Camaro", 2023, 52000);
assertEquals(true, primero.equals(segundo)); // Action // Assert
}
@Test
void testEqualsObjectMultiple2() {
Coche primero = new Coche ("Chevrolet", "Camaro", 2023, 52000);
Coche segundo = new Coche ("Chevrolet", "Camaro", 2021, 52000);
assertEquals(false, primero.equals(segundo)); // Action // Assert
}
@Test
void testEqualsObjectMultiple3() {
Coche primero = new Coche ("Chevrolet", "Camaro", 2023, 52000);
Coche segundo = new Coche ("Ford", "Camaro", 2023, 52000);
assertEquals(false, primero.equals(segundo)); // Action // Assert
}
@Test
void testEqualsObjectMultiple4() {
Coche primero = new Coche ("Chevrolet", "Camaro", 2023, 52000);
Coche segundo = new Coche ("Chevrolet", "Mustang", 2023, 52000);
assertEquals(false, primero.equals(segundo)); // Action // Assert
}
@Test
void testEqualsObjectMultiple5() {
Coche primero = new Coche ("Chevrolet", "Camaro", 2023, 52000);
Coche segundo = new Coche ("Chevrolet", "Camaro", 2023, 45000);
assertEquals(false, primero.equals(segundo)); // Action // Assert
}

@Test
void testEqualsGetMarca() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
String resultado = "Chevrolet";
assertEquals(resultado,coche1.getMarca()); // Action // Assert
}

@Test
void testEqualsSetMarca() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
String resultado = "Honda";
coche1.setMarca("Honda");
assertEquals(resultado, coche1.getMarca()); // Action // Assert
}

@Test
void testEqualsGetModelo() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
String resultado = "Camaro";
assertEquals(resultado, coche1.getModelo()); // Action // Assert
}

@Test
void testEqualsSetModelo() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
String resultado = "Civic";
coche1.setModelo("Civic");
assertEquals(resultado, coche1.getModelo()); // Action // Assert
}

@Test
void testEqualsGetAño() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
int resultado = 2023;
assertEquals(resultado, coche1.getAño()); // Action // Assert
}

@Test
void testEqualsSetAño() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
int resultado = 2023;
coche1.setAño(2023);
assertEquals(resultado, coche1.getAño()); // Action // Assert
}

@Test
void testEqualsGetPrecio() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
int resultado = 52000;
assertEquals(resultado, coche1.getPrecio()); // Action // Assert
}

@Test
void testEqualsSetPrecio() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
int resultado = 40000;
coche1.setPrecio(40000);
assertEquals(resultado, coche1.getPrecio()); // Action // Assert
}

@Test
void testEqualsString() {
Coche coche1 = new Coche ("Chevrolet", "Camaro", 2023, 52000);
String resultado = "Coche [marca=Chevrolet, modelo=Camaro, año=2023, precio=52000]";
assertEquals(resultado, coche1.toString()); // Action // Assert
}

@ParameterizedTest
@CsvSource({"Toyota, Corolla, 2020, 22000",
"Ford, Mustang, 2021, 45000",
"Chevrolet, Camaro, 2023, 22000",
"Toyota, Civic, 2022, 25000"})

void testEqualsObjectMultiple(String marca, String modelo, int año, int precio) {
Coche coche1 = new Coche("Chevrolet", "Camaro", 2023, 52000);
Coche coche2 = new Coche(marca, modelo, año, precio);
assertEquals(false, coche1.equals(coche2));
}

@ParameterizedTest
@ValueSource(strings = {"Toyota", "Ford", "Chevrolet", "Honda"})

void testGetMarca(String marca){
Coche coche1 = new Coche(marca, "-", 0, 0);
assertEquals(marca, coche1.getMarca());
}

@ParameterizedTest
@ValueSource(strings = {"Corolla", "Mustang", "Camaro", "Civic"})

void testGetModelo(String modelo){
Coche coche1 = new Coche("-", modelo, 2, 2);
assertEquals(modelo, coche1.getModelo());
}

@ParameterizedTest
@ValueSource(ints = {2022, 2021, 2023, 2022})

void testGetAño(int año){
Coche coche1 = new Coche("-", "-", año, 2);
assertEquals(año, coche1.getAño());
}

@ParameterizedTest
@ValueSource(ints = {22000, 45000, 52000, 25000})

void testGetPrecio(int precio){
Coche coche1 = new Coche("-", "-", 2, precio);
assertEquals(precio, coche1.getPrecio());
}

@ParameterizedTest
@ValueSource(strings = {"Toyota", "Ford", "Chevrolet", "Honda"})

void testSetMarca(String marca){
Coche coche1 = new Coche("-", "-", 2, 2);
coche1.setMarca(marca);
assertEquals(marca, coche1.getMarca());
}

@ParameterizedTest
@ValueSource(strings = {"Corolla", "Mustang", "Camaro", "Civic"})

void testSetModelo(String modelo){
Coche coche1 = new Coche("-", "-", 2, 2);
coche1.setModelo(modelo);
assertEquals(modelo, coche1.getModelo());
}

@ParameterizedTest
@ValueSource(ints = {2022, 2021, 2023, 2022})

void testSetAño(int año){
Coche coche1 = new Coche("-", "-", 2, 2);
coche1.setAño(año);
assertEquals(año, coche1.getAño());
}

@ParameterizedTest
@ValueSource(ints = {22000, 45000, 52000, 25000})

void testSetPrecio(int precio){
Coche coche1 = new Coche("-", "-", 2, 2);
coche1.setPrecio(precio);
assertEquals(precio, coche1.getPrecio());
}

@ParameterizedTest
@CsvSource({"Toyota, Corolla, 2022, 22000",
"Ford, Mustang, 2021, 45000",
"Chevrolet, Camaro, 2023, 52000",
"Honda, Civic, 2022, 25000"})
void testToString(String marca, String modelo, int año, int precio) {
String result = "Coche [marca=" + marca + ", modelo=" + modelo + ", año=" + año + ", precio=" + precio + "]";
Coche coche1 = new Coche(marca, modelo, año, precio);
assertEquals(result, coche1.toString());
}

}
Loading