From e3f2e1ea27e938aeb18c0e77c6069a3959c87639 Mon Sep 17 00:00:00 2001
From: Javier Calvo <javiercalvoporro@gmail.com>
Date: Sat, 9 Nov 2024 11:52:29 +0100
Subject: [PATCH] Puerto ya esta con los nullException y PuertoTest realizado
 al 100%

---
 src/es/markse/Puerto.java      |  8 +++++
 uses/es/markse/PuertoTest.java | 55 +++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/src/es/markse/Puerto.java b/src/es/markse/Puerto.java
index 6372f98..406121f 100644
--- a/src/es/markse/Puerto.java
+++ b/src/es/markse/Puerto.java
@@ -37,6 +37,9 @@ public class Puerto {
 	 * @param ciudad Ciudad del puerto(3 letras)
 	 */
 	private void comprobarIdentificador(String pais, String ciudad) {
+		if (pais == null || ciudad == null) {
+			throw new IllegalArgumentException("El pais o la ciudad no pueden ser nulos");
+		}
 		if (!(pais.matches("[A-Za-z]{2}") && ciudad.matches("[A-Za-z]{3}"))) {
 		    throw new IllegalArgumentException("Formato incorrecto. Debe ser en el formato 'XX-XXX', donde XX es el país y XXX es la ciudad, usando solo letras.");
 		}
@@ -48,6 +51,7 @@ public class Puerto {
 	 * @param m objeto tipo Muelle
 	 */
 	public boolean anyadirMuelle(Muelle m) {
+		if (m == null) throw new IllegalArgumentException("Muelle no puede ser nulo");
 		if (!this.comprobarMuelleEnPuerto(m)) {
 			return this.muelles.add(m);
 		}
@@ -59,6 +63,7 @@ public class Puerto {
 	 * @param id : Identificador del muelle que se elimina
 	 */
 	public boolean eliminarMuelle(String id) {
+		if (id == null) throw new IllegalArgumentException("Identificador no puede ser nulo");
 		return this.muelles.removeIf(muelle -> muelle.getIdentificador().equals(id));
 	}
 	
@@ -127,6 +132,7 @@ public class Puerto {
 	 * @return Lista con los muelles mas cercanos a ese punto gps dado
 	 */
 	public Muelle[] muellesCercanoAPunto(GPSCoordinate puntoDado) {
+		if (puntoDado == null) throw new IllegalArgumentException("El Punto no puede ser nulo");
 	    List<Muelle> cercanos = new ArrayList<>();
 	    //Inicializamos la distanciaMinima con el valor mas alto posible (la primera distancia sera siempre mas corta)
 	    double distanciaMinima = Double.MAX_VALUE;
@@ -157,6 +163,8 @@ public class Puerto {
 	 */
 	
 	public void colocarContenedorEnMuelle(Muelle m, Contenedor c, int plaza) {
+		if (m == null) throw new IllegalArgumentException("El Muelle no puede ser nulo");
+		if (c == null) throw new IllegalArgumentException("El Contenedor no puede ser nulo");
 	    // Verificar si el muelle m está en la lista de muelles del puerto
 	    if (!this.muelles.contains(m)) {
 	        throw new IllegalArgumentException("El muelle no está en el puerto.");
diff --git a/uses/es/markse/PuertoTest.java b/uses/es/markse/PuertoTest.java
index 1c41515..0109de9 100644
--- a/uses/es/markse/PuertoTest.java
+++ b/uses/es/markse/PuertoTest.java
@@ -20,7 +20,22 @@ public class PuertoTest {
 		assertEquals("ES", p.paisDelPuerto());
         assertEquals("BAR", p.ciudadDelPuerto());
 	}
-
+	
+	@Test(expected = IllegalArgumentException.class)
+	public void testCreacionPuertoPaisNulo() {
+	    new Puerto(null, "BAR");
+	}
+	
+	@Test(expected = IllegalArgumentException.class)
+	public void testCreacionPuertoCiudadNulo() {
+	    new Puerto("AG", null);
+	}
+	
+	@Test(expected = IllegalArgumentException.class)
+	public void testCreacionPuertoNulo() {
+	    new Puerto(null, null);
+	}
+	
 	@Test(expected = IllegalArgumentException.class)
 	public void testCreacionPuertoCiudadInvalida() {
 	    new Puerto("ES", "455");
@@ -44,6 +59,13 @@ public class PuertoTest {
 		assertTrue(p.anyadirMuelle(m));
 	}
 	
+	@Test(expected = IllegalArgumentException.class)
+	public void testAnyadirMuelleNulo() {
+		Puerto p = new Puerto("ES","BAR");
+		assertTrue(p.anyadirMuelle(null));
+	}
+	
+	
 	@Test
 	public void testAnyadirMuelleRepetido() {
 		Puerto p = new Puerto("ES","BAR");
@@ -66,6 +88,15 @@ public class PuertoTest {
 		assertTrue(p.eliminarMuelle("03"));
 	}
 	
+	@Test(expected = IllegalArgumentException.class)
+	public void testEliminarMuelleNulo() {
+		Puerto p = new Puerto("ES","BAR");
+		GPSCoordinate cord = new GPSCoordinate(5d, 10d);
+		Muelle m = new Muelle("03", cord, true, 40, 5);
+		p.anyadirMuelle(m);
+		p.eliminarMuelle(null);
+	}
+	
 	@Test
 	public void testEliminarMuelleQueNoEstaEnPuerto() {
 		Puerto p = new Puerto("ES","BAR");
@@ -154,6 +185,12 @@ public class PuertoTest {
 		assertArrayEquals(muellesCercanos, p.muellesCercanoAPunto(puntoDado));
 	}
 	
+	@Test(expected = IllegalArgumentException.class)
+	public void testMuellesCercanoAPuntoVacio() {
+		Puerto p = new Puerto("ES","BAR");
+		p.muellesCercanoAPunto(null);
+	}
+	
 	@Test
 	public void testColocarContenedorEnMuelle() {
 		Puerto p = new Puerto("ES","BAR");
@@ -167,6 +204,22 @@ public class PuertoTest {
 		assertEquals(0, m1.plazasSemillenas());
 	}
 	
+	@Test(expected = IllegalArgumentException.class)
+	public void testColocarContenedorEnMuelleMuelleVacio() {
+		Puerto p = new Puerto("ES","BAR");
+		Contenedor c11 = new Contenedor("ZRE", 'J', "056731", 100, 400, 500, false, true);
+		p.colocarContenedorEnMuelle(null, c11, 0);
+	}
+	
+	@Test(expected = IllegalArgumentException.class)
+	public void testColocarContenedorEnMuelleContenedorVacio() {
+		Puerto p = new Puerto("ES","BAR");
+		GPSCoordinate cord1 = new GPSCoordinate(10d, 10d);
+		Muelle m1 = new Muelle("01", cord1, true, 1, 1);
+		p.anyadirMuelle(m1);
+		p.colocarContenedorEnMuelle(m1, null, 0);
+	}
+	
 	@Test(expected = IllegalArgumentException.class)
 	public void testColocarContenedorEnMuelleQueNoEstaEnPuerto() {
 		Puerto p = new Puerto("ES","BAR");
-- 
GitLab