Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kylian LOUSSOUARN
TD-685
Commits
0d9c6258
Commit
0d9c6258
authored
Feb 19, 2021
by
sunye
Browse files
Add tests to exercise 7, start implementing ex. 8
parent
a16e1395
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/unantes/l3/construction/exercice7/Action.java
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice7
;
public
class
Action
{
private
ReferenceToOne
<
Action
,
Button
>
button
=
new
ReferenceToOne
<>(
this
)
{
@Override
protected
ReferenceToOne
<
Button
,
Action
>
opposite
(
Button
target
)
{
return
target
.
action
();
}
};
public
ReferenceToOne
<
Action
,
Button
>
button
()
{
return
button
;
}
}
src/main/java/fr/unantes/l3/construction/exercice7/Button.java
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice7
;
public
class
Button
{
private
ReferenceToOne
<
Button
,
Action
>
action
=
new
ReferenceToOne
<>(
this
)
{
@Override
protected
ReferenceToOne
<
Action
,
Button
>
opposite
(
Action
target
)
{
return
target
.
button
();
}
};
public
ReferenceToOne
<
Button
,
Action
>
action
()
{
return
action
;
}
}
src/main/java/fr/unantes/l3/construction/exercice7/ReferenceToOne.java
View file @
0d9c6258
...
...
@@ -2,7 +2,7 @@ package fr.unantes.l3.construction.exercice7;
import
java.util.Optional
;
public
class
ReferenceToOne
<
C
,
T
>
{
public
abstract
class
ReferenceToOne
<
C
,
T
>
{
private
final
C
container
;
private
Optional
<
T
>
target
=
Optional
.
empty
();
...
...
@@ -36,10 +36,7 @@ public class ReferenceToOne<C, T> {
}
}
private
ReferenceToOne
<
T
,
C
>
opposite
(
T
target
)
{
return
null
;
//return target.button();
}
protected
abstract
ReferenceToOne
<
T
,
C
>
opposite
(
T
target
);
public
void
set
(
T
newTarget
)
{
this
.
basicSet
(
newTarget
);
...
...
src/main/java/fr/unantes/l3/construction/exercice8/Field.java
0 → 100644
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice8
;
public
class
Field
{
private
ReferenceToWindow
window
=
new
ReferenceToWindow
();
public
ReferenceToWindow
window
()
{
return
window
;
}
}
src/main/java/fr/unantes/l3/construction/exercice8/ReferenceToFields.java
0 → 100644
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice8
;
public
class
ReferenceToFields
{
}
src/main/java/fr/unantes/l3/construction/exercice8/ReferenceToWindow.java
0 → 100644
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice8
;
public
class
ReferenceToWindow
{
private
Window
target
;
public
Window
get
()
{
return
target
;
}
public
void
set
(
Window
target
)
{
this
.
target
=
target
;
}
public
void
unSet
()
{
target
=
null
;
}
}
src/main/java/fr/unantes/l3/construction/exercice8/Window.java
0 → 100644
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice8
;
public
class
Window
{
}
src/test/java/fr/unantes/l3/construction/TestWindow.java
View file @
0d9c6258
...
...
@@ -9,12 +9,12 @@ public class TestWindow {
@Test
void
testWidgets
()
{
Window
w
=
new
Window
();
Field
f
=
new
Field
();
Window
w
=
new
Window
();
Field
f
=
new
Field
();
w
.
getWidgets
().
add
(
f
);
w
.
getWidgets
().
add
(
f
);
w
.
getWidgets
().
remove
(
f
);
w
.
getWidgets
().
remove
(
f
);
Iterator
<
Field
>
it
=
w
.
getWidgets
().
iterator
();
...
...
src/test/java/fr/unantes/l3/construction/exercice6/ActionTest.java
View file @
0d9c6258
...
...
@@ -6,11 +6,41 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
ActionTest
{
@Test
public
void
testHandshake
()
{
public
void
testHandshake
FromButton
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
a1
.
button
().
set
(
b1
);
assertThat
(
b1
.
action
().
get
()).
isEqualTo
(
a1
);
}
@Test
public
void
testHandShakeFromAction
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
b1
.
action
().
set
(
a1
);
assertThat
(
a1
.
button
().
get
()).
isEqualTo
(
b1
);
}
@Test
public
void
testHandshakeWithPreviousAssociation
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
Action
a2
=
new
Action
();
Button
b2
=
new
Button
();
a1
.
button
().
set
(
b2
);
b1
.
action
().
set
(
a2
);
a1
.
button
().
set
(
b1
);
assertThat
(
a2
.
button
().
isSet
()).
isFalse
();
assertThat
(
b2
.
action
().
isSet
()).
isFalse
();
}
}
\ No newline at end of file
src/test/java/fr/unantes/l3/construction/exercice7/ActionTest.java
0 → 100644
View file @
0d9c6258
package
fr.unantes.l3.construction.exercice7
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
ActionTest
{
@Test
public
void
testHandshakeFromButton
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
a1
.
button
().
set
(
b1
);
assertThat
(
b1
.
action
().
get
()).
isEqualTo
(
a1
);
}
@Test
public
void
testHandShakeFromAction
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
b1
.
action
().
set
(
a1
);
assertThat
(
a1
.
button
().
get
()).
isEqualTo
(
b1
);
}
@Test
public
void
testHandshakeWithPreviousAssociation
()
{
Action
a1
=
new
Action
();
Button
b1
=
new
Button
();
Action
a2
=
new
Action
();
Button
b2
=
new
Button
();
a1
.
button
().
set
(
b2
);
b1
.
action
().
set
(
a2
);
a1
.
button
().
set
(
b1
);
assertThat
(
a2
.
button
().
isSet
()).
isFalse
();
assertThat
(
b2
.
action
().
isSet
()).
isFalse
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment