This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-27 10:34:48 +02:00
parent a2470d132d
commit ec93ff22cc
7 changed files with 26 additions and 7 deletions

View file

@ -37,6 +37,7 @@ dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.3'
testImplementation 'org.springframework.security:spring-security-test' testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'com.h2database:h2:1.4.200' testImplementation 'com.h2database:h2:1.4.200'
// Fixes https://stackoverflow.com/a/60455550 // Fixes https://stackoverflow.com/a/60455550

View file

@ -9,7 +9,7 @@ import lombok.NonNull;
@Data @Data
@Entity @Entity
public class ConfirmationToken { public final class ConfirmationToken {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@ -55,7 +55,6 @@ public class ConfirmationToken {
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ConfirmationToken that = (ConfirmationToken) o; ConfirmationToken that = (ConfirmationToken) o;
return resetPassword == that.resetPassword return resetPassword == that.resetPassword
&& Objects.equals(id, that.id)
&& confirmToken.equals(that.confirmToken) && confirmToken.equals(that.confirmToken)
&& createdDate.equals(that.createdDate) && createdDate.equals(that.createdDate)
&& Objects.equals(user, that.user); && Objects.equals(user, that.user);
@ -63,6 +62,6 @@ public class ConfirmationToken {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, confirmToken, createdDate, user, resetPassword); return Objects.hash(confirmToken, createdDate, user, resetPassword);
} }
} }

View file

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.persistence.*; import javax.persistence.*;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@ -56,6 +57,7 @@ public class User {
@GsonExclude @GsonExclude
@Getter @Getter
@ToString.Exclude @ToString.Exclude
@EqualsAndHashCode.Exclude
private Set<User> guests = new HashSet<>(); private Set<User> guests = new HashSet<>();
@ManyToMany(cascade = CascadeType.DETACH) @ManyToMany(cascade = CascadeType.DETACH)
@ -66,6 +68,7 @@ public class User {
@GsonExclude @GsonExclude
@Getter @Getter
@ToString.Exclude @ToString.Exclude
@EqualsAndHashCode.Exclude
private Set<User> hosts = new HashSet<>(); private Set<User> hosts = new HashSet<>();
/** Determines whether a guest can access security cameras */ /** Determines whether a guest can access security cameras */

View file

@ -58,7 +58,7 @@ public class RegularLightControllerTests {
@Test @Test
public void testGetAll() { public void testGetAll() {
when(regularLightRepository.findAll()).thenReturn(List.of()); when(regularLightRepository.findAll()).thenReturn(List.of());
assertThat(regularLightController.findAll().isEmpty()); assertThat(regularLightController.findAll()).isEmpty();
} }
@Test @Test

View file

@ -171,6 +171,6 @@ public class RoomControllerTests {
public void testGetDevices() throws NotFoundException { public void testGetDevices() throws NotFoundException {
when(mockPrincipal.getName()).thenReturn("user"); when(mockPrincipal.getName()).thenReturn("user");
when(deviceService.findAll(2020L, 10L, "user")).thenReturn(List.of()); when(deviceService.findAll(2020L, 10L, "user")).thenReturn(List.of());
assertThat(roomController.getDevices(2020L, mockPrincipal, 10L)); assertThat(roomController.getDevices(2020L, mockPrincipal, 10L)).isNotNull();
} }
} }

View file

@ -3,6 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Date; import java.util.Date;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -66,7 +67,7 @@ public class ConfirmationTokenTests {
public void equals() { public void equals() {
User user = new User(); User user = new User();
user.setName("Tizio Sempronio"); user.setName("Tizio Sempronio");
user.setId(42l); user.setId(42L);
user.setUsername("xXCoolUserNameXx"); user.setUsername("xXCoolUserNameXx");
user.setEmail("realMail@service.ext"); user.setEmail("realMail@service.ext");
user.setPassword("alpaca"); user.setPassword("alpaca");
@ -75,4 +76,18 @@ public class ConfirmationTokenTests {
assertNotEquals(t, token); assertNotEquals(t, token);
} }
@Test
public void testEqualsHashCode() {
final User u = new User();
u.setId(1L);
final User t = new User();
t.setId(2L);
EqualsVerifier.forClass(ConfirmationToken.class)
.withNonnullFields("createdDate")
.withNonnullFields("confirmToken")
.withPrefabValues(User.class, u, t)
.verify();
assertDoesNotThrow(() -> new ConfirmationToken().hashCode());
}
} }

View file

@ -1,5 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.service; package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
@ -38,6 +39,6 @@ public class DevicePopulationServiceTests {
list.add(t1); list.add(t1);
list.add(light2); list.add(light2);
doNothing().when(populationService).populateMeasuredTemperature(t1); doNothing().when(populationService).populateMeasuredTemperature(t1);
service.populateComputedFields(list); assertDoesNotThrow(() -> service.populateComputedFields(list));
} }
} }