@Test public void testGenerateSessions() { String fileName = "TinySample.java"; String filePath = "C:/Users/Christian Adriano/Documents/GitHub/crowd-debug-firefly/samples-discarded/sample/tiny/"; String fileContent = SourceFileReader.readFileToString(filePath + fileName); CodeSnippetFactory snippetFactory = new CodeSnippetFactory("TinySample.java", fileContent); Vector<CodeSnippet> list = snippetFactory.generateSnippetsForFile(); if ((list == null) || (list.size() != 2)) Assert.fail( "Null list of snippets or file does not match test data, actual size is: " + list.size()); else { QuestionFactory questionFactory = new QuestionFactory(); questionFactory.generateMicrotasks(list, "Bug report message", 0); Hashtable<Integer, Microtask> microtaskMap = questionFactory.getConcreteQuestions(); FileDebugSession fileDebuggingSession = new FileDebugSession("TinySample.java", fileContent, microtaskMap); // Persist data MicrotaskStorage memento = MicrotaskStorage.initializeSingleton(); ; memento.insert(fileName, fileDebuggingSession); // Generate the WorkerSession WorkerSessionFactory sessionFactory = new WorkerSessionFactory(2); // Test the original Stack Stack<WorkerSession> actualStack = sessionFactory.generateSessions(3 - 1); while (!actualStack.isEmpty() && !expectedStack.isEmpty()) { WorkerSession actual = actualStack.pop(); WorkerSession expected = expectedStack.pop(); Assert.assertEquals( "WorkerSession ID: " + expected.getId() + " does not match", actual.getId(), expected.getId()); } } }
@Test public void testMethodMap() { String fileName = "TinySample.java"; String filePath = "C:/Users/Christian Adriano/Documents/GitHub/crowd-debug-firefly/samples-discarded/sample/tiny/"; String fileContent = SourceFileReader.readFileToString(filePath + fileName); CodeSnippetFactory snippetFactory = new CodeSnippetFactory("TinySample.java", fileContent); Vector<CodeSnippet> list = snippetFactory.generateSnippetsForFile(); if ((list == null) || (list.size() != 2)) Assert.fail( "Null list of snippets or file does not match test data, actual size is: " + list.size()); else { QuestionFactory questionFactory = new QuestionFactory(); questionFactory.generateMicrotasks(list, "Bug report message", 0); Hashtable<Integer, Microtask> microtaskMap = questionFactory.getConcreteQuestions(); FileDebugSession fileDebuggingSession = new FileDebugSession("TinySample.java", fileContent, microtaskMap); // Persist data MicrotaskStorage memento = MicrotaskStorage.initializeSingleton(); ; memento.insert(fileName, fileDebuggingSession); // Generate the WorkerSession WorkerSessionFactory sessionFactory = new WorkerSessionFactory(10); HashMap<String, HashMap<String, ArrayList<Microtask>>> actualFileMethodMap = sessionFactory.getFileMethodMap(); HashMap<String, ArrayList<Microtask>> methodMap = actualFileMethodMap.get("TinySample.java"); Assert.assertNotNull(methodMap); ArrayList<Microtask> method1List = methodMap.get("TinySample"); if (method1List == null || method1List.size() != 4) Assert.fail( "List of microtasks for method TinySample is wrong, actual size is: " + method1List.size()); else { ArrayList<Microtask> method2List = methodMap.get("seedCounter"); if (method2List == null || method2List.size() != 7) Assert.fail( "List of microtasks for method seedCounter is wrong, actual size is: " + method2List.size()); else { Microtask mtask1 = method1List.get(0); Assert.assertEquals( "First Microtask (ID=" + mtask1.getID().toString() + ") of TinySample does not match", 0, mtask1.getID().toString().compareTo("0")); Microtask mtask2 = method2List.get(0); Assert.assertEquals( "First Microtask (ID=" + mtask2.getID().toString() + ") of seedCounter does not match", 0, mtask2.getID().toString().compareTo("4")); } } } }
@Test public void testObtainMicrotaskList() { String fileName = "TinySample.java"; String filePath = "C:/Users/Christian Adriano/Documents/GitHub/crowd-debug-firefly/samples-discarded/sample/tiny/"; String fileContent = SourceFileReader.readFileToString(filePath + fileName); CodeSnippetFactory snippetFactory = new CodeSnippetFactory("TinySample.java", fileContent); Vector<CodeSnippet> list = snippetFactory.generateSnippetsForFile(); if ((list == null) || (list.size() != 2)) Assert.fail( "Null list of snippets or file does not match test data, actual size is: " + list.size()); else { QuestionFactory questionFactory = new QuestionFactory(); questionFactory.generateMicrotasks(list, "Bug report message", 0); Hashtable<Integer, Microtask> microtaskMap = questionFactory.getConcreteQuestions(); FileDebugSession fileDebuggingSession = new FileDebugSession("TinySample.java", fileContent, microtaskMap); // Persist data MicrotaskStorage memento = MicrotaskStorage.initializeSingleton(); ; memento.insert(fileName, fileDebuggingSession); // Generate the WorkerSession WorkerSessionFactory sessionFactory = new WorkerSessionFactory(10); HashMap<String, HashMap<String, ArrayList<Microtask>>> actualFileMethodMap = sessionFactory.getFileMethodMap(); HashMap<String, ArrayList<Microtask>> methodMap = actualFileMethodMap.get("TinySample.java"); Assert.assertNotNull(methodMap); // Obtain a list of N microtasks from N different codesnippets (i.e., methods) Vector<Microtask> actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 0 does not match", 0, this.compareVectors(actual, mtaskList0)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 1 does not match", 0, this.compareVectors(actual, mtaskList1)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 2 does not match", 0, this.compareVectors(actual, mtaskList2)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 3 does not match", 0, this.compareVectors(actual, mtaskList3)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 4 does not match", 0, this.compareVectors(actual, mtaskList4)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 5 does not match", 0, this.compareVectors(actual, mtaskList5)); actual = sessionFactory.nextMicrotaskList(10); Assert.assertEquals( "MicrotasksList 6 does not match", 0, this.compareVectors(actual, mtaskList6)); } }