Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CydeWeys committed Oct 7, 2019
1 parent e8c53b4 commit 377295d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/google/registry/schema/tld/PremiumList.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@
@Entity
@Table(
name = "PremiumList",
indexes = {@Index(columnList = "name", name = "name_idx")})
indexes = {@Index(columnList = "name", name = "premiumlist_name_idx")})
public class PremiumList {

@Column(name = "name", nullable = false)
@Column(nullable = false)
private String name;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "revision_id", nullable = false)
@Column(nullable = false)
private Long revisionId;

@Column(name = "creation_timestamp", nullable = false)
@Column(nullable = false)
private CreateAutoTimestamp creationTimestamp = CreateAutoTimestamp.create(null);

@Column(name = "currency", nullable = false)
@Column(nullable = false)
private CurrencyUnit currency;

@ElementCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public static void saveNew(PremiumList premiumList) {
*/
public static boolean checkExists(String premiumListName) {
return jpaTm()
.getEntityManager()
.createQuery("SELECT 1 FROM PremiumList WHERE name = :name", Long.class)
.setParameter("name", premiumListName)
.getSingleResult()
> 0;
.transact(
() ->
jpaTm()
.getEntityManager()
.createQuery("SELECT 1 FROM PremiumList WHERE name = :name", Long.class)
.setParameter("name", premiumListName)
.getSingleResult()
> 0);
}

private PremiumListDao() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.JUnitBackports.assertThrows;

import com.google.common.collect.ImmutableMap;
import google.registry.model.transaction.JpaTransactionManagerRule;
Expand Down Expand Up @@ -60,6 +61,18 @@ public void saveNew_worksSuccessfully() {
assertThat(persistedList.getCreationTimestamp()).isGreaterThan(beforeTest);
}

@Test
public void saveNew_throwsWhenPremiumListAlreadyExists() {
PremiumListDao.saveNew(PremiumList.create("testlist", CurrencyUnit.USD, TEST_PRICES));
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() ->
PremiumListDao.saveNew(
PremiumList.create("testlist", CurrencyUnit.USD, TEST_PRICES)));
assertThat(thrown).hasMessageThat().contains("A premium list of this name already exists");
}

@Test
public void checkExists_worksSuccessfully() {
assertThat(PremiumListDao.checkExists("testlist")).isFalse();
Expand Down

0 comments on commit 377295d

Please sign in to comment.