Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura)
Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura)
Abbiamo provato per dieci giorni la Hyundai IONIQ 5 N, con 650 CV, 770 Nm e uno 0-100 km/h in 3,4 secondi. Il suo punto forte è N e-Shift, che simula un cambio a otto rapporti con suoni da motore termico e perfino un bang supersonico
CES Unveiled Milan, l'IA diventa tecnologia fondativa e il commercio torna centrale
CES Unveiled Milan, l'IA diventa tecnologia fondativa e il commercio torna centrale
La prima tappa italiana della Road to CES porta a Milano i vertici della Consumer Technology Association, con una nuova griglia di lettura dei trend tecnologici e una posizione netta su dazi e regolamentazione dell'IA
 Recensione OPPO Find X10 Pro Max: un top di gamma completo con tre fotocamere da 200MP
Recensione OPPO Find X10 Pro Max: un top di gamma completo con tre fotocamere da 200MP
OPPO ha appena lanciato sul mercato la nuova serie Find X10, che ha come smartphone premium il Find X10 Pro Max, uno smartphone completo, che fa del comparto fotografico il suo vero punto di forza. Ma sono tante le novità, tra cui l'AI che adesso diventa agentica. Ma andiamo a vedere nel dettaglio questo nuovo smartphone.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 09-11-2011, 17:49   #1
e-commerce84
Senior Member
 
Iscritto dal: Feb 2009
Messaggi: 700
[Java] Problema con JUnit, errori vari :-( Un aiutino?

Ciao,
sono nella seguente situazione: ho una classe chiamata Addresses che contiene le informazioni relative ad un indirizzo.

Codice:
package com.sogeit.fids.model.domain;

import java.io.Serializable;
import java.util.Date;

import javax.validation.constraints.NotNull;

public class Addresses implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int addressesPk, contactFk;
	
	@NotNull(message = "may not be null")
	private String addressText;
	
	private String addressNumber, city, countryCode2, districtCode, zipCode, latitude, longitude;
	private boolean isPrimary;
	private Date creationDate, lastUpdate;
	
	private int createdBy;
	private int modifiedBy;
	
	public Addresses(int addressesPk, int contactFk){
		this.addressesPk = addressesPk;
		this.contactFk = contactFk;
	}

	// GETTER PK E FK:
	public int getAddressesPk() {
		return addressesPk;
	}

	public int getContactFk() {
		return contactFk;
	}

	// GETTER E SETTER:
	public String getAddressText() {
		return addressText;
	}

	public void setAddressText(String addressText) {
		this.addressText = addressText;
	}

	public String getAddressNumber() {
		return addressNumber;
	}

	public void setAddressNumber(String addressNumber) {
		this.addressNumber = addressNumber;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCountryCode2() {
		return countryCode2;
	}

	public void setCountryCode2(String countryCode2) {
		this.countryCode2 = countryCode2;
	}

	public String getDistrictCode() {
		return districtCode;
	}

	public void setDistrictCode(String districtCode) {
		this.districtCode = districtCode;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public boolean getIsPrimary() {
		return isPrimary;
	}

	public void setIsPrimary(boolean isPrimary) {
		this.isPrimary = isPrimary;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public int getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(int createdBy) {
		this.createdBy = createdBy;
	}

	public int getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(int modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Addresses [addressesPk=" + addressesPk + ", contactFk="
				+ contactFk + ", addressText=" + addressText
				+ ", addressNumber=" + addressNumber + ", city=" + city
				+ ", countryCode2=" + countryCode2 + ", districtCode="
				+ districtCode + ", zipCode=" + zipCode + ", latitude="
				+ latitude + ", longitude=" + longitude + ", isPrimary="
				+ isPrimary + ", creationDate=" + creationDate
				+ ", lastUpdate=" + lastUpdate + ", createdBy=" + createdBy
				+ ", modifiedBy=" + modifiedBy + "]";
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((addressNumber == null) ? 0 : addressNumber.hashCode());
		result = prime * result
				+ ((addressText == null) ? 0 : addressText.hashCode());
		result = prime * result + addressesPk;
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + contactFk;
		result = prime * result
				+ ((countryCode2 == null) ? 0 : countryCode2.hashCode());
		result = prime * result + createdBy;
		result = prime * result
				+ ((creationDate == null) ? 0 : creationDate.hashCode());
		result = prime * result
				+ ((districtCode == null) ? 0 : districtCode.hashCode());
		result = prime * result + (isPrimary ? 1231 : 1237);
		result = prime * result
				+ ((lastUpdate == null) ? 0 : lastUpdate.hashCode());
		result = prime * result
				+ ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result
				+ ((longitude == null) ? 0 : longitude.hashCode());
		result = prime * result + modifiedBy;
		result = prime * result + ((zipCode == null) ? 0 : zipCode.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Addresses))
			return false;
		Addresses other = (Addresses) obj;
		if (addressNumber == null) {
			if (other.addressNumber != null)
				return false;
		} else if (!addressNumber.equals(other.addressNumber))
			return false;
		if (addressText == null) {
			if (other.addressText != null)
				return false;
		} else if (!addressText.equals(other.addressText))
			return false;
		if (addressesPk != other.addressesPk)
			return false;
		if (city == null) {
			if (other.city != null)
				return false;
		} else if (!city.equals(other.city))
			return false;
		if (contactFk != other.contactFk)
			return false;
		if (countryCode2 == null) {
			if (other.countryCode2 != null)
				return false;
		} else if (!countryCode2.equals(other.countryCode2))
			return false;
		if (createdBy != other.createdBy)
			return false;
		if (creationDate == null) {
			if (other.creationDate != null)
				return false;
		} else if (!creationDate.equals(other.creationDate))
			return false;
		if (districtCode == null) {
			if (other.districtCode != null)
				return false;
		} else if (!districtCode.equals(other.districtCode))
			return false;
		if (isPrimary != other.isPrimary)
			return false;
		if (lastUpdate == null) {
			if (other.lastUpdate != null)
				return false;
		} else if (!lastUpdate.equals(other.lastUpdate))
			return false;
		if (latitude == null) {
			if (other.latitude != null)
				return false;
		} else if (!latitude.equals(other.latitude))
			return false;
		if (longitude == null) {
			if (other.longitude != null)
				return false;
		} else if (!longitude.equals(other.longitude))
			return false;
		if (modifiedBy != other.modifiedBy)
			return false;
		if (zipCode == null) {
			if (other.zipCode != null)
				return false;
		} else if (!zipCode.equals(other.zipCode))
			return false;
		return true;
	}
	

}
Come potete notare tale bean contiene l'annotation @NotNull per il campo addressesText che stà ad indicare che quel campo NON PUO' ESSERE NULLO (annotation per la validazione dei bean: http://docs.jboss.org/hibernate/vali...ngstarted.html )

Poi nella cartella src/test/java ho un package che contiene il seguente test di JUnit:

Codice:
package com.sogeit.fids.model.domain;

import com.sogeit.fids.model.domain.Addresses;
import static org.junit.Assert.*;
 

import java.util.Date;

import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import org.junit.BeforeClass;
import org.junit.Test;

public class TestAddresses {
	
	private static Validator validator;

	
	@Test
	public void test() {
		
		Addresses indirizzo1 = new Addresses(1, 2);
		Addresses indirizzo2 = new Addresses(1, 2);
		
		Date data = new Date(2011, 11, 4);
		
		// indirizzo1:
				indirizzo1.setAddressNumber("Indirizzo");
				indirizzo1.setAddressText("Testo");
				indirizzo1.setCity("Roma");
				indirizzo1.setCountryCode2("countrycode");
				indirizzo1.setCreatedBy(5);
				indirizzo1.setCreationDate(data);
				indirizzo1.setDistrictCode("districtCode");
				indirizzo1.setLastUpdate(data);
				indirizzo1.setLatitude("33");
				indirizzo1.setLongitude("21");
				indirizzo1.setModifiedBy(6);
				indirizzo1.setIsPrimary(true);
				indirizzo1.setZipCode("00100");
				
				// indirizzo2 (uguale ad indirizzo1)
				indirizzo2.setAddressNumber("Indirizzo");
				indirizzo2.setAddressText("Testo");
				indirizzo2.setCity("Roma");
				indirizzo2.setCountryCode2("countrycode");
				indirizzo2.setCreatedBy(5);
				indirizzo2.setCreationDate(data);
				indirizzo2.setDistrictCode("districtCode");
				indirizzo2.setLastUpdate(data);
				indirizzo2.setLatitude("33");
				indirizzo2.setLongitude("21");
				indirizzo2.setModifiedBy(6);
				indirizzo2.setIsPrimary(true);
				indirizzo2.setZipCode("00100");
		
				assertEquals( indirizzo1.hashCode(), indirizzo2.hashCode());
	}
	
	
	@BeforeClass
	public static void setUp() {
		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
		validator = factory.getValidator();
	}
	
	@Test
	public void addressTextIsNull(){
		Addresses indirizzo = new Addresses(5, 10);
		
		Date data = new Date(2011, 11, 4);
		
		// indirizzo1:
		indirizzo.setAddressNumber("Indirizzo");
		indirizzo.setAddressText("Testo");
		indirizzo.setCity("Roma");
		indirizzo.setCountryCode2("countrycode");
		indirizzo.setCreatedBy(5);
		indirizzo.setCreationDate(data);
		indirizzo.setDistrictCode("districtCode");
		indirizzo.setLastUpdate(data);
		indirizzo.setLatitude("33");
		indirizzo.setLongitude("21");
		indirizzo.setModifiedBy(6);
		indirizzo.setIsPrimary(true);
		indirizzo.setZipCode("00100");
		
		Set<ConstraintViolation<Addresses>> constraintViolations = validator.validate(indirizzo);
		
		assertEquals( 1, constraintViolations.size() );
		assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() );
	}
	
}
Tale classe contiene 2 metodi annotati con l'annotation @Test che rappresentano 2 test di JUnit

Se lascio solo il primo test (commentando tutto ciò che non è il metodo chiamato test() ) funziona perfettamente e JUnit mi avverte che il test è stato superato con la classica barra verde

Se aggiungo anche i 2 metodi: setUp() e addressTextIsNull() (lo unit test vero e proprio che dovrebbe testare la validazione del bean relativamente al valore del campo addressText dell'oggetto indirizzo) quando dentro Eclipse faccio Run As JUnit Test NON FUNZIONA...

Non mi appare ne la barra verde che dice che il test è stato passato, ne la barra rossa che dice che il test non è stato passato ma mi viene dato il seguente messaggio di errore:

Codice:
TestAddresses
com.sogeit.fids.model.domain.TestAddresses
javax.validation.ValidationException: Unable to find a default provider

	at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)

	at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)

	at com.sogeit.fids.model.domain.TestAddresses.setUp(TestAddresses.java:67)

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

	at java.lang.reflect.Method.invoke(Method.java:597)

	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Come mai? Da cosa potrebbe dipendere? Come risolvere?

Grazie mille
Andrea
e-commerce84 è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura) Hyundai IONIQ 5 N, l'elettrica che finge di esse...
CES Unveiled Milan, l'IA diventa tecnologia fondativa e il commercio torna centrale CES Unveiled Milan, l'IA diventa tecnologia fond...
 Recensione OPPO Find X10 Pro Max: un top di gamma completo con tre fotocamere da 200MP Recensione OPPO Find X10 Pro Max: un top di gam...
WoW Forever provato: il MMORPG che la community chiedeva da anni è arrivato WoW Forever provato: il MMORPG che la community ...
TCL P80 Ultra: con un display AMOLED opaco è una gioia per gli occhi e per le dita TCL P80 Ultra: con un display AMOLED opaco &egra...
Musk mette sul piatto 40 miliardi per le...
Apple Watch in offerta su Amazon: Ultra ...
Lavapavimenti senza fili in offerta su A...
Pieghevoli da record in Europa per Samsu...
Corsair RM1200e: arriva l'alimentatore d...
Apple porta l'IA su iWork: debutta l'Int...
Codec AV2: YouTube fissa al 2027 il pass...
Modder sbloccano i Tensor Core delle GeF...
AI, per la maggior parte delle aziende U...
Dopo le GPU, NVIDIA punta sugli abboname...
Samsung Galaxy e Android 17: la lista uf...
SanDisk Extreme da 256GB a 59€ su Amazon...
Made for iPhone Duo: ecco come riconosce...
GPU vietate in Cina: NVIDIA B300 compare...
NVIDIA RTX Remix 1.6 porta il DLSS 5 Neu...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 09:24.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v