Merge pull request #2654 from FOCONIS/file-dirty-detection

Fix: Setting file with same content should not make bean dirty
This commit is contained in:
Rob Bygrave
2022-04-19 22:30:15 +12:00
committed by GitHub
2 changed files with 60 additions and 0 deletions
@@ -12,6 +12,7 @@ import java.io.PrintStream;
import java.net.URL;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
public class TestFileType extends BaseTestCase {
@@ -184,6 +185,31 @@ public class TestFileType extends BaseTestCase {
DB.delete(bean3);
}
@Test
void test_FileDirty() throws Exception {
SomeFileBean bean0 = new SomeFileBean();
bean0.setName("afile");
bean0.setContent(file);
DB.save(bean0);
SomeFileBean bean1 = DB.find(SomeFileBean.class)
.select("name, file")
.setId(bean0.getId())
.findOne();
assertThat(bean1.getContent())
.isNotEqualTo(file) // not same file object, but same content
.hasSameBinaryContentAs(file);
assertFalse(DB.beanState(bean1).isDirty());
bean1.setContent(file);
assertFalse(DB.beanState(bean1).isDirty());
bean1.setContent(file2);
assertTrue(DB.beanState(bean1).isDirty());
}
private File getFile(String resource) {
URL url = getClass().getResource(resource);
return new File(url.getFile());