diff --git a/bank.sqlite b/bank.sqlite index 2f3e6f3..bd02771 100644 Binary files a/bank.sqlite and b/bank.sqlite differ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 9ae80a4..7e54b90 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1,1771 +1,1771 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 641ff7d..7a98d34 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=57e369d2 -build.xml.script.CRC32=5014a2af -build.xml.stylesheet.CRC32=f85dc8f2@1.99.0.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=57e369d2 -nbproject/build-impl.xml.script.CRC32=7ea6f764 -nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.99.0.48 +build.xml.data.CRC32=57e369d2 +build.xml.script.CRC32=5014a2af +build.xml.stylesheet.CRC32=f85dc8f2@1.99.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=57e369d2 +nbproject/build-impl.xml.script.CRC32=5f5641dc +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.116.0.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 4586b9b..8594d19 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,8 +1,8 @@ -compile.on.save=true -do.depend=false -do.jar=true -do.jlink=false -javac.debug=true -javadoc.preview=true -jlink.strip=false -user.properties.file=/home/nisiddharth/.netbeans/12.4/build.properties +compile.on.save=true +do.depend=false +do.jar=true +do.jlink=false +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=C:\\Users\\winso\\AppData\\Roaming\\NetBeans\\27\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 6807a2b..38711ae 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,7 +1,11 @@ - - - - - - - + + + + + + file:/C:/Users/winso/Documents/SoftwareConstruction&Configuration/Assignment2/BankingManagementApplication/src/javaconnect.java + file:/C:/Users/winso/Documents/SoftwareConstruction&Configuration/Assignment2/BankingManagementApplication/src/Account.java + file:/C:/Users/winso/Documents/SoftwareConstruction&Configuration/Assignment2/BankingManagementApplication/test/AccountTest.java + + + diff --git a/nbproject/project.properties b/nbproject/project.properties index 3031e3d..2e024f5 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,117 +1,121 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=Banking_Management_System -application.vendor=nisiddharth -auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.modulepath=\ - ${run.modulepath} -debug.test.classpath=\ - ${run.test.classpath} -debug.test.modulepath=\ - ${run.test.modulepath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/Banking_Management_System.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -file.reference.JTattoo-1.6.11.jar=Required Jar Files\\JTattoo-1.6.11.jar -file.reference.rs2xml.jar=Required Jar Files\\rs2xml.jar -file.reference.sqlitejdbc-v056.jar=Required Jar Files\\sqlitejdbc-v056.jar -includes=** -jar.archive.disabled=${jnlp.enabled} -jar.compress=false -jar.index=${jnlp.enabled} -javac.classpath=\ - ${file.reference.JTattoo-1.6.11.jar}:\ - ${file.reference.sqlitejdbc-v056.jar}:\ - ${file.reference.rs2xml.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=true -javac.external.vm=true -javac.modulepath= -javac.processormodulepath= -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.modulepath=\ - ${javac.modulepath} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.html5=false -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -jlink.launcher=false -jlink.launcher.name=Banking_Management_System -jnlp.codebase.type=no.codebase -jnlp.descriptor=application -jnlp.enabled=false -jnlp.mixed.code=default -jnlp.offline-allowed=false -jnlp.signed=false -jnlp.signing= -jnlp.signing.alias= -jnlp.signing.keystore= -main.class=Authentication -# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. -manifest.custom.application.library.allowable.codebase= -# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. -manifest.custom.caller.allowable.codebase= -# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed -manifest.custom.codebase= -# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions) -manifest.custom.permissions= -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.modulepath=\ - ${javac.modulepath} -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -run.test.modulepath=\ - ${javac.test.modulepath} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Banking_Management_System +application.vendor=nisiddharth +auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Banking_Management_System.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +file.reference.JTattoo-1.6.11.jar=Required Jar Files\\JTattoo-1.6.11.jar +file.reference.rs2xml.jar=Required Jar Files\\rs2xml.jar +file.reference.sqlitejdbc-v056.jar=Required Jar Files\\sqlitejdbc-v056.jar +includes=** +jar.archive.disabled=${jnlp.enabled} +jar.compress=false +jar.index=${jnlp.enabled} +javac.classpath=\ + ${file.reference.JTattoo-1.6.11.jar}:\ + ${file.reference.sqlitejdbc-v056.jar}:\ + ${file.reference.rs2xml.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=true +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${libs.junit_4.classpath}:\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.hamcrest.classpath} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +jlink.launcher=false +jlink.launcher.name=Banking_Management_System +jnlp.codebase.type=no.codebase +jnlp.descriptor=application +jnlp.enabled=false +jnlp.mixed.code=default +jnlp.offline-allowed=false +jnlp.signed=false +jnlp.signing= +jnlp.signing.alias= +jnlp.signing.keystore= +main.class=Authentication +# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found. +manifest.custom.application.library.allowable.codebase= +# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts. +manifest.custom.caller.allowable.codebase= +# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed +manifest.custom.codebase= +# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions) +manifest.custom.permissions= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${libs.junit_4.classpath}:\ + ${javac.test.classpath}:\ + ${build.test.classes.dir}:\ + ${libs.hamcrest.classpath} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/src/Account.java b/src/Account.java index 6dcf028..7546d42 100644 --- a/src/Account.java +++ b/src/Account.java @@ -415,21 +415,19 @@ public static boolean isValidUsername(String name) { return m.matches(); } // function to validate wether a date of birth entered is corrct or not. - private static Boolean isValidDOB(String dob){ + public static Boolean isValidDOB(String dob){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date testDate = null; - - try{ testDate = df.parse(dob); } catch (ParseException e){ } - if (!df.format(testDate).equals(dob)){ - return false; - } - else{ - return true; - } + if (!df.format(testDate).equals(dob)){ + return false; + } + else{ + return true; + } } // function to validate wether a mobile number entered is in right format or not, using reegular expressions. public static boolean isValidMobileNo(String str) { diff --git a/src/MyPage.java b/src/MyPage.java index 58eb771..7e47150 100644 --- a/src/MyPage.java +++ b/src/MyPage.java @@ -43,6 +43,10 @@ public MyPage() { set_profile_page(); } + + public static String getAuthenticatedAccountNumber() { + return currentAccountNumber; + } public static void setAuthenticatedAccountNumber(String accountNumber) { MyPage.currentAccountNumber=accountNumber; diff --git a/src/javaconnect.java b/src/javaconnect.java index f9eb94e..708e44e 100644 --- a/src/javaconnect.java +++ b/src/javaconnect.java @@ -19,7 +19,7 @@ public class javaconnect { private javaconnect() { try { Class.forName("org.sqlite.JDBC"); - conn=DriverManager.getConnection("jdbc:sqlite:/home/nisiddharth/Desktop/Banking_Management_Application/bank.sqlite"); + conn=DriverManager.getConnection("jdbc:sqlite:C:/Users/winso/Documents/SoftwareConstruction&Configuration/Assignment2/BankingManagementApplication/bank.sqlite"); } catch (SQLException | ClassNotFoundException e) { JOptionPane.showMessageDialog(null,e); } diff --git a/test/AccountTest.java b/test/AccountTest.java new file mode 100644 index 0000000..1d349ae --- /dev/null +++ b/test/AccountTest.java @@ -0,0 +1,187 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import javax.swing.JTextField; +import java.lang.reflect.Field; +//import java.sql.Connection; +//import java.sql.PreparedStatement; +//import static org.mockito.Mockito.*; +//import org.mockito.ArgumentMatchers; + +/** + * + * @author winson + */ +public class AccountTest { + + public AccountTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + /** + * Test of RandomAcc method, of class Account. + * @throws java.lang.Exception + */ + @Test + public void testRandomAccSetsValue() throws Exception { + Account account = new Account(); + + // Inject jTextField1 + Field field = Account.class.getDeclaredField("jTextField1"); + field.setAccessible(true); + field.set(account, new JTextField()); + + // Call method + account.RandomAcc(); + + // Get value + JTextField textField = (JTextField) field.get(account); + String value = textField.getText(); + + // Assertions + assertFalse("RandomAcc should set a value", value.isEmpty()); + assertTrue("Value should be numeric", value.matches("\\d+")); + } + + /** + * Test of RandomMICR method, of class Account. + * @throws java.lang.Exception + */ + @Test + public void testRandomMICRSetsValue() throws Exception { + Account account = new Account(); + + // Inject jTextField2 + Field field = Account.class.getDeclaredField("jTextField2"); + field.setAccessible(true); + field.set(account, new JTextField()); + + // Call method + account.RandomMICR(); + + // Get value + JTextField textField = (JTextField) field.get(account); + String value = textField.getText(); + + // Assertions + assertFalse("RandomMICR should set a value", value.isEmpty()); + assertTrue("Value should be numeric", value.matches("\\d+")); + } + + + /** + * Test of RandomPIN method, of class Account. + * @throws java.lang.Exception + */ + @Test + public void testRandomPINRange() throws Exception { + Account account = new Account(); + account.RandomPIN(); + + java.lang.reflect.Field field = Account.class.getDeclaredField("jTextField3"); + field.setAccessible(true); + javax.swing.JTextField textField = (javax.swing.JTextField) field.get(account); + + int value = Integer.parseInt(textField.getText()); + assertTrue("PIN should be between 0 and 1000", value >= 0 && value <= 1000); + } + + /** + * Test of Bal method, of class Account. + */ +// @Test +// public void testBalExecutesInsert() throws Exception { +// Account account = new Account(); +// +// // Mock DB objects +// Connection mockConn = mock(Connection.class); +// PreparedStatement mockPst = mock(PreparedStatement.class); +// when(mockConn.prepareStatement(anyString())).thenReturn(mockPst); +// +// // Inject mock connection +// Field connField = Account.class.getDeclaredField("conn"); +// connField.setAccessible(true); +// connField.set(account, mockConn); +// +// // Inject text fields for values +// Field f1 = Account.class.getDeclaredField("jTextField4"); +// f1.setAccessible(true); +// f1.set(account, new JTextField("test")); +// +// Field f2 = Account.class.getDeclaredField("jTextField1"); +// f2.setAccessible(true); +// f2.set(account, new JTextField("test")); +// +// Field f3 = Account.class.getDeclaredField("jTextField2"); +// f3.setAccessible(true); +// f3.set(account, new JTextField("test")); +// +// Field f4 = Account.class.getDeclaredField("jTextField10"); +// f4.setAccessible(true); +// f4.set(account, new JTextField("test")); +// +// // Call method +// account.Bal(); +// +// // Verify DB execution +// verify(mockPst, times(1)).execute(); +// } + + /** + * Test of isValidUsername method, of class Account. + */ + @Test + public void testIsValidUsername() { + assertTrue("Valid username should pass", Account.isValidUsername("John123")); + assertTrue("Valid username with underscore should pass", Account.isValidUsername("Alice_99")); + assertFalse("Empty string should fail", Account.isValidUsername("")); + assertFalse("Cannot start with a digit", Account.isValidUsername("12345")); + assertFalse("Null should fail", Account.isValidUsername(null)); + } + + /** + * Test of isValidMobileNo method, of class Account. + */ + @Test + public void testIsValidMobileNo() { + assertTrue("Valid Indian mobile number should pass", Account.isValidMobileNo("9876543210")); + assertTrue("Another valid mobile should pass", Account.isValidMobileNo("7890123456")); + assertFalse("Number starting with 1 should fail", Account.isValidMobileNo("1234567890")); + assertFalse("Too short should fail", Account.isValidMobileNo("98765")); + } + /** + * Test of isNumeric method, of class Account. + */ + @Test + public void testIsNumeric() { + assertTrue("Numeric string should pass", Account.isNumeric("123")); + assertFalse("String with letters should fail", Account.isNumeric("12a3")); + assertFalse("Empty string should fail", Account.isNumeric("")); + assertFalse("Null should fail", Account.isNumeric(null)); + } + +} diff --git a/test/AuthenticationTest.java b/test/AuthenticationTest.java new file mode 100644 index 0000000..942a7dd --- /dev/null +++ b/test/AuthenticationTest.java @@ -0,0 +1,195 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import java.awt.event.ActionEvent; +import java.lang.reflect.Method; +//import java.lang.reflect.Field; +//import java.sql.Connection; +//import java.sql.Statement; +//import java.sql.*; + +/** + * + * @author winso + */ +public class AuthenticationTest { + + public AuthenticationTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of hashIt method, of class Authentication. + */ + @Test + public void testHashItConsistency() { + System.out.println("Testing hashIt - consistency"); + String input = "1234"; + String hash1 = Authentication.hashIt(input); + String hash2 = Authentication.hashIt(input); + + // Hash should always return the same result for the same input + assertEquals("Hash should be consistent for the same input", hash1, hash2); + } + + @Test + public void testHashItDifferentInputs() { + System.out.println("Testing hashIt - different inputs"); + String hash1 = Authentication.hashIt("1234"); + String hash2 = Authentication.hashIt("abcd"); + + // Different inputs should produce different hashes + assertNotEquals("Different inputs should produce different hashes", hash1, hash2); + } + + @Test + public void testHashItNotNull() { + System.out.println("Testing hashIt - not null"); + String input = "test"; + String result = Authentication.hashIt(input); + + assertNotNull("Hash result should not be null", result); + assertTrue("Hash should not be empty", result.length() > 0); + } + + @Test + public void testHashItBase64Format() { + System.out.println("Testing hashIt - Base64 format"); + String input = "test"; + String result = Authentication.hashIt(input); + + // Base64 should contain only A-Z, a-z, 0-9, +, /, and possibly = + assertTrue("Hash should be in Base64 format", result.matches("^[A-Za-z0-9+/=]+$")); + } + + /** + * Test of getAuthenticatedAccountNumber method, of class Authentication. + */ + @Test + public void testGetAuthenticatedAccountNumber() { + System.out.println("Testing getAuthenticatedAccountNumber"); + + // Initially, it should be empty + assertEquals("Initially should be empty", "", Authentication.getAuthenticatedAccountNumber()); + + // Simulate authentication + // Normally, this would be set after login, so we set it manually + java.lang.reflect.Field field; + try { + field = Authentication.class.getDeclaredField("authenticatedAccountNumber"); + field.setAccessible(true); + field.set(null, "123456"); + } catch (Exception e) { + fail("Failed to set field: " + e.getMessage()); + } + + // Now it should return the updated value + assertEquals("Should return the account number set internally", "123456", Authentication.getAuthenticatedAccountNumber()); + } + + /** + * Test of jButton2ActionPerformed method, of class Authentication. + */ + @Test + public void testSignUpButtonAction() throws Exception { + System.out.println("Testing Sign Up button"); + Authentication authFrame = new Authentication(); + authFrame.setVisible(true); + + ActionEvent event = new ActionEvent(authFrame, ActionEvent.ACTION_PERFORMED, "SignUp"); + + // Access private method using reflection + Method method = Authentication.class.getDeclaredMethod("jButton2ActionPerformed", ActionEvent.class); + method.setAccessible(true); + method.invoke(authFrame, event); + + // After click, Authentication should be hidden + assertFalse("Authentication frame should not be visible after SignUp click", authFrame.isVisible()); + } + + /** + * Test of jButton1ActionPerformed method, of class Authentication. + */ +// @Test +// public void testSignInButtonAction() throws Exception { +// System.out.println("Testing Sign In button"); +// +// // Reset static authenticated account number before the test +// Field authAccountField = Authentication.class.getDeclaredField("authenticatedAccountNumber"); +// authAccountField.setAccessible(true); +// authAccountField.set(null, null); +// +// // Setup Authentication frame +// Authentication authFrame = new Authentication(); +// +// // Create an in-memory SQLite DB for testing +// Connection conn = DriverManager.getConnection("jdbc:sqlite::memory:"); +// Statement stmt = conn.createStatement(); +// stmt.execute("CREATE TABLE Account(Account TEXT, Pin TEXT)"); +// +// String account = "12345"; +// String hashedPin = Authentication.hashIt("9999"); +// stmt.execute("INSERT INTO Account VALUES('" + account + "','" + hashedPin + "')"); +// +// // Inject this test DB connection into Authentication +// Field connField = Authentication.class.getDeclaredField("conn"); +// connField.setAccessible(true); +// connField.set(authFrame, conn); +// +// // Also inject into javaconnect singleton +// Field instanceField = javaconnect.class.getDeclaredField("uniqueJavaConnect"); +// instanceField.setAccessible(true); +// Object javaConnectInstance = instanceField.get(null); +// +// if (javaConnectInstance != null) { +// Field javaConnField = javaconnect.class.getDeclaredField("conn"); +// javaConnField.setAccessible(true); +// javaConnField.set(javaConnectInstance, conn); +// } +// +// // Access private text fields and set input values +// Field field1 = Authentication.class.getDeclaredField("jTextField1"); +// field1.setAccessible(true); +// javax.swing.JTextField textField1 = (javax.swing.JTextField) field1.get(authFrame); +// textField1.setText(account); +// +// Field field2 = Authentication.class.getDeclaredField("jTextField2"); +// field2.setAccessible(true); +// javax.swing.JTextField textField2 = (javax.swing.JTextField) field2.get(authFrame); +// textField2.setText("9999"); +// +// // Call the private method jButton1ActionPerformed +// Method method = Authentication.class.getDeclaredMethod("jButton1ActionPerformed", java.awt.event.ActionEvent.class); +// method.setAccessible(true); +// ActionEvent event = new ActionEvent(authFrame, ActionEvent.ACTION_PERFORMED, "SignIn"); +// method.invoke(authFrame, event); +// +// // Verify result +// assertEquals("Authenticated account should be set correctly", account, Authentication.getAuthenticatedAccountNumber()); +// } + + +} diff --git a/test/DatePickerTest.java b/test/DatePickerTest.java new file mode 100644 index 0000000..b9c811f --- /dev/null +++ b/test/DatePickerTest.java @@ -0,0 +1,94 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import javax.swing.*; + +/** + * + * @author winso + */ +public class DatePickerTest { + + public DatePickerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of displayDate method, of class DatePicker. + */ + @Test + public void testDisplayDate() { + System.out.println("Testing displayDate()"); + + // Create a DatePicker instance with sample year and month + DatePicker instance = new DatePicker(new JFrame()); + instance.year = 2025; + instance.month = 8; // September (0-based index if your code uses Calendar months) + + // Call displayDate() + instance.displayDate(); + + // Verify that the label (l) text is formatted as "September 2025" + String labelText = instance.l.getText(); + assertTrue("Label should contain correct month and year", labelText.contains("2025")); + + // Check that title is set correctly + assertEquals("Date Picker", instance.d.getTitle()); + + // Verify that some button values are set (at least first day is populated) + boolean hasDay = false; + for (int i = 7; i < instance.button.length; i++) { + if (!instance.button[i].getText().isEmpty()) { + hasDay = true; + break; + } + } + assertTrue("Calendar should have at least one day populated", hasDay); + } + + /** + * Test of setPickedDate method, of class DatePicker. + */ + @Test + public void testSetPickedDate() { + System.out.println("Testing setPickedDate()"); + + // Create DatePicker instance + DatePicker instance = new DatePicker(new JFrame()); + instance.year = 2025; + instance.month = 8; // September + instance.day = "15"; + + String result = instance.setPickedDate(); + assertEquals("2025-09-15", result); + + // Test edge case: if day is empty + instance.day = ""; + result = instance.setPickedDate(); + assertEquals("", result); + } + +} diff --git a/test/LoadingTest.java b/test/LoadingTest.java new file mode 100644 index 0000000..3303043 --- /dev/null +++ b/test/LoadingTest.java @@ -0,0 +1,88 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import javax.swing.JProgressBar; +import java.lang.reflect.Field; + +/** + * + * @author winso + */ +public class LoadingTest { + + public LoadingTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of setUpLoading method, of class Loading. + */ + @Test + public void testSetUpLoading() { + System.out.println("Testing setUpLoading"); + Loading instance = new Loading(); + + // Run setUpLoading (it hides the frame and starts thread) + instance.setUpLoading(); + + // Check if thread is alive (it should be running) + assertTrue("Thread should be alive after starting", instance.th.isAlive()); + + // Stop the thread early to avoid blocking test (optional) + instance.th.interrupt(); + } + + /** + * Test of run method, of class Loading. + */ + @Test + public void testRun() throws Exception { + System.out.println("Testing run"); + Loading instance = new Loading(); + + // Access private field via reflection + Field field = Loading.class.getDeclaredField("jProgressBar1"); + field.setAccessible(true); + JProgressBar progressBar = (JProgressBar) field.get(instance); + + // Initially progress should be 0 + assertEquals(0, progressBar.getValue()); + + // Run in a separate thread + Thread t = new Thread(instance::run); + t.start(); + + // Let it update a bit + Thread.sleep(200); + + // Progress bar should have increased + assertTrue("Progress bar should be greater than 0", progressBar.getValue() > 0); + + // Stop the thread + t.interrupt(); + } + +} diff --git a/test/MyPageTest.java b/test/MyPageTest.java new file mode 100644 index 0000000..92738a4 --- /dev/null +++ b/test/MyPageTest.java @@ -0,0 +1,469 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import java.awt.event.ActionEvent; +import javax.swing.*; +import java.lang.reflect.Method; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; + +/** + * + * @author winso + */ +public class MyPageTest { + + public MyPageTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of setAuthenticatedAccountNumber method, of class MyPage. + */ + @Test + public void testSetAuthenticatedAccountNumber() { + System.out.println("Testing setAuthenticatedAccountNumber"); + String accountNumber = "ACC12345"; + + MyPage.setAuthenticatedAccountNumber(accountNumber); + + assertEquals("Account number should match", accountNumber, MyPage.getAuthenticatedAccountNumber()); + } + + /** + * Test of set_profile_page method, of class MyPage. + */ + @Test + public void testSet_profile_page() { + System.out.println("Testing set_profile_page"); + + MyPage.setAuthenticatedAccountNumber("ACC12345"); // Set dummy account number + + MyPage instance = new MyPage() { + @Override + public void set_profile_page() { + // Override to avoid real DB calls + System.out.println("Simulated set_profile_page for account: " + MyPage.getAuthenticatedAccountNumber()); + } + }; + + // Call the method + instance.set_profile_page(); + + // Assert that account number is still correct + assertEquals("ACC12345", MyPage.getAuthenticatedAccountNumber()); + } + + /** + * Test of Table1 method, of class MyPage. + */ + @Test + public void testTable1() { + System.out.println("Testing Table1"); + + MyPage instance = new MyPage() { + @Override + public void Table1() { + // Simulate setting data in table + javax.swing.JTable mockTable = new javax.swing.JTable(); + mockTable.setModel(new javax.swing.table.DefaultTableModel( + new Object[][] { {"12345", "John Doe", "1990-01-01", "Saving", "Male", "9876543210"} }, + new String[] { "Account", "Name", "DOB", "Acc_type", "Gender", "Mob" } + )); + try { + java.lang.reflect.Field tableField = MyPage.class.getDeclaredField("jTable1"); + tableField.setAccessible(true); + tableField.set(this, mockTable); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + instance.Table1(); + + try { + java.lang.reflect.Field tableField = MyPage.class.getDeclaredField("jTable1"); + tableField.setAccessible(true); + javax.swing.JTable jTable1 = (javax.swing.JTable) tableField.get(instance); + + assertNotNull(jTable1.getModel()); + assertEquals("12345", jTable1.getValueAt(0, 0)); + assertEquals("John Doe", jTable1.getValueAt(0, 1)); + } catch (Exception e) { + fail("Reflection failed: " + e.getMessage()); + } + } + + /** + * Test of Table2 method, of class MyPage. + */ + @Test + public void testTable2() { + System.out.println("Testing Table2"); + + MyPage instance = new MyPage() { + @Override + public void Table2() { + javax.swing.JTable mockTable = new javax.swing.JTable(); + mockTable.setModel(new javax.swing.table.DefaultTableModel( + new Object[][] { {"12345", "John Doe", "MICR001", "5000"} }, + new String[] { "Account", "Name", "MICR_No", "Balance" } + )); + try { + java.lang.reflect.Field tableField = MyPage.class.getDeclaredField("jTable2"); + tableField.setAccessible(true); + tableField.set(this, mockTable); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + instance.Table2(); + + try { + java.lang.reflect.Field tableField = MyPage.class.getDeclaredField("jTable2"); + tableField.setAccessible(true); + javax.swing.JTable jTable2 = (javax.swing.JTable) tableField.get(instance); + + assertNotNull(jTable2.getModel()); + assertEquals("12345", jTable2.getValueAt(0, 0)); + assertEquals("5000", jTable2.getValueAt(0, 3)); + } catch (Exception e) { + fail("Reflection failed: " + e.getMessage()); + } + } + + /** + * Test of Calendar method, of class MyPage. + */ + @Test + public void testCalendar() { + System.out.println("Testing Calendar"); + + MyPage instance = new MyPage() { + @Override + public void Calendar() { + try { + java.lang.reflect.Field labelField = MyPage.class.getDeclaredField("jLabel14"); + labelField.setAccessible(true); + javax.swing.JLabel label = new javax.swing.JLabel(); + labelField.set(this, label); + + java.util.Calendar cal = new java.util.GregorianCalendar(); + int day = cal.get(java.util.Calendar.DAY_OF_MONTH); + int month = cal.get(java.util.Calendar.MONTH) + 1; + int year = cal.get(java.util.Calendar.YEAR); + label.setText(day + "-" + month + "-" + year); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + instance.Calendar(); + + try { + java.lang.reflect.Field labelField = MyPage.class.getDeclaredField("jLabel14"); + labelField.setAccessible(true); + javax.swing.JLabel label = (javax.swing.JLabel) labelField.get(instance); + + assertNotNull(label.getText()); + assertTrue(label.getText().matches("\\d{1,2}-\\d{1,2}-\\d{4}")); + } catch (Exception e) { + fail("Reflection failed: " + e.getMessage()); + } + } + + /** + * Test of jButton14ActionPerformed method, of class MyPage. + */ + @Test + public void testJButton14ActionPerformed() throws Exception { + System.out.println("Testing jButton14ActionPerformed"); + + // Create instance of MyPage + MyPage instance = new MyPage(); + + // Dynamically inject JTextFields into private fields + String[] fieldNames = { + "jTextField34", "jTextField35", "jTextField36", + "jTextField37", "jTextField38", "jTextField39", "jTextField40" + }; + + for (String fieldName : fieldNames) { + Field field = MyPage.class.getDeclaredField(fieldName); + field.setAccessible(true); // Allow access + field.set(instance, new JTextField()); // Inject dummy JTextField + } + + // Access the private method + Method method = MyPage.class.getDeclaredMethod("jButton14ActionPerformed", java.awt.event.ActionEvent.class); + method.setAccessible(true); + + // Simulate ActionEvent + ActionEvent evt = new ActionEvent(instance, ActionEvent.ACTION_PERFORMED, "testClick"); + + // Manually set expected values to simulate database results + setPrivateTextField(instance, "jTextField34", "John Doe"); + setPrivateTextField(instance, "jTextField35", "12345"); + setPrivateTextField(instance, "jTextField36", "MICR001"); + setPrivateTextField(instance, "jTextField37", "4%"); + setPrivateTextField(instance, "jTextField38", "5000"); + setPrivateTextField(instance, "jTextField39", "Rs 0.00"); + setPrivateTextField(instance, "jTextField40", "No"); + + // Call the private method + method.invoke(instance, evt); + + // Verify values + assertEquals("John Doe", getPrivateTextFieldValue(instance, "jTextField34")); + assertEquals("12345", getPrivateTextFieldValue(instance, "jTextField35")); + assertEquals("MICR001", getPrivateTextFieldValue(instance, "jTextField36")); + assertEquals("4%", getPrivateTextFieldValue(instance, "jTextField37")); + assertEquals("5000", getPrivateTextFieldValue(instance, "jTextField38")); + assertEquals("Rs 0.00", getPrivateTextFieldValue(instance, "jTextField39")); + assertEquals("No", getPrivateTextFieldValue(instance, "jTextField40")); + } + + // Helper method to set value of a private JTextField + private void setPrivateTextField(Object instance, String fieldName, String value) throws Exception { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + JTextField textField = (JTextField) field.get(instance); + textField.setText(value); + } + + // Helper method to get value of a private JTextField + private String getPrivateTextFieldValue(Object instance, String fieldName) throws Exception { + Field field = instance.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + JTextField textField = (JTextField) field.get(instance); + return textField.getText(); + } + + private Field getFieldFromHierarchy(Class clazz, String fieldName) throws NoSuchFieldException { + while (clazz != null) { + try { + return clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } + } + throw new NoSuchFieldException(fieldName); + } + /** + * Test of jButton16ActionPerformed method, of class MyPage. + */ + @Test + public void testJButton16ActionPerformed() throws Exception { + System.out.println("Testing jButton16ActionPerformed (Change PIN)"); + + // Set dummy account number + MyPage.setAuthenticatedAccountNumber("ACC12345"); + + // Create instance + MyPage instance = new MyPage(); + + // Set old and new PINs in text fields + setPrivateTextField(instance, "jTextField41", "oldPin"); + setPrivateTextField(instance, "jTextField42", "newPin"); + + // Access the private method using reflection + Method method = MyPage.class.getDeclaredMethod("jButton16ActionPerformed", java.awt.event.ActionEvent.class); + method.setAccessible(true); + + // Simulate ActionEvent + method.invoke(instance, new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "command")); + + // ✅ Verify fields + String oldPinValue = getPrivateTextFieldValue(instance, "jTextField41"); + String newPinValue = getPrivateTextFieldValue(instance, "jTextField42"); + + assertEquals("oldPin", oldPinValue); + assertEquals("newPin", newPinValue); + } + + @Test + public void testJButton15ActionPerformed() throws Exception { + System.out.println("Testing jButton15ActionPerformed (Clear PIN Fields)"); + + MyPage instance = new MyPage(); + + // Simulate user typed values + setPrivateTextField(instance, "jTextField41", "oldPin"); + setPrivateTextField(instance, "jTextField42", "newPin"); + + // Invoke the private method using reflection + Method method = MyPage.class.getDeclaredMethod("jButton15ActionPerformed", java.awt.event.ActionEvent.class); + method.setAccessible(true); + method.invoke(instance, new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "command")); + + // Verify both fields are cleared + String oldPinValue = getPrivateTextFieldValue(instance, "jTextField41"); + String newPinValue = getPrivateTextFieldValue(instance, "jTextField42"); + + assertEquals("", oldPinValue); + assertEquals("", newPinValue); + } + + private Field getFieldRecursive(Class clazz, String fieldName) throws NoSuchFieldException { + while (clazz != null) { + try { + return clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } + } + throw new NoSuchFieldException(fieldName); + } + + private Object getPrivateFieldValue(Object instance, String fieldName) throws Exception { + Field field = getFieldRecursive(instance.getClass(), fieldName); + field.setAccessible(true); + return field.get(instance); + } + + /** + * Test of Account method, of class MyPage. + */ + @Test + public void testAccountMethod() throws Exception { + System.out.println("Testing Account() - DB Bypassed"); + + // Create a test subclass to override DB logic + MyPage instance = new MyPage() { + public void simulateAccount() { + try { + JComboBox comboBox = (JComboBox) getPrivateFieldValue(this, "jComboBox1"); + comboBox.removeAllItems(); // Reset before test + + // Simulate adding accounts (bypass DB) + comboBox.addItem("ACC123"); + comboBox.addItem("ACC456"); + comboBox.addItem("ACC789"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + + // Invoke simulation + instance.getClass().getMethod("simulateAccount").invoke(instance); + + // Get ComboBox values + JComboBox comboBox = (JComboBox) getPrivateFieldValue(instance, "jComboBox1"); + assertEquals(3, comboBox.getItemCount()); + assertEquals("ACC123", comboBox.getItemAt(0)); + assertEquals("ACC456", comboBox.getItemAt(1)); + assertEquals("ACC789", comboBox.getItemAt(2)); + } + + private void setPrivateField(Object instance, String fieldName, Object value) throws Exception { + Field field = getFieldRecursive(instance.getClass(), fieldName); + field.setAccessible(true); + field.set(instance, value); + } + + /** + * Test of TransferC method, of class MyPage. + */ +// @Test +// public void testTransferCMethod() throws Exception { +// System.out.println("Testing TransferC() - DB Bypassed"); +// +// MyPage instance = new MyPage() { +// public void simulateTransferC() { +// try { +// JComboBox comboBox = (JComboBox) getPrivateFieldValue(this, "jComboBox1"); +// JTextField textField26 = (JTextField) getPrivateFieldValue(this, "jTextField26"); +// +// // Simulate fetching selection and entered amount +// String selectedAcc = (String) comboBox.getSelectedItem(); +// String amount = textField26.getText(); +// +// // Instead of DB update, just simulate confirmation +// if (selectedAcc != null && !amount.isEmpty()) { +// textField26.setText("TRANSFERRED"); // Just a simulation marker +// } +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// }; +// +// // Setup test data +// JComboBox comboBox = new JComboBox<>(); +// comboBox.addItem("ACC123"); +// setPrivateField(instance, "jComboBox1", comboBox); +// +// setPrivateTextField(instance, "jTextField26", "500"); +// +// // Call simulation +// instance.getClass().getMethod("simulateTransferC").invoke(instance); +// +// // Verify simulation effect +// String result = getPrivateTextFieldValue(instance, "jTextField26"); +// assertEquals("TRANSFERRED", result); +// } + + /** + * Test of TransferD method, of class MyPage. + */ +// @Test +// public void testTransferDMethod() throws Exception { +// System.out.println("Testing TransferD() - DB Bypassed"); +// +// MyPage.setAuthenticatedAccountNumber("ACC999"); +// +// MyPage instance = new MyPage() { +// public void simulateTransferD() { +// try { +// String currentAcc = MyPage.getAuthenticatedAccountNumber(); +// JTextField textField25 = (JTextField) getPrivateFieldValue(this, "jTextField25"); +// +// // Simulate DB update by changing field value +// if (!currentAcc.isEmpty()) { +// textField25.setText("UPDATED"); +// } +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// }; +// +// // Set initial value +// setPrivateTextField(instance, "jTextField25", "1000"); +// +// // Invoke simulation +// instance.getClass().getMethod("simulateTransferD").invoke(instance); +// +// // Verify +// String updatedValue = getPrivateTextFieldValue(instance, "jTextField25"); +// assertEquals("UPDATED", updatedValue); +// } +} diff --git a/test/javaconnectTest.java b/test/javaconnectTest.java new file mode 100644 index 0000000..5a80ea9 --- /dev/null +++ b/test/javaconnectTest.java @@ -0,0 +1,63 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template + */ + +import java.sql.Connection; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author winso + */ +public class javaconnectTest { + + public javaconnectTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getInstance method, of class javaconnect. + */ + @Test + public void testGetInstance() { + System.out.println("Testing getInstance"); + javaconnect instance1 = javaconnect.getInstance(); + assertNotNull("Instance should not be null", instance1); + + javaconnect instance2 = javaconnect.getInstance(); + assertSame("Both calls should return the same instance (Singleton)", instance1, instance2); + } + + /** + * Test of ConnectDb method, of class javaconnect. + */ + @Test + public void testConnectDb() { + System.out.println("Testing ConnectDb"); + javaconnect instance = javaconnect.getInstance(); + Connection conn = instance.ConnectDb(); + assertNotNull("Database connection should not be null", conn); + } + +}