Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonathanvila/4e1022d9b37f950129e3ed8e6797b596 to your computer and use it in GitHub Desktop.
Save jonathanvila/4e1022d9b37f950129e3ed8e6797b596 to your computer and use it in GitHub Desktop.
CREATE TABLE specialties (
id IDENTITY PRIMARY KEY,
name VARCHAR(80)
);
// file Specialty.java
@Entity
@Table(name = "specialties")
public class Specialty extends NamedEntity {
}
// file namedentity.java
@MappedSuperclass
public class NamedEntity extends BaseEntity {
@Column(name = "name")
@NotEmpty
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return this.getName();
}
}
// file BaseEntity
@MappedSuperclass
public class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@JsonIgnore
public boolean isNew() {
return this.id == null;
}
}
// file ClinicServiceTests
@Test
@Transactional
public void shouldInsertSpecialty() {
Collection<Specialty> specialties = this.clinicService.findAllSpecialties();
int found = specialties.size();
Specialty specialty = new Specialty();
specialty.setName("dermatologista");
this.clinicService.saveSpecialty(specialty);
assertThat(specialty.getId().longValue()).isNotEqualTo(0);
specialties = this.clinicService.findAllSpecialties();
assertThat(specialties.size()).isEqualTo(found + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment