@date 2019年4月30日上午09:58:02 @desc Update测试类
| 14 | * @desc Update测试类 |
| 15 | */ |
| 16 | public class UpdateTest { |
| 17 | private static final Logger logger = LogManager.getLogger(UpdateTest.class); |
| 18 | |
| 19 | private String table; |
| 20 | private String column1; |
| 21 | private String column2; |
| 22 | private String column3; |
| 23 | private String value1; |
| 24 | private String value2; |
| 25 | private String simpleSql; |
| 26 | |
| 27 | @Before |
| 28 | public void before() { |
| 29 | // TODO Auto-generated method stub |
| 30 | table = "table"; |
| 31 | column1 = "column1"; |
| 32 | column2 = "column2"; |
| 33 | column3 = "column3"; |
| 34 | value1 = "1"; |
| 35 | value2 = "2"; |
| 36 | simpleSql = "update " + table + " set pk = 1"; |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void testParse() { |
| 41 | try { |
| 42 | Update update = Update.parse(simpleSql); |
| 43 | Assert.assertEquals( |
| 44 | SqlFormatter.format(update.getSql()), |
| 45 | SqlFormatter.format("UPDATE table SET pk = 1 WHERE 1 = 2") |
| 46 | ); |
| 47 | Assert.assertEquals( |
| 48 | SqlFormatter.format(update.getSql(false)), |
| 49 | SqlFormatter.format("UPDATE table SET pk = 1") |
| 50 | ); |
| 51 | } catch (Exception e) { |
| 52 | Assert.fail(e.getMessage()); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @desc 最简单的更新 |
| 58 | */ |
| 59 | @Test |
| 60 | public void testSimpleUpdate() { |
| 61 | try { |
| 62 | Update update = Update.parse(simpleSql); |
| 63 | update.addColumn(new UpdateItem(column1, value1)); |
| 64 | Assert.assertEquals( |
| 65 | SqlFormatter.format(update.getSql()), |
| 66 | SqlFormatter.format("UPDATE table SET pk = 1, column1 = 1 WHERE 1 = 2") |
| 67 | ); |
| 68 | Assert.assertEquals( |
| 69 | SqlFormatter.format(update.getSql(false)), |
| 70 | SqlFormatter.format("UPDATE table SET pk = 1, column1 = 1") |
| 71 | ); |
| 72 | } catch (Exception e) { |
| 73 | Assert.fail(e.getMessage()); |
nothing calls this directly
no outgoing calls
no test coverage detected