-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ValidationUtils class with custom asserts
- Loading branch information
1 parent
9074e73
commit 91d5ccd
Showing
14 changed files
with
137 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
package com.yetanalytics.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.yetanalytics.util.ValidationUtils; | ||
import com.yetanalytics.xapi.model.Account; | ||
|
||
import jakarta.validation.Validation; | ||
import jakarta.validation.Validator; | ||
|
||
public class AccountTest { | ||
private Validator validator; | ||
private Account account; | ||
|
||
@Before | ||
public void initValidator() { | ||
validator = Validation.buildDefaultValidatorFactory().getValidator(); | ||
public void init() { | ||
validator = ValidationUtils.getValidator(); | ||
account = new Account(); | ||
} | ||
|
||
@Test | ||
public void testValidAccount() { | ||
account.setHomePage("http://examplehomepage.com"); | ||
account.setName("My Account"); | ||
assertTrue(validator.validate(account).isEmpty()); | ||
ValidationUtils.assertValid(validator, account); | ||
} | ||
|
||
@Test | ||
public void testEmptyAccount() { | ||
var violations = validator.validate(account); | ||
assertEquals(2, violations.size()); | ||
ValidationUtils.assertInvalid(validator, account, 2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
package com.yetanalytics.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.yetanalytics.util.ValidationUtils; | ||
import com.yetanalytics.xapi.model.Account; | ||
import com.yetanalytics.xapi.model.Agent; | ||
|
||
import jakarta.validation.Validation; | ||
import jakarta.validation.Validator; | ||
|
||
public class AgentTest { | ||
private Validator validator; | ||
private Agent agent; | ||
|
||
@Before | ||
public void initValidator() { | ||
validator = Validation.buildDefaultValidatorFactory().getValidator(); | ||
public void init() { | ||
validator = ValidationUtils.getValidator(); | ||
agent = new Agent(); | ||
} | ||
|
||
@Test | ||
public void testMbox() { | ||
agent.setMbox("mailto:[email protected]"); | ||
assertTrue(validator.validate(agent).isEmpty()); | ||
ValidationUtils.assertValid(validator, agent); | ||
} | ||
|
||
@Test | ||
public void testMboxSha1Sum() { | ||
agent.setMbox_sha1sum("767e74eab7081c41e0b83630511139d130249666"); | ||
assertTrue(validator.validate(agent).isEmpty()); | ||
ValidationUtils.assertValid(validator, agent); | ||
} | ||
|
||
@Test | ||
public void testOpenid() { | ||
agent.setOpenid("http://openid.example.com"); | ||
assertTrue(validator.validate(agent).isEmpty()); | ||
ValidationUtils.assertValid(validator, agent); | ||
} | ||
|
||
@Test | ||
|
@@ -46,28 +44,25 @@ public void testAccount() { | |
account.setName("My Account"); | ||
|
||
agent.setAccount(account); | ||
assertTrue(validator.validate(agent).isEmpty()); | ||
ValidationUtils.assertValid(validator, agent); | ||
} | ||
|
||
@Test | ||
public void testInvalidAccount() { | ||
Account account = new Account(); | ||
agent.setAccount(account); | ||
var violations = validator.validate(agent); | ||
assertEquals(2, violations.size()); | ||
ValidationUtils.assertInvalid(validator, agent, 2); | ||
} | ||
|
||
@Test | ||
public void testNoIFI() { | ||
var violations = validator.validate(agent); | ||
assertEquals(1, violations.size()); | ||
ValidationUtils.assertInvalid(validator, agent); | ||
} | ||
|
||
@Test | ||
public void testMultiIFI() { | ||
agent.setMbox("mailto:[email protected]"); | ||
agent.setMbox_sha1sum("767e74eab7081c41e0b83630511139d130249666"); | ||
var violations = validator.validate(agent); | ||
assertEquals(1, violations.size()); | ||
ValidationUtils.assertInvalid(validator, agent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.