public void RulesPluginBuilder_RulesFileSetToNull_Fails()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            // Act and assert
            AssertException.Expect <ArgumentNullException>(() => builder.SetRulesFilePath(null));
            AssertException.Expect <ArgumentNullException>(() => builder.SetRulesFilePath(""));
        }
        public void RulesPluginBuilder_RulesFileSetToNull_Fails()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            // Act and assert
            AssertException.Expect<ArgumentNullException>(() => builder.SetRulesFilePath(null));
            AssertException.Expect<ArgumentNullException>(() => builder.SetRulesFilePath(""));
        }
        public void RulesPluginBuilder_RulesFileValidation()
        {
            // Arrange
            MockJdkWrapper     mockJdkWrapper = new MockJdkWrapper();
            RulesPluginBuilder builder        = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger());

            SetValidCoreProperties(builder);
            builder.SetLanguage("aLanguage");

            // 1. Rules file not specified -> error
            AssertException.Expect <InvalidOperationException>(() => builder.Build());

            // 2. Non-existent rules file specified -> error
            string testDir   = TestUtils.EnsureTestDirectoryExists(this.TestContext);
            string rulesFile = Path.Combine(testDir, "missingFile.txt");

            mockJdkWrapper.AssertCodeNotCompiled();

            builder.SetRulesFilePath(rulesFile);
            FileNotFoundException ex = AssertException.Expect <FileNotFoundException>(() => builder.Build());

            Assert.AreEqual(ex.FileName, rulesFile);
            mockJdkWrapper.AssertCodeNotCompiled();

            // 3. Rules file exists -> succeeds
            AddValidDummyRulesFiles(builder);
            builder.Build(); // should succeed
            mockJdkWrapper.AssertJarBuilt();
        }
        private void AddValidDummyRulesFiles(RulesPluginBuilder builder)
        {
            string testDir   = TestUtils.EnsureTestDirectoryExists(this.TestContext);
            string rulesFile = TestUtils.CreateTextFile("rules.txt", testDir, "dummy rules file");

            builder.SetRulesFilePath(rulesFile);
        }
        public void RulesPluginBuilder_RulesFileValidation()
        {
            // Arrange
            MockJdkWrapper mockJdkWrapper = new MockJdkWrapper();
            RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger());
            SetValidCoreProperties(builder);
            builder.SetLanguage("aLanguage");

            // 1. Rules file not specified -> error
            AssertException.Expect<InvalidOperationException>(() => builder.Build());

            // 2. Non-existent rules file specified -> error
            string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext);
            string rulesFile = Path.Combine(testDir, "missingFile.txt");
            mockJdkWrapper.AssertCodeNotCompiled();

            builder.SetRulesFilePath(rulesFile);
            FileNotFoundException ex = AssertException.Expect<FileNotFoundException>(() => builder.Build());
            Assert.AreEqual(ex.FileName, rulesFile);
            mockJdkWrapper.AssertCodeNotCompiled();

            // 3. Rules file exists -> succeeds
            AddValidDummyRulesFiles(builder);
            builder.Build(); // should succeed
            mockJdkWrapper.AssertJarBuilt();
        }
        private void AddValidDummyRulesFiles(RulesPluginBuilder builder)
        {
            string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext);
            string rulesFile = TestUtils.CreateTextFile("rules.txt", testDir, "dummy rules file");

            builder.SetRulesFilePath(rulesFile);
        }