EnumGenerator { Slot findSlotByName(String name, EnumerationLiteral enumLiteral) { EList<Slot> slots = enumLiteral.getSlots(); for (Slot slot : slots) { Property property = (Property) slot.getDefiningFeature(); String slotPropertyName = property.getName(); if (slotPropertyName.equals(name)) { return slot; } } return null; }  void setConstructorParameterNames(
			ArrayList<String> constructorParameterNames); CompilationUnit generateEnum(Classifier clazz,
			String sourceDirectoryPackageName); @SuppressWarnings("unchecked") void generateAttributes(Classifier clazz, AST ast, EnumDeclaration ed); FieldDeclaration generateAttribute(Classifier clazz, AST ast,
			Property property); @SuppressWarnings("unchecked") void generateGetterMethod(Classifier clazz, AST ast,
			EnumDeclaration ed); void generateGetterMethod(Classifier clazz, AST ast,
			EnumDeclaration ed, String sourceDirectoryPackageName); @SuppressWarnings("unchecked") void generateConstructor(Classifier clazz, AST ast,
			EnumDeclaration ed); @SuppressWarnings("unchecked") EnumDeclaration generateEnum(Classifier clazz, AST ast,
			CompilationUnit cu); void generateClassJavadoc(Element clazz, AST ast, BodyDeclaration td); void generatePackage(Classifier clazz, AST ast, CompilationUnit cu); @SuppressWarnings("unchecked") void generateConstants(Classifier clazz, AST ast, EnumDeclaration ed);  }
@SuppressWarnings("unchecked") @Test public void testFindSlotByNameFoundIt() { EnumerationLiteral enumLiteral = mock(EnumerationLiteral.class); EList<Slot> slots = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Slot> slotIter = mock(Iterator.class); Slot slot1 = mock(Slot.class); Slot slot2 = mock(Slot.class); Property property1 = mock(Property.class); Property property2 = mock(Property.class); when(enumLiteral.getSlots()).thenReturn(slots); when(slots.iterator()).thenReturn(slotIter); when(slotIter.hasNext()).thenReturn(true).thenReturn(true) .thenReturn(false); when(slotIter.next()).thenReturn(slot1).thenReturn(slot2); when(slot1.getDefiningFeature()).thenReturn(property1); when(slot2.getDefiningFeature()).thenReturn(property2); when(property1.getName()).thenReturn("test1"); when(property2.getName()).thenReturn("test2"); Slot slotResult = enumGenerator.findSlotByName("test1", enumLiteral); assertEquals(slot1, slotResult); }
@SuppressWarnings("unchecked") @Test public void testFindSlotByNameNotFound() { EnumerationLiteral enumLiteral = mock(EnumerationLiteral.class); EList<Slot> slots = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Slot> slotIter = mock(Iterator.class); Slot slot1 = mock(Slot.class); Slot slot2 = mock(Slot.class); Property property1 = mock(Property.class); Property property2 = mock(Property.class); when(enumLiteral.getSlots()).thenReturn(slots); when(slots.iterator()).thenReturn(slotIter); when(slotIter.hasNext()).thenReturn(true).thenReturn(true) .thenReturn(false); when(slotIter.next()).thenReturn(slot1).thenReturn(slot2); when(slot1.getDefiningFeature()).thenReturn(property1); when(slot2.getDefiningFeature()).thenReturn(property2); when(property1.getName()).thenReturn("test1"); when(property2.getName()).thenReturn("test2"); Slot slotResult = enumGenerator.findSlotByName("test3", enumLiteral); assertEquals(null, slotResult); }