       }
     }
     
+    segmentedField.validator = { (var genderType) -> NSError? in
+      switch genderType {
+      case .Female, .Male:
+        return nil
+      case .Unknown:
+        return NSError()
+      default:
+        return NSError()
+      }
+    }
+    
     testSection.append(segmentedField)
     
-    //Test Form
-    XCTAssertTrue(form?.item(indexPath: NSIndexPath(forRow: 0, inSection: 0)) === segmentedField, "Wrong element is returned from form")
+    // Test Form
+    XCTAssertTrue(form?.item(indexPath: NSIndexPath(forRow: 0, inSection: 0)) === segmentedField, "Expected the field that was previously added to the form")
+    XCTAssertEqual(form!.numberOfFieldsInSection(0), 1, "Section should have an Element")
+    var values = form!.serialize()
+    XCTAssertNotNil(values.isEmpty, "There should be a value since there is an element in the section")
+    XCTAssertEqual(values.count, 1, "There should only be one value since there is only one element in the section")
+    var gender = values.first!["SegmentedField"] as TestGender
+    XCTAssertTrue(gender == .Female, "value of SegmentedField has not expected value")
+    
+    // Test Selection
+    segmentedField.internalValue = 1
+    values = form!.serialize()
+    gender = values.first!["SegmentedField"] as TestGender
+    XCTAssertTrue(gender == .Male, "Expected gender to be Male after selection")
+    
+    // Test if Delegate is called
+    XCTAssertTrue((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Selection did not update the FormDelegate")
+    
+    // Reset FormDelegate
+    (form!.delegate! as FormTestDelegate).calledDidUpdateForm = false
+    // Just to be sure it is reset
+    XCTAssertFalse((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Should be reset")
+    
+    // Test Field Validation with valid value
+    segmentedField.value = .Female
+    XCTAssertTrue((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Value change did not update the FormDelegate")
+    XCTAssertNil(segmentedField.error, "There should not be an error after setting the value")
+    
+    // Reset FormDelegate
+    (form!.delegate! as FormTestDelegate).calledDidUpdateForm = false
+    // Just to be sure it is reset
+    XCTAssertFalse((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Should be reset")
+    
+    // Test Field Validation with invalid value
+    segmentedField.value = .Unknown
+    XCTAssertFalse((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Expected that FormDelegate did not update when setting invalid value")
+    XCTAssertTrue(segmentedField.error != nil, "There should be an error after setting an invalid value")
+    
+    // Test Field
+    XCTAssertEqual(segmentedField.representationValues!, ["Female", "Male"], "Representation is expected to return the values set in representationTransformer ")
+  }
+  
+  func test04addOneLineSegmentedFormField() {
+    
+    // Add Section and ForwardingElement
+    let testSection = form!.addSection("Test Section")
+    let segmentedField = SegmentedFormField<TestCountry, Int, String>(name: "SegmentedField", value: .Germany, values: [.Germany, .Austria])
+    testSection.append(segmentedField)
+    
+    // Test Form
+    XCTAssertTrue(form?.item(indexPath: NSIndexPath(forRow: 0, inSection: 0)) === segmentedField, "Expected the field that was previously added to the form")
     XCTAssertEqual(form!.numberOfFieldsInSection(0), 1, "Section should have an Element")
     var values = form!.serialize()
     XCTAssertNotNil(values.isEmpty, "Their should be a value since there is an element in the section")
-    var gender = values.first!["SegmentedField"] as TestGender
-    XCTAssertTrue(gender == .Female, "value of SegmentedField has not expected value")
-    
-    //Test Selection
+    XCTAssertEqual(values.count, 1, "There should only be one value since there is only one element in the section")
+    var country = values.first!["SegmentedField"] as TestCountry
+    XCTAssertTrue(country == .Germany, "value of SegmentedField has not expected value")
+    
+    // Test Selection
     segmentedField.internalValue = 1
     values = form!.serialize()
     XCTAssertNotNil(values.isEmpty, "Their should be a value since there is an element in the section")
-    gender = values.first!["SegmentedField"] as TestGender
-    XCTAssertTrue(gender == .Male, "value of SegmentedField has not expected value")
-    
-    //Test if Delegate is called
+    country = values.first!["SegmentedField"] as TestCountry
+    XCTAssertTrue(country == .Austria, "value of SegmentedField has not expected value")
+    
+    // Test if Delegate is called
     XCTAssertTrue((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Selection did not update the form")
-  }
-  
-}
+    
+    // Reset FormDelegate
+    (form!.delegate! as FormTestDelegate).calledDidUpdateForm = false
+    // Just to be sure it is reset
+    XCTAssertFalse((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Should be reset")
+    
+    // Test Field Validation with valid value
+    segmentedField.value = .Germany
+    XCTAssertTrue((form!.delegate! as FormTestDelegate).calledDidUpdateForm, "Value change did not update the FormDelegate")
+    XCTAssertNil(segmentedField.error, "There should not be an error after setting the value")
+    
+    // Test Field
+    XCTAssertEqual(segmentedField.representationValues!, ["Germany", "Austria"], "Representation is expected to return the values set in representationTransformer ")
+  }
+}

}

enum TestGender: Int {
  case Female = 2
  case Male = 3
}

class BureaucracyTests: XCTestCase {

  func test01addSection() {
    form!.addSection("Test Section")
    XCTAssertEqual(form!.numberOfSections(), 1, "Form should contain a section after adding")
    XCTAssertEqual(form!.numberOfFieldsInSection(0), 0, "Section should not have any elements yet")
    XCTAssertFalse(form!.serialize().isEmpty, "Serialize function should return something when there is a section")
    XCTAssertEqual(form!.serialize().count, 1, "Serialize function should return only one element since there is only one section")
    if let section = form!.serialize().first {
      XCTAssertTrue(section.isEmpty, "The section values should be empty since there are no elements added yet")
    }
    
    // Section Setup
    let section = form!.sections.first!
    XCTAssertEqual(section.name, "Test Section", "Form should have the title set correct")
    XCTAssertTrue(section.form === form, "Form property of the section should be the form of the testclass")
    XCTAssertEqual(section.count, 0, "Section should not contain elements yet")
  }
  
  func test02addForwardingElement() {
    
    // Add Section and ForwardingElement
    let testSection = form!.addSection("Test Section")
    let allProductsField = testSection.append(ForwardingElement(name: "Test Element"))
    
