Merge branch 'tests' into 'dev'
Tests See merge request sa4-2020/the-sanmarinoes/backend!200
This commit is contained in:
commit
c7de5ca437
7 changed files with 26 additions and 7 deletions
|
@ -37,6 +37,7 @@ dependencies {
|
|||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.3'
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
testImplementation 'com.h2database:h2:1.4.200'
|
||||
// Fixes https://stackoverflow.com/a/60455550
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.NonNull;
|
|||
|
||||
@Data
|
||||
@Entity
|
||||
public class ConfirmationToken {
|
||||
public final class ConfirmationToken {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
|
@ -55,7 +55,6 @@ public class ConfirmationToken {
|
|||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ConfirmationToken that = (ConfirmationToken) o;
|
||||
return resetPassword == that.resetPassword
|
||||
&& Objects.equals(id, that.id)
|
||||
&& confirmToken.equals(that.confirmToken)
|
||||
&& createdDate.equals(that.createdDate)
|
||||
&& Objects.equals(user, that.user);
|
||||
|
@ -63,6 +62,6 @@ public class ConfirmationToken {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, confirmToken, createdDate, user, resetPassword);
|
||||
return Objects.hash(confirmToken, createdDate, user, resetPassword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.HashSet;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import javax.persistence.*;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
@ -56,6 +57,7 @@ public class User {
|
|||
@GsonExclude
|
||||
@Getter
|
||||
@ToString.Exclude
|
||||
@EqualsAndHashCode.Exclude
|
||||
private Set<User> guests = new HashSet<>();
|
||||
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
|
@ -66,6 +68,7 @@ public class User {
|
|||
@GsonExclude
|
||||
@Getter
|
||||
@ToString.Exclude
|
||||
@EqualsAndHashCode.Exclude
|
||||
private Set<User> hosts = new HashSet<>();
|
||||
|
||||
/** Determines whether a guest can access security cameras */
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RegularLightControllerTests {
|
|||
@Test
|
||||
public void testGetAll() {
|
||||
when(regularLightRepository.findAll()).thenReturn(List.of());
|
||||
assertThat(regularLightController.findAll().isEmpty());
|
||||
assertThat(regularLightController.findAll()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -171,6 +171,6 @@ public class RoomControllerTests {
|
|||
public void testGetDevices() throws NotFoundException {
|
||||
when(mockPrincipal.getName()).thenReturn("user");
|
||||
when(deviceService.findAll(2020L, 10L, "user")).thenReturn(List.of());
|
||||
assertThat(roomController.getDevices(2020L, mockPrincipal, 10L));
|
||||
assertThat(roomController.getDevices(2020L, mockPrincipal, 10L)).isNotNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Date;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -66,7 +67,7 @@ public class ConfirmationTokenTests {
|
|||
public void equals() {
|
||||
User user = new User();
|
||||
user.setName("Tizio Sempronio");
|
||||
user.setId(42l);
|
||||
user.setId(42L);
|
||||
user.setUsername("xXCoolUserNameXx");
|
||||
user.setEmail("realMail@service.ext");
|
||||
user.setPassword("alpaca");
|
||||
|
@ -75,4 +76,18 @@ public class ConfirmationTokenTests {
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
|
||||
|
@ -38,6 +39,6 @@ public class DevicePopulationServiceTests {
|
|||
list.add(t1);
|
||||
list.add(light2);
|
||||
doNothing().when(populationService).populateMeasuredTemperature(t1);
|
||||
service.populateComputedFields(list);
|
||||
assertDoesNotThrow(() -> service.populateComputedFields(list));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue