Commit bbb4412e authored by mlaminebendib's avatar mlaminebendib

Initial commit

parents
Pipeline #894 failed with stages
<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DATA>
<MASTER_LANGUAGE>D</MASTER_LANGUAGE>
<STARTING_FOLDER>/abap/ABAP-OO/</STARTING_FOLDER>
<FOLDER_LOGIC>FULL</FOLDER_LOGIC>
<IGNORE>
<item>/.gitignore</item>
<item>/LICENSE</item>
<item>/README.md</item>
<item>/package.json</item>
<item>/.travis.yml</item>
</IGNORE>
</DATA>
</asx:values>
</asx:abap>
# Java Ignores
/java/trip-service-kata/target
/java/trip-service-kata/.classpath
/java/trip-service-kata/.project
/java/trip-service-kata/.settings
/java/trip-service-kata/tomcat.*
/java/trip-service-kata/.idea
/java/trip-service-kata/*.iml
# C# Ignores
_ReSharper.*/
[Bb]in
[Oo]bj
*.suo
*.user
_NCrunch_*/
# Python Ignores
*.pyc
#php netbeans
php/nbproject/
# JavaScript Ignores
/javascript/node_modules
# Ignore Vim undo history
*.un~
# sbt specific
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
# Scala-IDE specific
.scala_dependencies
# IntelliJ IDEA
.idea/
.idea_modules
out/
*.iml
**/.idea
#Xcode / Objective-c Ignores
.DS_Store
## Build generated
build/
DerivedData
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
## Other
*.xccheckout
*.moved-aside
*.xcuserstate
Trip Service Kata
=================
Kata for legacy code hands-on session. The objective is to test and refactor the legacy TripService class.
The end result should be well-crafted code that express the domain.
You can watch the video with my solution. Although quite long, I explain my whole thought process while writting tests, how I break dependencies, the reasons for refactoring and re-desining the code (tests and production code), and why certain steps are important. I also cover how often I commit and why I do it.
The video is full of tips and tricks that can be used in any language.
https://www.youtube.com/watch?v=_NnElPO5BU0
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:TripServiceKata.xcodeproj">
</FileRef>
</Workspace>
//
// AppDelegate.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
//
// Trip.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
class Trip { }
\ No newline at end of file
//
// TripDAO.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
class TripDAO
{
class func findTripsByUser(user:User) throws -> [Trip]?
{
throw UnitTestErrorType.DependendClassCallDuringUnitTest
}
}
\ No newline at end of file
//
// TripService.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
class TripService
{
func GetTripsByUser(user:User) throws -> [Trip]?
{
var tripList:[Trip]? = nil
let loggedUser = try! UserSession.sharedInstance.getLoggedUser()
var isFriend = false
if let loggedUser = loggedUser {
for friend in user.getFriends() {
if friend == loggedUser {
isFriend = true
break
}
}
if isFriend {
tripList = try! TripDAO.findTripsByUser(user)
}
return tripList
}
else {
throw TripServiceErrorType.UserNotLoggedIn
}
}
}
\ No newline at end of file
//
// TripServiceKataFW.h
// TripServiceKataFW
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for TripServiceKataFW.
FOUNDATION_EXPORT double TripServiceKataFWVersionNumber;
//! Project version string for TripServiceKataFW.
FOUNDATION_EXPORT const unsigned char TripServiceKataFWVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <TripServiceKataFW/PublicHeader.h>
//
// UnitTestErrorType.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
enum UnitTestErrorType : ErrorType
{
case DependendClassCallDuringUnitTest
}
enum TripServiceErrorType : ErrorType
{
case UserNotLoggedIn
}
\ No newline at end of file
//
// User.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
func ==(lhs: User, rhs: User) -> Bool
{
return lhs === rhs
}
class User : Equatable
{
private var userTrips:[Trip] = []
private var friends:[User] = []
func getFriends() -> [User]
{
return self.friends
}
func addFriend(friend:User)
{
self.friends.append(friend)
}
func trips() -> [Trip]
{
return self.userTrips
}
func addTrip(trip:Trip)
{
self.userTrips.append(trip)
}
}
\ No newline at end of file
//
// UserSession.swift
// TripServiceKata
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import Foundation
class UserSession
{
static var sharedInstance:UserSession = UserSession()
func isUserLoggedIn(user:User) throws -> Bool
{
throw UnitTestErrorType.DependendClassCallDuringUnitTest
}
func getLoggedUser() throws -> User?
{
throw UnitTestErrorType.DependendClassCallDuringUnitTest
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// TripServiceKataTests.swift
// TripServiceKataTests
//
// Created by Alessandro Benvenuti on 21/02/2016.
// Copyright © 2016 Alessandro Benvenuti. All rights reserved.
//
import XCTest
@testable import TripServiceKata
class TripServiceKataTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
}
}
.DS_Store
/.build
/Packages
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "TripServiceKata",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "TripServiceKata",
targets: ["TripServiceKata"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "TripServiceKata",
dependencies: []),
.testTarget(
name: "TripServiceKataTests",
dependencies: ["TripServiceKata"]),
]
)
# TripServiceKata
A Swift 4 port of the Trip Service Kata.
## Requirements
- Swift 4
- Xcode 9.1 (if you want to work with Xcode)
## Swift Package
Since this is a Swift Package, you don't need Xcode to build the project or run the test.
You can build the package on the command line with `swift build`.
You can build the package and run the tests with `swift test`.
The Xcode project file is just included for convenience.
It can be recreated at any time with `swift package generate-xcodeproj`.
Happy Coding 🐳
import Foundation
class TripDAO
{
class func findTripsByUser(_ user:User) throws -> [Trip]?
{
throw UnitTestErrorType.dependendClassCallDuringUnitTest
}
}
import Foundation
class TripService
{
func getTripsByUser(_ user:User) throws -> [Trip]?
{
var tripList:[Trip]? = nil
let loggedUser = try! UserSession.sharedInstance.getLoggedUser()
var isFriend = false
if let loggedUser = loggedUser {
for friend in user.getFriends() {
if friend == loggedUser {
isFriend = true
break
}
}
if isFriend {
tripList = try! TripDAO.findTripsByUser(user)
}
return tripList
}
else {
throw TripServiceErrorType.userNotLoggedIn
}
}
}
import Foundation
enum UnitTestErrorType : Error
{
case dependendClassCallDuringUnitTest
}
enum TripServiceErrorType : Error
{
case userNotLoggedIn
}
import Foundation
func ==(lhs: User, rhs: User) -> Bool
{
return lhs === rhs
}
class User : Equatable
{
private var userTrips:[Trip] = []
private var friends:[User] = []
func getFriends() -> [User]
{
return self.friends
}
func addFriend(_ friend:User)
{
self.friends.append(friend)
}
func trips() -> [Trip]
{
return self.userTrips
}
func addTrip(_ trip:Trip)
{
self.userTrips.append(trip)
}
}
import Foundation
class UserSession
{
static var sharedInstance:UserSession = UserSession()
func isUserLoggedIn(_ user:User) throws -> Bool
{
throw UnitTestErrorType.dependendClassCallDuringUnitTest
}
func getLoggedUser() throws -> User?
{
throw UnitTestErrorType.dependendClassCallDuringUnitTest
}
}
import XCTest
@testable import TripServiceKataTests
XCTMain([
testCase(TripServiceKataTests.allTests),
])
import XCTest
@testable import TripServiceKata
class TripServiceKataTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
XCTAssertTrue(true)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>