Question: Consider java while doing this question please: Note: Please check the code and make sure it is without any error. here is the code: FlawedClass.java
Consider java while doing this question please:
Note: Please check the code and make sure it is without any error.
here is the code:
FlawedClass.java packageedu.gatech.seclass; public class FlawedClass { Public int flawedMethod1(int x, boolean s, boolean c) {if (s) { x++} else {x-- } if (c){x += 2} else {x -= 2} return x / (x + 1);} Task 2
public int flawedMethod2(){ int number = 20; return 20/0;}} Task 3 Public boolean flawedMethod3(boolean a, boolean b) {int x = 2; int y = 6; if (a){x = 4; } else{y = y / x;} if (b){x --; } else {x ++;}return ((2 / (y - x) >= 1);}
Task 4 public boolean flawedMethod4 (boolean a, boolean b) { int x = 2; int y = 6; if(a) x = 4;else y = y / x; if(b) x -= 1;else x += 1; return ((2/(y-x)) >= 1); }
____________
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test;
class FlawedClassTest { @Test void test() {fail("Not yet implemented");}FlawedClassTestBC1.java
packageedu.gatech.seclass.test; importedu.gatech.seclass.FlawedClass; importorg.junit.Assert;importorg.junit.Test; public class FlawedClassTestBC1 {FlawedClassflawedClass = new FlawedClass(); int x = 123; @Test public void testCase1() {int res = flawedClass.flawedMethod1(x, true, false); Assert.assertEquals(res, 0);} @Test public void testCase2() { int res = flawedClass.flawedMethod1(x, false, true); Assert.assertEquals(res, 0);} @Test public void testCase3() { int res = flawedClass.flawedMethod1(x, false, false);Assert.assertEquals(res, 0);} @Test public void testCase4() {int res = flawedClass.flawedMethod1(x, true, true); Assert.assertEquals(res, 0);}} FlawedClassTestPC3.java packageedu.gatech.seclass.test; importedu.gatech.seclass.FlawedClass; importorg.junit.Assert; importorg.junit.Test; public class FlawedClassTestPC3 { FlawedClassflawedClass = new FlawedClass(); @Test public void testCase1() {boolean res = flawedClass.flawedMethod3(true, false);Assert.assertTrue(res); } @Test public void testCase2() {boolean res = flawedClass.flawedMethod3(false, true);Assert.assertTrue(res);} @Test public void testCase3() {boolean res = flawedClass.flawedMethod3(true, true); Assert.assertFalse(res);} @Test public void testCase4() {boolean res = flawedClass.flawedMethod3(false, false);Assert.assertFalse(res);}} FlawedClassTestSC1.java packageedu.gatech.seclass.test; importedu.gatech.seclass.FlawedClass;importorg.junit.Assert;importorg.junit.Test; public class FlawedClassTestSC1 {FlawedClassflawedClass = new FlawedClass(); int x = 0; @Test public void testCase1() {int res = flawedClass.flawedMethod1(x, true, false);Assert.assertEquals(res, 0);} @Test public void testCase2() {int res = flawedClass.flawedMethod1(x, false, true); Assert.assertEquals(res, 0);}} FlawedClassTestSC3.java packageedu.gatech.seclass.test; importedu.gatech.seclass.FlawedClass; importorg.junit.Assert; importorg.junit.Test; public class FlawedClassTestSC3 {FlawedClassflawedClass = new FlawedClass(); @Test public void testCase1() {boolean res = flawedClass.flawedMethod3(true, false);Assert.assertTrue(res);} @Test public void testCase2() {boolean res = flawedClass.flawedMethod3(false, true);Assert.assertTrue(res);}} FlawedClassTestXC5.java packageedu.gatech.seclass.test; importedu.gatech.seclass.FlawedClass;importorg.junit.Assert;importorg.junit.Test; public class FlawedClassTestXC5 {FlawedClassflawedClass = new FlawedClass(); @Test public void testCase1() {boolean res = flawedClass.flawedMethod3(true, false);Assert.assertTrue(res);} @Test public void testCase2() {boolean res = flawedClass.flawedMethod3(false, true); Assert.assertTrue(res);} @Test public void testCase3() {boolean res = flawedClass.flawedMethod3(true, true);Assert.assertFalse(res);} @Test public void testCase4() {boolean res = flawedClass.flawedMethod3(false, false); Assert.assertFalse(res);}}} ____________
import org.junit.After;import org.junit.Before;import org.junit.Rule;import org.junit.Test;import org.junit.rules.TemporaryFolder;import java.io.*;import java.nio.charset.Charset;import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Paths;import static org.junit.Assert.*;
public class MainTest {private ByteArrayOutputStream outStream; private ByteArrayOutputStream errStream; private PrintStream outOrig; private PrintStream errOrig; private Charset charset = StandardCharsets.UTF_8;
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Before public void setUp() throws Exception {outStream = new ByteArrayOutputStream(); PrintStream out = new PrintStream(outStream); errStream = new ByteArrayOutputStream(); PrintStream err = new PrintStream(errStream); outOrig = System.out; errOrig = System.err; System.setOut(out); System.setErr(err);} @After public void tearDown() throws Exception {System.setOut(outOrig); System.setErr(errOrig);}
// Some utilities
private File createTmpFile() throws IOException {File tmpfile = temporaryFolder.newFile(); tmpfile.deleteOnExit(); return tmpfile;} private File createInputFile1() throws Exception { File file1 = createTmpFile(); FileWriter fileWriter = new FileWriter(file1); fileWriter.write("Howdy Billy, " + "This is a test file for the capitalize utility. " + "let's make sure it has at least a few lines, " + "so that we can create some "+ "interesting test cases...And let's say \"howdy\" to Bill again!"); fileWriter.close(); return file1; }
private String getFileContent(String filename) {String content = null; try {content = new String(Files.readAllBytes(Paths.get(filename)), charset);} catch (IOException e) {e.printStackTrace();} return content; } @Test public void mainTest1() throws Exception { File inputFile1 = createInputFile1();String args[] = {inputFile1.getPath()};Main.main(args); String expected1 = "Howdy Billy, " +"This Is A Test File For The Capitalize Utility. " +"Let's Make Sure It Has At Least A Few Lines, " + "So That We Can Create Some " + "Interesting Test Cases...And Let's Say \"howdy\" To Bill Again!"; String actual1 = getFileContent(inputFile1.getPath()); assertEquals("The files differ!", expected1, actual1);} @Test public void mainTest2() throws Exception { File inputFile1 = createInputFile1();String args[] = {"-l", inputFile1.getPath()}; Main.main(args); String expected1 = "Howdy Billy, " + "This is a test file for the capitalize utility. " +"Let's make sure it has at least a few lines, " + "So that we can create some " + "Interesting test cases...And let's say \"howdy\" to Bill again!"; String actual1 = getFileContent(inputFile1.getPath());assertEquals("The files differ!", expected1, actual1); } @Test public void mainTest3() throws Exception { File inputFile1 = createInputFile1(); String args[] = {"-e", "-s", inputFile1.getPath()};Main.main(args); String expected2 = "Howdy Billy, " + "This is a test file for the capitalize utility. " + "Let's make sure it has at least a few lines, " + "so that we can create some " + "interesting test cases...AND LET'S SAY \"HOWDY\" TO BILL AGAIN!";String actual2 = getFileContent(inputFile1.getPath()); assertEquals("The files differ!", expected2, actual2); } @Test public void mainTest4() throws Exception { File inputFile1 = createInputFile1();String args[] = {"-s", ",", "-x", inputFile1.getPath()}; Main.main(args);String expected3 = "Howdy billy, " + "This is a test file for the capitalize utility. " + "let's make sure it has at least a few lines, " +"So that we can create some " + "interesting test cases...and let's say \"howdy\" to bill again!";String actual3 = getFileContent(inputFile1.getPath());assertEquals("The files differ!", expected3, actual3); } @Test public void mainTest5() {String args[] = null; //invalid argumentMain.main(args); assertEquals("Usage: Capitalize [-l] [-e] [-s] [string] [-x]
________________
public class MyMainTest { private string name; public MyMainTest1() { int size = Not empty; if size == Not empty; System.out.println("Not empty"); } public MyMainTest2() {int length of the pattern = More than one; if (length of the pattern > More than one)System.out.println("More than one");elseSystem.out.println("Longer than the file"); } public MyMainTest3() { int length of the pattern = longer than the file; if (length of the pattern = longer than the file)System.out.println("longer");elseSystem.out.println("error"); }
public MyMainTest4() { int presence of enclosing quotes = enclosed;if (presence of enclosing = enclosed)System.out.println("enclosed");elseSystem.out.println("closed"); }
public MyMainTest5() { int presence of enclosing quotes = Incorrect; if (presence of enclosing = Incorrect)System.out.println("incorrect");elseSystem.out.println("correct"); }
public MyMainTest6() { int presence of blank = One; if (presence of blank = Many)System.out.println("One"); elseSystem.out.println("Many"); }
public MyMainTest7() { int presence of quotes within the pattern = None; if (presence of within the pattern = None)System.out.println("One");elseSystem.out.println("Many"); }
public MyMainTest8() { int presence of a file = Present;if (presence of enclosing = Present)System.out.println("Present");elseSystem.out.println("Not present"); }
public MyMainTest9() { int length of the pattern = One; if (length of the pattern = One)System.out.println("One");elseSystem.out.println("More than one"); }
public MyMainTest10() { int length of the pattern = More than one; if (length of the pattern = Longer than the file)System.out.println("More than one");else System.out.println("Longer than the file"); }
public MyMainTest11() { int presence of a file corresponding to the name = Not present;if (presence of file = Not present) System.out.println("Not present"); else System.out.println("Present"); }
public MyMainTest12() { int length of the pattern = One; if (length of the pattern = One) System.out.println("One"); else System.out.println("More than one"); }
public MyMainTest13() { int length of the pattern = More than one; if (length of the pattern = Longer than the file) System.out.println("More than one"); else System.out.println("Longer than the file"); }
public MyMainTest14() { int length of the pattern = Longer than the file; if (length of the pattern = More than one) System.out.println("Longer than the file"); else System.out.println("More than the file"); }
public MyMainTest15() { int -e pattern -s -l = Not present; if (-e pattern -s -l = Not present) System.out.println("Not present"); else System.out.println("Present"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
