Skip to content

Commit e748edb

Browse files
author
James Heggs
committed
First base class tests
0 parents  commit e748edb

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
25+
target
26+
.settings
27+
28+
.project
29+
30+
.idea
31+
32+
.vscode
33+
/.classpath
34+
/java-oop-coding-exercises.iml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Tech Returners
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Object Oriented Programming and Java
2+
3+
## Instructions
4+
5+
This repository contains challenges you to undertake in pairs on Java.
6+
7+
(The instructions below assume you have got your laptop setup ready for running Java applications as per the pre-journey)
8+
9+
To get started you should "fork" this repository into your own Git account and the clone down to your machine.
10+
11+
Once cloned you can run the tests by running:
12+
13+
```
14+
mvn test
15+
```
16+
17+
You'll see that all the tests are currently failing.
18+
19+
Working in your pairs you job is to one by one fix the failing tests.
20+
21+
We recommend working on one persons machine during pairing but once your session has ended send over the code to your pair so that you both have a copy.
22+
23+
## Some facts about your objects
24+
25+
The objects you'll be working with are all types of Cat
26+
27+
Here's some facts about Cats....
28+
29+
By definition the blueprint for ALL cats is that they can do the following things:
30+
31+
* Eat
32+
* Sleep
33+
* Run
34+
35+
They ALL have the following attributes
36+
37+
* A piece of data that says whether they are asleep or not
38+
* An average height represented in centimetres
39+
* A piece of data that indicates their setting such as "domestic" or "wild"
40+
* ALL cats go to sleep exactly the same way
41+
42+
After a cat has eaten its food their reaction tends to differ between species
43+
44+
* A Lion will let out a victorious roar
45+
* A cheetah will let out a snoring sound as it becomes tired following a chase
46+
* A domestic cat tends to let our a purring sound
47+
48+
49+
As a bonus exercise some domestic cats will randomly let out a dismissive "It will do I suppose" comment following eating.
50+
51+
52+
## Your solution should have...
53+
54+
* The usage of a Java interface
55+
56+
* The usage of a Java abstract class
57+
58+
* The usage of encapsulation, abstraction, polymorphism and inheritance
59+
60+
61+
62+

pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.techreturners</groupId>
8+
<artifactId>java-oop-coding-exercises</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>java-oop-coding-exercises</name>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>junit</groupId>
22+
<artifactId>junit</artifactId>
23+
<version>4.11</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
30+
<plugins>
31+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
32+
<plugin>
33+
<artifactId>maven-clean-plugin</artifactId>
34+
<version>3.1.0</version>
35+
</plugin>
36+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
37+
<plugin>
38+
<artifactId>maven-resources-plugin</artifactId>
39+
<version>3.0.2</version>
40+
</plugin>
41+
<plugin>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<version>3.8.0</version>
44+
</plugin>
45+
<plugin>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>2.22.1</version>
48+
</plugin>
49+
<plugin>
50+
<artifactId>maven-jar-plugin</artifactId>
51+
<version>3.0.2</version>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-install-plugin</artifactId>
55+
<version>2.5.2</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-deploy-plugin</artifactId>
59+
<version>2.8.2</version>
60+
</plugin>
61+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
62+
<plugin>
63+
<artifactId>maven-site-plugin</artifactId>
64+
<version>3.7.1</version>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-project-info-reports-plugin</artifactId>
68+
<version>3.0.0</version>
69+
</plugin>
70+
</plugins>
71+
</pluginManagement>
72+
</build>
73+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.techreturners.cats;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
public class CatTest {
9+
10+
@Test
11+
public void checkCatIsAwake() {
12+
Cat domesticCat = new DomesticCat();
13+
assertFalse("Cat should be awake by default", domesticCat.isAsleep());
14+
}
15+
16+
@Test
17+
public void checkCatCanGoToSleep() {
18+
Cat domesticCat = new DomesticCat();
19+
domesticCat.goToSleep();
20+
assertTrue("Cat should be snoozing", domesticCat.isAsleep());
21+
}
22+
23+
@Test
24+
public void checkCatCanWakep() {
25+
Cat domesticCat = new DomesticCat();
26+
domesticCat.goToSleep();
27+
domesticCat.wakeUp();
28+
assertFalse("Cat should be awake now", domesticCat.isAsleep());
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)