task: MVVM design pattern using zkoss framework. (#1678)
* MVVM design pattern using zkoss framework. * MVVM Design pattern updates for issues reported by SonarCloud. * MVVM Design pattern updates for coverage issues reported by SonarCloud. * MVVM Design pattern updates for coverage issues (removing lombok @Data) reported by SonarCloud. * MVVM Design pattern updates for coverage issues reported by Sonar - TEST cases added for Equals and ToString * MVVM Design Pattern - updating missing/todo details. * MVVM Design Pattern - adding lombok.config * MVVM Design Pattern - Removing xml, updating pom.xml and README as per suggested changes in code review * Update model-view-viewmodel/README.md * Update model-view-viewmodel/README.md * Update model-view-viewmodel/README.md * Update model-view-viewmodel/README.md * MVVM Design Pattern - Updated pom.xml and Readme based on Suggested changes * added type as xml * MVVM Design Patterm - root pom.xml and module pom.xml updated * Update pom.xml Co-authored-by: Subhrodip Mohanta <hello@subho.xyz> Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2021 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.model.view.viewmodel;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.google.common.testing.EqualsTester;
|
||||
|
||||
class BookTest {
|
||||
|
||||
BookViewModel bvm;
|
||||
Book testBook;
|
||||
List<Book> testBookList;
|
||||
Book testBookTwo;
|
||||
Book testBookThree;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bvm = new BookViewModel();
|
||||
testBook = new Book("Head First Design Patterns: A Brain-Friendly Guide",
|
||||
"Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson",
|
||||
"Head First Design Patterns Description");
|
||||
testBookList = bvm.getBookList();
|
||||
testBookTwo = new Book("Head First Design Patterns: A Brain-Friendly Guide",
|
||||
"Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson",
|
||||
"Head First Design Patterns Description");
|
||||
testBookThree = new Book("Design Patterns: Elements of Reusable Object-Oriented Software",
|
||||
"Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides",
|
||||
"Design Patterns Description");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBookModel() {
|
||||
assertNotNull(testBook);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
new EqualsTester().addEqualityGroup(testBook, testBookTwo).testEquals();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
assertThat(testBook.toString(), is(testBookTwo.toString()));
|
||||
assertThat(testBook.toString(), is(not(testBookThree.toString())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHashCode() {
|
||||
assertTrue(testBook.equals(testBookTwo) && testBookTwo.equals(testBook));
|
||||
assertEquals(testBook.hashCode(), testBookTwo.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoadData() {
|
||||
assertNotNull(testBookList);
|
||||
assertTrue(testBookList.get(0).toString().contains("Head First Design Patterns"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSelectedData() {
|
||||
bvm.setSelectedBook(testBook);
|
||||
assertNotNull(bvm.getSelectedBook());
|
||||
assertEquals(testBook.toString(), bvm.getSelectedBook().toString());
|
||||
assertTrue(true, bvm.getSelectedBook().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteData() {
|
||||
bvm.setSelectedBook(testBook);
|
||||
assertNotNull(bvm.getSelectedBook());
|
||||
assertTrue(testBookList.get(0).toString().contains("Head First Design Patterns"));
|
||||
bvm.deleteBook();
|
||||
assertNull(bvm.getSelectedBook());
|
||||
assertFalse(testBookList.get(0).toString().contains("Head First Design Patterns"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user