Pārlūkot izejas kodu

createaccounttest

Seth 6 gadus atpakaļ
vecāks
revīzija
ffd90ea0aa

+ 65
- 50
.idea/workspace.xml Parādīt failu

4
     <list default="true" id="b71a0d05-772d-4338-8f47-61b6a36d5d57" name="Default Changelist" comment="">
4
     <list default="true" id="b71a0d05-772d-4338-8f47-61b6a36d5d57" name="Default Changelist" comment="">
5
       <change beforePath="$PROJECT_DIR$/src/main/java/AccountApp.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
5
       <change beforePath="$PROJECT_DIR$/src/main/java/AccountApp.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
6
       <change beforePath="$PROJECT_DIR$/src/main/java/AccountServ.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountServ.java" afterDir="false" />
6
       <change beforePath="$PROJECT_DIR$/src/main/java/AccountServ.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountServ.java" afterDir="false" />
7
-      <change beforePath="$PROJECT_DIR$/src/main/java/Console.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Console.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/src/test/java/AccountServTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/AccountServTest.java" afterDir="false" />
8
     </list>
8
     </list>
9
     <ignored path="$PROJECT_DIR$/target/" />
9
     <ignored path="$PROJECT_DIR$/target/" />
10
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
10
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
45
       </usages-collector>
45
       </usages-collector>
46
       <usages-collector id="statistics.file.extensions.edit">
46
       <usages-collector id="statistics.file.extensions.edit">
47
         <counts>
47
         <counts>
48
-          <entry key="java" value="1425" />
48
+          <entry key="java" value="2021" />
49
         </counts>
49
         </counts>
50
       </usages-collector>
50
       </usages-collector>
51
       <usages-collector id="statistics.file.types.edit">
51
       <usages-collector id="statistics.file.types.edit">
52
         <counts>
52
         <counts>
53
-          <entry key="JAVA" value="1425" />
53
+          <entry key="JAVA" value="2021" />
54
         </counts>
54
         </counts>
55
       </usages-collector>
55
       </usages-collector>
56
     </session>
56
     </session>
69
       <file pinned="false" current-in-tab="false">
69
       <file pinned="false" current-in-tab="false">
70
         <entry file="file://$PROJECT_DIR$/src/test/java/MockDao.java">
70
         <entry file="file://$PROJECT_DIR$/src/test/java/MockDao.java">
71
           <provider selected="true" editor-type-id="text-editor">
71
           <provider selected="true" editor-type-id="text-editor">
72
-            <state relative-caret-position="-1666">
72
+            <state relative-caret-position="516">
73
               <caret line="37" column="12" selection-start-line="37" selection-start-column="10" selection-end-line="37" selection-end-column="12" />
73
               <caret line="37" column="12" selection-start-line="37" selection-start-column="10" selection-end-line="37" selection-end-column="12" />
74
               <folding>
74
               <folding>
75
                 <element signature="imports" expanded="true" />
75
                 <element signature="imports" expanded="true" />
84
           </provider>
84
           </provider>
85
         </entry>
85
         </entry>
86
       </file>
86
       </file>
87
-      <file pinned="false" current-in-tab="false">
87
+      <file pinned="false" current-in-tab="true">
88
         <entry file="file://$PROJECT_DIR$/src/test/java/AccountServTest.java">
88
         <entry file="file://$PROJECT_DIR$/src/test/java/AccountServTest.java">
89
           <provider selected="true" editor-type-id="text-editor">
89
           <provider selected="true" editor-type-id="text-editor">
90
-            <state relative-caret-position="480">
91
-              <caret line="35" selection-start-line="35" selection-end-line="35" />
90
+            <state relative-caret-position="285">
91
+              <caret line="25" column="5" lean-forward="true" selection-start-line="25" selection-start-column="5" selection-end-line="25" selection-end-column="5" />
92
             </state>
92
             </state>
93
           </provider>
93
           </provider>
94
         </entry>
94
         </entry>
95
       </file>
95
       </file>
96
-      <file pinned="false" current-in-tab="true">
96
+      <file pinned="false" current-in-tab="false">
97
         <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
97
         <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
98
           <provider selected="true" editor-type-id="text-editor">
98
           <provider selected="true" editor-type-id="text-editor">
99
-            <state relative-caret-position="188">
100
-              <caret line="45" column="24" lean-forward="true" selection-start-line="45" selection-start-column="24" selection-end-line="45" selection-end-column="24" />
99
+            <state relative-caret-position="248">
100
+              <caret line="47" column="49" selection-start-line="47" selection-start-column="49" selection-end-line="47" selection-end-column="49" />
101
               <folding>
101
               <folding>
102
                 <element signature="imports" expanded="true" />
102
                 <element signature="imports" expanded="true" />
103
               </folding>
103
               </folding>
108
       <file pinned="false" current-in-tab="false">
108
       <file pinned="false" current-in-tab="false">
109
         <entry file="file://$PROJECT_DIR$/src/main/java/AccountServ.java">
109
         <entry file="file://$PROJECT_DIR$/src/main/java/AccountServ.java">
110
           <provider selected="true" editor-type-id="text-editor">
110
           <provider selected="true" editor-type-id="text-editor">
111
-            <state relative-caret-position="450">
112
-              <caret line="30" lean-forward="true" selection-start-line="30" selection-end-line="30" />
111
+            <state relative-caret-position="255">
112
+              <caret line="17" column="28" lean-forward="true" selection-start-line="17" selection-start-column="28" selection-end-line="17" selection-end-column="28" />
113
               <folding>
113
               <folding>
114
                 <element signature="imports" expanded="true" />
114
                 <element signature="imports" expanded="true" />
115
                 <element signature="e#175#176#0" expanded="true" />
115
                 <element signature="e#175#176#0" expanded="true" />
165
   <component name="IdeDocumentHistory">
165
   <component name="IdeDocumentHistory">
166
     <option name="CHANGED_PATHS">
166
     <option name="CHANGED_PATHS">
167
       <list>
167
       <list>
168
-        <option value="$PROJECT_DIR$/src/test/java/AccountServTest.java" />
169
         <option value="$PROJECT_DIR$/src/test/java/MockDao.java" />
168
         <option value="$PROJECT_DIR$/src/test/java/MockDao.java" />
170
-        <option value="$PROJECT_DIR$/src/main/java/AccountServ.java" />
171
         <option value="$PROJECT_DIR$/src/main/java/Console.java" />
169
         <option value="$PROJECT_DIR$/src/main/java/Console.java" />
170
+        <option value="$PROJECT_DIR$/src/main/java/AccountServ.java" />
171
+        <option value="$PROJECT_DIR$/src/test/java/AccountServTest.java" />
172
         <option value="$PROJECT_DIR$/src/main/java/AccountApp.java" />
172
         <option value="$PROJECT_DIR$/src/main/java/AccountApp.java" />
173
       </list>
173
       </list>
174
     </option>
174
     </option>
239
   <component name="PropertiesComponent">
239
   <component name="PropertiesComponent">
240
     <property name="WebServerToolWindowFactoryState" value="false" />
240
     <property name="WebServerToolWindowFactoryState" value="false" />
241
     <property name="aspect.path.notification.shown" value="true" />
241
     <property name="aspect.path.notification.shown" value="true" />
242
-    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542565159357" />
242
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1542566112760" />
243
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
243
     <property name="last_opened_file_path" value="$PROJECT_DIR$" />
244
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
244
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
245
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
245
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
260
       </list>
260
       </list>
261
     </option>
261
     </option>
262
   </component>
262
   </component>
263
-  <component name="RunManager">
263
+  <component name="RunManager" selected="JUnit.AccountServTest.createTest">
264
     <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
264
     <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
265
       <option name="MAIN_CLASS_NAME" value="AccountApp" />
265
       <option name="MAIN_CLASS_NAME" value="AccountApp" />
266
       <module name="SimpleAccount" />
266
       <module name="SimpleAccount" />
268
         <option name="Make" enabled="true" />
268
         <option name="Make" enabled="true" />
269
       </method>
269
       </method>
270
     </configuration>
270
     </configuration>
271
+    <configuration name="AccountServTest.createTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
272
+      <module name="SimpleAccount" />
273
+      <option name="PACKAGE_NAME" value="" />
274
+      <option name="MAIN_CLASS_NAME" value="AccountServTest" />
275
+      <option name="METHOD_NAME" value="createTest" />
276
+      <option name="TEST_OBJECT" value="method" />
277
+      <method v="2">
278
+        <option name="Make" enabled="true" />
279
+      </method>
280
+    </configuration>
281
+    <list>
282
+      <item itemvalue="Application.AccountApp" />
283
+      <item itemvalue="JUnit.AccountServTest.createTest" />
284
+    </list>
271
     <recent_temporary>
285
     <recent_temporary>
272
       <list>
286
       <list>
287
+        <item itemvalue="JUnit.AccountServTest.createTest" />
273
         <item itemvalue="Application.AccountApp" />
288
         <item itemvalue="Application.AccountApp" />
274
       </list>
289
       </list>
275
     </recent_temporary>
290
     </recent_temporary>
287
       <workItem from="1542239571129" duration="6414000" />
302
       <workItem from="1542239571129" duration="6414000" />
288
       <workItem from="1542402275147" duration="2006000" />
303
       <workItem from="1542402275147" duration="2006000" />
289
       <workItem from="1542420139392" duration="4000" />
304
       <workItem from="1542420139392" duration="4000" />
290
-      <workItem from="1542475891339" duration="6221000" />
305
+      <workItem from="1542475891339" duration="7385000" />
291
     </task>
306
     </task>
292
     <servers />
307
     <servers />
293
   </component>
308
   </component>
294
   <component name="TimeTrackingManager">
309
   <component name="TimeTrackingManager">
295
-    <option name="totallyTimeSpent" value="14645000" />
310
+    <option name="totallyTimeSpent" value="15809000" />
296
   </component>
311
   </component>
297
   <component name="ToolWindowManager">
312
   <component name="ToolWindowManager">
298
     <frame x="0" y="23" width="1440" height="807" extended-state="0" />
313
     <frame x="0" y="23" width="1440" height="807" extended-state="0" />
367
         </state>
382
         </state>
368
       </provider>
383
       </provider>
369
     </entry>
384
     </entry>
385
+    <entry file="file://$PROJECT_DIR$/src/main/java/Console.java">
386
+      <provider selected="true" editor-type-id="text-editor">
387
+        <state relative-caret-position="435">
388
+          <caret line="29" column="30" selection-start-line="29" selection-start-column="30" selection-end-line="29" selection-end-column="30" />
389
+          <folding>
390
+            <element signature="e#135#136#0" expanded="true" />
391
+            <element signature="e#169#170#0" expanded="true" />
392
+            <element signature="e#213#214#0" expanded="true" />
393
+            <element signature="e#241#242#0" expanded="true" />
394
+            <element signature="e#273#274#0" expanded="true" />
395
+            <element signature="e#286#287#0" expanded="true" />
396
+            <element signature="e#331#332#0" expanded="true" />
397
+            <element signature="e#353#354#0" expanded="true" />
398
+          </folding>
399
+        </state>
400
+      </provider>
401
+    </entry>
370
     <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
402
     <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
371
       <provider selected="true" editor-type-id="text-editor">
403
       <provider selected="true" editor-type-id="text-editor">
372
         <state relative-caret-position="55">
404
         <state relative-caret-position="55">
374
         </state>
406
         </state>
375
       </provider>
407
       </provider>
376
     </entry>
408
     </entry>
377
-    <entry file="file://$PROJECT_DIR$/src/test/java/AccountServTest.java">
409
+    <entry file="file://$PROJECT_DIR$/src/main/java/AccountServ.java">
378
       <provider selected="true" editor-type-id="text-editor">
410
       <provider selected="true" editor-type-id="text-editor">
379
-        <state relative-caret-position="480">
380
-          <caret line="35" selection-start-line="35" selection-end-line="35" />
411
+        <state relative-caret-position="255">
412
+          <caret line="17" column="28" lean-forward="true" selection-start-line="17" selection-start-column="28" selection-end-line="17" selection-end-column="28" />
413
+          <folding>
414
+            <element signature="imports" expanded="true" />
415
+            <element signature="e#175#176#0" expanded="true" />
416
+            <element signature="e#203#204#0" expanded="true" />
417
+          </folding>
381
         </state>
418
         </state>
382
       </provider>
419
       </provider>
383
     </entry>
420
     </entry>
384
     <entry file="file://$PROJECT_DIR$/src/test/java/MockDao.java">
421
     <entry file="file://$PROJECT_DIR$/src/test/java/MockDao.java">
385
       <provider selected="true" editor-type-id="text-editor">
422
       <provider selected="true" editor-type-id="text-editor">
386
-        <state relative-caret-position="-1666">
423
+        <state relative-caret-position="516">
387
           <caret line="37" column="12" selection-start-line="37" selection-start-column="10" selection-end-line="37" selection-end-column="12" />
424
           <caret line="37" column="12" selection-start-line="37" selection-start-column="10" selection-end-line="37" selection-end-column="12" />
388
           <folding>
425
           <folding>
389
             <element signature="imports" expanded="true" />
426
             <element signature="imports" expanded="true" />
397
         </state>
434
         </state>
398
       </provider>
435
       </provider>
399
     </entry>
436
     </entry>
400
-    <entry file="file://$PROJECT_DIR$/src/main/java/AccountServ.java">
437
+    <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
401
       <provider selected="true" editor-type-id="text-editor">
438
       <provider selected="true" editor-type-id="text-editor">
402
-        <state relative-caret-position="450">
403
-          <caret line="30" lean-forward="true" selection-start-line="30" selection-end-line="30" />
439
+        <state relative-caret-position="248">
440
+          <caret line="47" column="49" selection-start-line="47" selection-start-column="49" selection-end-line="47" selection-end-column="49" />
404
           <folding>
441
           <folding>
405
             <element signature="imports" expanded="true" />
442
             <element signature="imports" expanded="true" />
406
-            <element signature="e#175#176#0" expanded="true" />
407
-            <element signature="e#203#204#0" expanded="true" />
408
-          </folding>
409
-        </state>
410
-      </provider>
411
-    </entry>
412
-    <entry file="file://$PROJECT_DIR$/src/main/java/Console.java">
413
-      <provider selected="true" editor-type-id="text-editor">
414
-        <state relative-caret-position="435">
415
-          <caret line="29" column="30" selection-start-line="29" selection-start-column="30" selection-end-line="29" selection-end-column="30" />
416
-          <folding>
417
-            <element signature="e#135#136#0" expanded="true" />
418
-            <element signature="e#169#170#0" expanded="true" />
419
-            <element signature="e#213#214#0" expanded="true" />
420
-            <element signature="e#241#242#0" expanded="true" />
421
-            <element signature="e#273#274#0" expanded="true" />
422
-            <element signature="e#286#287#0" expanded="true" />
423
-            <element signature="e#331#332#0" expanded="true" />
424
-            <element signature="e#353#354#0" expanded="true" />
425
           </folding>
443
           </folding>
426
         </state>
444
         </state>
427
       </provider>
445
       </provider>
428
     </entry>
446
     </entry>
429
-    <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
447
+    <entry file="file://$PROJECT_DIR$/src/test/java/AccountServTest.java">
430
       <provider selected="true" editor-type-id="text-editor">
448
       <provider selected="true" editor-type-id="text-editor">
431
-        <state relative-caret-position="188">
432
-          <caret line="45" column="24" lean-forward="true" selection-start-line="45" selection-start-column="24" selection-end-line="45" selection-end-column="24" />
433
-          <folding>
434
-            <element signature="imports" expanded="true" />
435
-          </folding>
449
+        <state relative-caret-position="285">
450
+          <caret line="25" column="5" lean-forward="true" selection-start-line="25" selection-start-column="5" selection-end-line="25" selection-end-column="5" />
436
         </state>
451
         </state>
437
       </provider>
452
       </provider>
438
     </entry>
453
     </entry>

+ 2
- 1
src/main/java/AccountApp.java Parādīt failu

39
          * Read and write some example data.
39
          * Read and write some example data.
40
          */
40
          */
41
         private void processData() throws Exception {
41
         private void processData() throws Exception {
42
+           AccountServ services = new AccountServ();
42
            boolean end = false;
43
            boolean end = false;
43
             console.print("Welcome to your account manager");
44
             console.print("Welcome to your account manager");
44
                 while(!end){
45
                 while(!end){
45
                    int input = console.prntTakeInt("Please enter your selection: ");
46
                    int input = console.prntTakeInt("Please enter your selection: ");
46
                     if (input == 1) {
47
                     if (input == 1) {
47
-
48
+                        services.createAccount();
48
                     } else if(input == 2) {
49
                     } else if(input == 2) {
49
 
50
 
50
                     } else if(input == 3) {
51
                     } else if(input == 3) {

+ 8
- 0
src/main/java/AccountServ.java Parādīt failu

5
 public class AccountServ {
5
 public class AccountServ {
6
 
6
 
7
     private Dao<Account, Integer> dao;
7
     private Dao<Account, Integer> dao;
8
+    private Console console = new Console();
8
 
9
 
9
     public AccountServ() {
10
     public AccountServ() {
10
         this.dao = dao;
11
         this.dao = dao;
11
     }
12
     }
12
 
13
 
14
+    public void createAccount() throws SQLException {
15
+        String name = console.prntTakeStr("Please enter new account name");
16
+        String pswrd = console.prntTakeStr("Please enter new account password");
17
+        Account account = new Account(name, pswrd);
18
+        dao.create(account);
19
+    }
20
+
13
     public int create(Account account) throws SQLException {
21
     public int create(Account account) throws SQLException {
14
         return dao.create(account);
22
         return dao.create(account);
15
     }
23
     }

+ 7
- 1
src/test/java/AccountServTest.java Parādīt failu

1
 import com.j256.ormlite.dao.Dao;
1
 import com.j256.ormlite.dao.Dao;
2
 import com.j256.ormlite.stmt.query.In;
2
 import com.j256.ormlite.stmt.query.In;
3
+import org.junit.Assert;
3
 import org.junit.Before;
4
 import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 
6
 
7
+import java.sql.SQLException;
8
+
6
 public class AccountServTest {
9
 public class AccountServTest {
7
 
10
 
8
     Dao<Account, Integer> dao;
11
     Dao<Account, Integer> dao;
15
     }
18
     }
16
 
19
 
17
     @Test
20
     @Test
18
-    public void createTest(){
21
+    public void createTest() throws SQLException {
22
+        int expected = 100;
23
+        int actual = dao.create(account);
19
 
24
 
25
+        Assert.assertEquals(expected, actual);
20
     }
26
     }
21
 
27
 
22
     @Test
28
     @Test

Binārs
target/classes/Account.class Parādīt failu


Binārs
target/classes/AccountApp.class Parādīt failu


Binārs
target/classes/AccountServ.class Parādīt failu


Binārs
target/classes/Console.class Parādīt failu


Binārs
target/test-classes/AccountServTest.class Parādīt failu


Binārs
target/test-classes/MockDao.class Parādīt failu